Unravel Engine C++ Reference
Loading...
Searching...
No Matches
pipeline.h
Go to the documentation of this file.
1#pragma once
2#include "../pipeline.h"
4
6#include <engine/ecs/ecs.h>
10
16
17namespace unravel
18{
19namespace rendering
20{
21
22class deferred : public pipeline
23{
24public:
25 deferred();
26 ~deferred();
27
28 auto init(rtti::context& ctx) -> bool override;
29 auto deinit(rtti::context& ctx) -> bool;
30
32 -> gfx::frame_buffer::ptr override;
33
34 void run_pipeline(const gfx::frame_buffer::ptr& output,
35 scene& scn,
36 const camera& camera,
37 gfx::render_view& rview,
38 delta_t dt,
39 const run_params& params,
41 void set_debug_pass(int pass) override;
42
54
55 using pipeline_flags = uint32_t;
56
58 scene& scn,
59 const camera& camera,
60 gfx::render_view& rview,
61 delta_t dt,
62 const run_params& params,
63 pipeline_flags pflags,
65
66 void run_g_buffer_pass(const visibility_set_models_t& visibility_set,
67 const camera& camera,
68 gfx::render_view& rview,
69 delta_t dt);
70
71 void run_assao_pass(const visibility_set_models_t& visibility_set,
72 const camera& camera,
73 gfx::render_view& rview,
74 delta_t dt,
75 const run_params& rparams);
76
77 auto run_lighting_pass(scene& scn, const camera& camera, gfx::render_view& rview, bool apply_shadows, delta_t dt)
79
80
82
84 scene& scn,
85 const camera& camera,
86 gfx::render_view& rview,
88
89 auto run_ssr_pass(const camera& camera, gfx::render_view& rview, const gfx::frame_buffer::ptr& output,
90 const run_params& rparams)
92
94 const run_params& rparams)
96
98 const run_params& rparams)
101 gfx::render_view& rview,
102 const gfx::frame_buffer::ptr& output);
103
104 void build_reflections(scene& scn, const camera& camera, delta_t dt);
105
107
109
110private:
111 struct ref_probe_program : uniforms_cache
112 {
113 void cache_uniforms()
114 {
115 cache_uniform(program.get(), u_data0, "u_data0", gfx::uniform_type::Vec4);
116 cache_uniform(program.get(), u_data1, "u_data1", gfx::uniform_type::Vec4);
117 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
118 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
119 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
120 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
121 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
122 cache_uniform(program.get(), s_tex_cube, "s_tex_cube", gfx::uniform_type::Sampler);
123 }
124
127
128 std::array<gfx::program::uniform_ptr, 5> s_tex;
129 gfx::program::uniform_ptr s_tex_cube;
130
131 std::unique_ptr<gpu_program> program;
132 };
133
134 struct box_ref_probe_program : ref_probe_program
135 {
136 void cache_uniforms()
137 {
138 ref_probe_program::cache_uniforms();
139
140 cache_uniform(program.get(), u_data2, "u_data2", gfx::uniform_type::Vec4);
141 cache_uniform(program.get(), u_inv_world, "u_inv_world", gfx::uniform_type::Mat4);
142 }
143 gfx::program::uniform_ptr u_inv_world;
145
146 } box_ref_probe_program_;
147
148 struct sphere_ref_probe_program : ref_probe_program
149 {
150 } sphere_ref_probe_program_;
151
152 struct geom_program : uniforms_cache
153 {
154 void cache_uniforms()
155 {
156 cache_uniform(program.get(), s_tex_color, "s_tex_color", gfx::uniform_type::Sampler);
157 cache_uniform(program.get(), s_tex_normal, "s_tex_normal", gfx::uniform_type::Sampler);
158 cache_uniform(program.get(), s_tex_roughness, "s_tex_roughness", gfx::uniform_type::Sampler);
159 cache_uniform(program.get(), s_tex_metalness, "s_tex_metalness", gfx::uniform_type::Sampler);
160 cache_uniform(program.get(), s_tex_ao, "s_tex_ao", gfx::uniform_type::Sampler);
161 cache_uniform(program.get(), s_tex_emissive, "s_tex_emissive", gfx::uniform_type::Sampler);
162
163 cache_uniform(program.get(), u_base_color, "u_base_color", gfx::uniform_type::Vec4);
164 cache_uniform(program.get(), u_subsurface_color, "u_subsurface_color", gfx::uniform_type::Vec4);
165 cache_uniform(program.get(), u_emissive_color, "u_emissive_color", gfx::uniform_type::Vec4);
166 cache_uniform(program.get(), u_surface_data, "u_surface_data", gfx::uniform_type::Vec4);
167 cache_uniform(program.get(), u_tiling, "u_tiling", gfx::uniform_type::Vec4);
168 cache_uniform(program.get(), u_dither_threshold, "u_dither_threshold", gfx::uniform_type::Vec4);
169 cache_uniform(program.get(), u_surface_data2, "u_surface_data2", gfx::uniform_type::Vec4);
170
171 cache_uniform(program.get(), u_camera_wpos, "u_camera_wpos", gfx::uniform_type::Vec4);
172 cache_uniform(program.get(), u_camera_clip_planes, "u_camera_clip_planes", gfx::uniform_type::Vec4);
173 cache_uniform(program.get(), u_lod_params, "u_lod_params", gfx::uniform_type::Vec4);
174 }
175
176 gfx::program::uniform_ptr s_tex_color;
177 gfx::program::uniform_ptr s_tex_normal;
178 gfx::program::uniform_ptr s_tex_roughness;
179 gfx::program::uniform_ptr s_tex_metalness;
181 gfx::program::uniform_ptr s_tex_emissive;
182
183 gfx::program::uniform_ptr u_base_color;
184 gfx::program::uniform_ptr u_subsurface_color;
185 gfx::program::uniform_ptr u_emissive_color;
186 gfx::program::uniform_ptr u_surface_data;
188 gfx::program::uniform_ptr u_dither_threshold;
189 gfx::program::uniform_ptr u_surface_data2;
190
191 gfx::program::uniform_ptr u_camera_wpos;
192 gfx::program::uniform_ptr u_camera_clip_planes;
193 gfx::program::uniform_ptr u_lod_params;
194
195 std::unique_ptr<gpu_program> program;
196 };
197
198 geom_program geom_program_;
199 geom_program geom_program_skinned_;
200
201 struct color_lighting : uniforms_cache
202 {
203 void cache_uniforms()
204 {
205 cache_uniform(program.get(), u_light_position, "u_light_position", gfx::uniform_type::Vec4);
206 cache_uniform(program.get(), u_light_direction, "u_light_direction", gfx::uniform_type::Vec4);
207 cache_uniform(program.get(), u_light_data, "u_light_data", gfx::uniform_type::Vec4);
208 cache_uniform(program.get(), u_light_color_intensity, "u_light_color_intensity", gfx::uniform_type::Vec4);
209 cache_uniform(program.get(), u_camera_position, "u_camera_position", gfx::uniform_type::Vec4);
210
211 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
212 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
213 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
214 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
215 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
216 cache_uniform(program.get(), s_tex[5], "s_tex5", gfx::uniform_type::Sampler);
217 cache_uniform(program.get(), s_tex[6], "s_tex6", gfx::uniform_type::Sampler);
218 }
219 gfx::program::uniform_ptr u_light_position;
220 gfx::program::uniform_ptr u_light_direction;
221 gfx::program::uniform_ptr u_light_data;
222 gfx::program::uniform_ptr u_light_color_intensity;
223 gfx::program::uniform_ptr u_camera_position;
224 std::array<gfx::program::uniform_ptr, 7> s_tex;
225
226 std::shared_ptr<gpu_program> program;
227 };
228
229 struct debug_visualization_program : uniforms_cache
230 {
231 void cache_uniforms()
232 {
233 cache_uniform(program.get(), u_params, "u_params", gfx::uniform_type::Vec4);
234 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
235 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
236 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
237 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
238 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
239 cache_uniform(program.get(), s_tex[5], "s_tex5", gfx::uniform_type::Sampler);
240 }
241
243 std::array<gfx::program::uniform_ptr, 6> s_tex;
244
245 std::unique_ptr<gpu_program> program;
246
247 } debug_visualization_program_;
248
249 auto get_light_program(const light& l) const -> const color_lighting&;
250 auto get_light_program_no_shadows(const light& l) const -> const color_lighting&;
251 void submit_pbr_material(geom_program& program, const pbr_material& mat);
252
253 color_lighting color_lighting_[uint8_t(light_type::count)][uint8_t(sm_depth::count)][uint8_t(sm_impl::count)];
254 color_lighting color_lighting_no_shadow_[uint8_t(light_type::count)];
255
256 asset_handle<gfx::texture> ibl_brdf_lut_;
257
258
259 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
260 int debug_pass_{-1};
261
262};
263
264} // namespace rendering
265} // namespace unravel
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:35
auto deinit(rtti::context &ctx) -> bool
void set_debug_pass(int pass) override
Definition pipeline.cpp:525
void build_shadows(scene &scn, const camera &camera, visibility_flags query=visibility_query::not_specified, layer_mask render_mask=layer_mask{layer_reserved::everything_layer})
Definition pipeline.cpp:421
void run_assao_pass(const visibility_set_models_t &visibility_set, const camera &camera, gfx::render_view &rview, delta_t dt, const run_params &rparams)
Definition pipeline.cpp:727
void run_reflection_probe_pass(scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt)
Definition pipeline.cpp:875
auto run_lighting_pass(scene &scn, const camera &camera, gfx::render_view &rview, bool apply_shadows, delta_t dt) -> gfx::frame_buffer::ptr
Definition pipeline.cpp:755
void run_debug_visualization_pass(const camera &camera, gfx::render_view &rview, const gfx::frame_buffer::ptr &output)
auto run_ssr_pass(const camera &camera, gfx::render_view &rview, const gfx::frame_buffer::ptr &output, const run_params &rparams) -> gfx::frame_buffer::ptr
void build_reflections(scene &scn, const camera &camera, delta_t dt)
Definition pipeline.cpp:335
auto run_fxaa_pass(gfx::render_view &rview, const gfx::frame_buffer::ptr &input, const gfx::frame_buffer::ptr &output, const run_params &rparams) -> gfx::frame_buffer::ptr
void run_g_buffer_pass(const visibility_set_models_t &visibility_set, const camera &camera, gfx::render_view &rview, delta_t dt)
Definition pipeline.cpp:597
auto run_atmospherics_pass(gfx::frame_buffer::ptr input, scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt) -> gfx::frame_buffer::ptr
auto run_tonemapping_pass(gfx::render_view &rview, const gfx::frame_buffer::ptr &input, const gfx::frame_buffer::ptr &output, const run_params &rparams) -> gfx::frame_buffer::ptr
auto run_hiz_pass(const camera &camera, gfx::render_view &rview, delta_t dt) -> gfx::texture::ptr
auto init(rtti::context &ctx) -> bool override
auto run_pipeline(scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt, const run_params &params, layer_mask render_mask=layer_mask{layer_reserved::everything_layer}) -> gfx::frame_buffer::ptr override
Renders the entire scene from the camera's perspective.
Definition pipeline.cpp:494
void run_pipeline_impl(const gfx::frame_buffer::ptr &output, scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt, const run_params &params, pipeline_flags pflags, layer_mask render_mask=layer_mask{layer_reserved::everything_layer})
Definition pipeline.cpp:530
@ not_specified
No specific visibility query.
Definition pipeline.h:72
uint32_t visibility_flags
Type alias for visibility flags.
Definition pipeline.h:79
std::chrono::duration< float > delta_t
hpp::small_vector< entt::handle > visibility_set_models_t
Definition pipeline.h:44
@ everything_layer
Definition layer_mask.h:16
Represents a handle to an asset, providing access and management functions.
std::shared_ptr< uniform > uniform_ptr
Definition program.h:19
Structure representing a reflection probe.
Represents a scene in the ACE framework, managing entities and their relationships.
Definition scene.h:21
Structure for caching uniforms.
void cache_uniform(gpu_program *program, gfx::program::uniform_ptr &uniform, const hpp::string_view &name, gfx::uniform_type type, uint16_t num=1)
Caches a uniform in the GPU program.