2#ifndef LIBSBX_POST_FILTERS_RESOLVE_FILTER_HPP_
3#define LIBSBX_POST_FILTERS_RESOLVE_FILTER_HPP_
6#include <unordered_map>
8#include <libsbx/scenes/components/transform.hpp>
10#include <libsbx/graphics/graphics_module.hpp>
11#include <libsbx/graphics/buffers/uniform_buffer.hpp>
12#include <libsbx/graphics/buffers/push_handler.hpp>
14#include <libsbx/scenes/scenes_module.hpp>
15#include <libsbx/scenes/scene.hpp>
16#include <libsbx/scenes/components/camera.hpp>
18#include <libsbx/scenes/scenes_module.hpp>
19#include <libsbx/scenes/scene.hpp>
20#include <libsbx/scenes/node.hpp>
21#include <libsbx/scenes/components/camera.hpp>
22#include <libsbx/scenes/components/point_light.hpp>
23#include <libsbx/scenes/components/static_mesh.hpp>
24#include <libsbx/scenes/components/skybox.hpp>
26#include <libsbx/post/filter.hpp>
30template<
bool Transparent>
35 inline static constexpr auto max_point_lights = std::size_t{32};
37 struct point_light_data {
43 .depth = graphics::depth::disabled,
44 .uses_transparency = Transparent,
46 .polygon_mode = graphics::polygon_mode::fill,
47 .cull_mode = graphics::cull_mode::none,
48 .front_face = graphics::front_face::counter_clockwise
52 static constexpr auto _default_shader_path() -> std::string_view {
53 if constexpr (Transparent) {
54 return "engine://shaders/resolve_transparent";
56 return "engine://shaders/resolve_opaque";
62 resolve_filter(
const std::vector<graphics::attachment_description>& attachments, std::vector<std::pair<std::string, std::string>>&& attachment_names,
const std::filesystem::path& path = _default_shader_path())
63 :
base{attachments, path, pipeline_definition},
64 _push_handler{base::pipeline()},
65 _point_lights_storage_handler{},
66 _attachment_names{std::move(attachment_names)} { }
71 EASY_BLOCK(
"resolve_filter::render", profiler::colors::Red);
73 auto& graphics_module = core::engine::get_module<graphics::graphics_module>();
75 auto& scenes_module = core::engine::get_module<scenes::scenes_module>();
77 auto& scene = scenes_module.active_scene();
78 auto& environment = scene.environment();
79 auto& graph = scene.graph();
81 auto& pipeline = base::pipeline();
82 auto& descriptor_handler = base::descriptor_handler();
84 pipeline.bind(command_buffer);
88 auto point_lights = std::vector<point_light_data>{};
89 point_lights.reserve(max_point_lights);
90 auto point_light_count = std::uint32_t{0};
92 for (
const auto&
node : point_light_nodes) {
93 const auto model = graph.world_transform(
node);
99 point_lights.push_back(point_light_data{
math::vector4{position, light.radius()}, light.color()});
103 if (point_light_count >= max_point_lights) {
108 if constexpr (!Transparent) {
109 _point_lights_storage_handler.push(std::span<const point_light_data>{point_lights.data(), point_light_count});
110 _push_handler.push(
"point_light_count", point_light_count);
112 descriptor_handler.push(
"scene", environment.uniform_handler());
113 descriptor_handler.push(
"buffer_point_lights", _point_lights_storage_handler);
116 for (
const auto& [name, attachment] : _attachment_names) {
117 descriptor_handler.push(name, graphics_module.attachment(attachment));
120 if constexpr (!Transparent) {
121 auto camera_node = environment.camera();
123 const auto& skybox = graph.get_component<
scenes::skybox>(camera_node);
125 descriptor_handler.push(
"brdf_image", graphics_module.get_resource<
graphics::image2d>(skybox.brdf_image));
126 descriptor_handler.push(
"irradiance_image", graphics_module.get_resource<
graphics::cube_image>(skybox.irradiance_image));
127 descriptor_handler.push(
"prefiltered_image", graphics_module.get_resource<
graphics::cube_image>(skybox.prefiltered_image));
130 if (!descriptor_handler.update(pipeline)) {
134 descriptor_handler.bind_descriptors(command_buffer);
136 if constexpr (!Transparent) {
137 _push_handler.bind(command_buffer);
140 command_buffer.draw(3, 1, 0, 0);
148 std::vector<std::pair<std::string, std::string>> _attachment_names;
Definition: command_buffer.hpp:15
Definition: cube_image.hpp:21
Definition: image2d.hpp:52
Definition: push_handler.hpp:18
Definition: storage_handler.hpp:17
Definition: vector3.hpp:23
Definition: vector4.hpp:24
RGBA color value type.
Definition: color.hpp:48
Definition: filter.hpp:19
Definition: resolve_filter.hpp:31
Definition: point_light.hpp:9
Definition: graphics_pipeline.hpp:106
Definition: graphics_pipeline.hpp:67
Definition: skybox.hpp:13