Unravel Engine C++ Reference
Loading...
Searching...
No Matches
pipeline.h
Go to the documentation of this file.
1#pragma once
2#include "../pipeline.h"
3
5#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
44 enum pipeline_steps : uint32_t
45 {
46 geometry_pass = 1u << 1,
47 shadow_pass = 1u << 2,
49 atmospheric = 1u << 5,
50 particles_pass = 1u << 6,
51
52 full = 0xFFFFFFFFu,
53 };
54
56 scene& scn,
57 const camera& camera,
58 gfx::render_view& rview,
59 delta_t dt,
60 const run_params& params,
62
63 void run_g_buffer_pass(const visibility_set_models_t& visibility_set,
64 const camera& camera,
65 gfx::render_view& rview,
66 delta_t dt);
67
68 void run_assao_pass(const camera& camera,
69 gfx::render_view& rview,
70 delta_t dt,
71 const run_params& rparams);
72
73 auto run_direct_lighting_pass(scene& scn, const camera& camera, gfx::render_view& rview, bool apply_shadows, delta_t dt)
75
76 auto run_indirect_lighting_pass(scene& scn, const camera& camera, gfx::render_view& rview, bool apply_reflection, delta_t dt)
78
79 void run_reflection_probe_pass(scene& scn, const camera& camera, gfx::render_view& rview, bool apply_probes, delta_t dt);
80
82 scene& scn,
83 const camera& camera,
84 gfx::render_view& rview,
86
87 void run_ssr_pass(const camera& camera, gfx::render_view& rview, const gfx::frame_buffer::ptr& previous_frame_source,
88 const run_params& rparams);
89
90 void run_ssil_pass(const camera& camera, gfx::render_view& rview, const run_params& rparams);
91
92 auto run_taa_pass(const camera& camera,
93 gfx::render_view& rview,
95 const gfx::frame_buffer::ptr& output,
96 const run_params& rparams) -> gfx::frame_buffer::ptr;
97
99 const run_params& rparams)
101
104 const run_params& rparams,
105 delta_t dt);
106
109 const run_params& rparams) -> gfx::frame_buffer::ptr;
110
112 const run_params& rparams)
115 gfx::render_view& rview,
116 const gfx::frame_buffer::ptr& output);
117
118 void build_reflections(scene& scn, const camera& camera, delta_t dt);
119
121
123 auto run_hiz_pass(const camera& camera,
124 gfx::render_view& rview,
125 const run_params& params,
126 const usize32_t& viewport_size,
127 delta_t dt) -> bool;
128
129private:
130 struct ref_probe_program : uniforms_cache
131 {
132 void cache_uniforms()
133 {
134 cache_uniform(program.get(), u_data0, "u_data0", gfx::uniform_type::Vec4);
135 cache_uniform(program.get(), u_data1, "u_data1", gfx::uniform_type::Vec4);
136 cache_uniform(program.get(), u_capture, "u_capture", gfx::uniform_type::Vec4);
137 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
138 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
139 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
140 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
141 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
142 cache_uniform(program.get(), s_tex_cube, "s_tex_cube", gfx::uniform_type::Sampler);
143 }
144
148
149 std::array<gfx::program::uniform_ptr, 5> s_tex;
150 gfx::program::uniform_ptr s_tex_cube;
151
152 std::unique_ptr<gpu_program> program;
153 };
154
155 struct box_ref_probe_program : ref_probe_program
156 {
157 void cache_uniforms()
158 {
159 ref_probe_program::cache_uniforms();
160
161 cache_uniform(program.get(), u_data2, "u_data2", gfx::uniform_type::Vec4);
162 cache_uniform(program.get(), u_inv_world, "u_inv_world", gfx::uniform_type::Mat4);
163 }
164 gfx::program::uniform_ptr u_inv_world;
166
167 } box_ref_probe_program_;
168
169 struct sphere_ref_probe_program : ref_probe_program
170 {
171 } sphere_ref_probe_program_;
172
173 struct geom_program : uniforms_cache
174 {
175 void cache_uniforms()
176 {
177 cache_uniform(program.get(), s_tex_color, "s_tex_color", gfx::uniform_type::Sampler);
178 cache_uniform(program.get(), s_tex_normal, "s_tex_normal", gfx::uniform_type::Sampler);
179 cache_uniform(program.get(), s_tex_roughness, "s_tex_roughness", gfx::uniform_type::Sampler);
180 cache_uniform(program.get(), s_tex_metalness, "s_tex_metalness", gfx::uniform_type::Sampler);
181 cache_uniform(program.get(), s_tex_ao, "s_tex_ao", gfx::uniform_type::Sampler);
182 cache_uniform(program.get(), s_tex_emissive, "s_tex_emissive", gfx::uniform_type::Sampler);
183
184 cache_uniform(program.get(), u_base_color, "u_base_color", gfx::uniform_type::Vec4);
185 cache_uniform(program.get(), u_subsurface_color, "u_subsurface_color", gfx::uniform_type::Vec4);
186 cache_uniform(program.get(), u_emissive_color, "u_emissive_color", gfx::uniform_type::Vec4);
187 cache_uniform(program.get(), u_surface_data, "u_surface_data", gfx::uniform_type::Vec4);
188 cache_uniform(program.get(), u_tiling, "u_tiling", gfx::uniform_type::Vec4);
189 cache_uniform(program.get(), u_dither_threshold, "u_dither_threshold", gfx::uniform_type::Vec4);
190 cache_uniform(program.get(), u_surface_data2, "u_surface_data2", gfx::uniform_type::Vec4);
191
192 cache_uniform(program.get(), u_camera_wpos, "u_camera_wpos", gfx::uniform_type::Vec4);
193 cache_uniform(program.get(), u_camera_clip_planes, "u_camera_clip_planes", gfx::uniform_type::Vec4);
194 cache_uniform(program.get(), u_lod_params, "u_lod_params", gfx::uniform_type::Vec4);
195 }
196
197 gfx::program::uniform_ptr s_tex_color;
198 gfx::program::uniform_ptr s_tex_normal;
199 gfx::program::uniform_ptr s_tex_roughness;
200 gfx::program::uniform_ptr s_tex_metalness;
202 gfx::program::uniform_ptr s_tex_emissive;
203
204 gfx::program::uniform_ptr u_base_color;
205 gfx::program::uniform_ptr u_subsurface_color;
206 gfx::program::uniform_ptr u_emissive_color;
207 gfx::program::uniform_ptr u_surface_data;
209 gfx::program::uniform_ptr u_dither_threshold;
210 gfx::program::uniform_ptr u_surface_data2;
211
212 gfx::program::uniform_ptr u_camera_wpos;
213 gfx::program::uniform_ptr u_camera_clip_planes;
214 gfx::program::uniform_ptr u_lod_params;
215
216 std::unique_ptr<gpu_program> program;
217 };
218
219 geom_program geom_program_;
220 geom_program geom_program_skinned_;
221 geom_program geom_program_instanced_;
222
223 struct color_lighting : uniforms_cache
224 {
225 void cache_uniforms()
226 {
227 cache_uniform(program.get(), u_light_position, "u_light_position", gfx::uniform_type::Vec4);
228 cache_uniform(program.get(), u_light_direction, "u_light_direction", gfx::uniform_type::Vec4);
229 cache_uniform(program.get(), u_light_data, "u_light_data", gfx::uniform_type::Vec4);
230 cache_uniform(program.get(), u_contact_shadow, "u_contact_shadow", gfx::uniform_type::Vec4);
231 cache_uniform(program.get(), u_light_color_intensity, "u_light_color_intensity", gfx::uniform_type::Vec4);
232 cache_uniform(program.get(), u_camera_position, "u_camera_position", gfx::uniform_type::Vec4);
233
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 cache_uniform(program.get(), s_tex[6], "s_tex6", gfx::uniform_type::Sampler);
241 }
242 gfx::program::uniform_ptr u_light_position;
243 gfx::program::uniform_ptr u_light_direction;
244 gfx::program::uniform_ptr u_light_data;
245 gfx::program::uniform_ptr u_contact_shadow;
246 gfx::program::uniform_ptr u_light_color_intensity;
247 gfx::program::uniform_ptr u_camera_position;
248 std::array<gfx::program::uniform_ptr, 7> s_tex;
249
250 std::shared_ptr<gpu_program> program;
251 };
252
253 struct irradiance_compute_program : uniforms_cache
254 {
255 void cache_uniforms()
256 {
257 cache_uniform(program.get(), u_mode, "u_mode", gfx::uniform_type::Vec4);
258 cache_uniform(program.get(), u_irradiance_tint_intensity, "u_irradiance_tint_intensity", gfx::uniform_type::Vec4);
259 cache_uniform(program.get(), u_sun_direction, "u_sun_direction", gfx::uniform_type::Vec4);
260 cache_uniform(program.get(), u_sun_luminance, "u_sun_luminance", gfx::uniform_type::Vec4);
261 cache_uniform(program.get(), u_sky_luminance_xyz, "u_sky_luminance_xyz", gfx::uniform_type::Vec4);
262 cache_uniform(program.get(), u_exposition, "u_exposition", gfx::uniform_type::Vec4);
263 cache_uniform(program.get(), u_perez_coeff, "u_perez_coeff", gfx::uniform_type::Vec4, 5);
264 cache_uniform(program.get(), s_env, "s_env", gfx::uniform_type::Sampler);
265 }
267 gfx::program::uniform_ptr u_irradiance_tint_intensity;
268 gfx::program::uniform_ptr u_sun_direction;
269 gfx::program::uniform_ptr u_sun_luminance;
270 gfx::program::uniform_ptr u_sky_luminance_xyz;
271 gfx::program::uniform_ptr u_exposition;
272 gfx::program::uniform_ptr u_perez_coeff;
274
275 std::unique_ptr<gpu_program> program;
276 } irradiance_compute_program_;
277
278 struct indirect_lighting_program : uniforms_cache
279 {
280 void cache_uniforms()
281 {
282 cache_uniform(program.get(), u_light_data, "u_light_data", gfx::uniform_type::Vec4);
283 cache_uniform(program.get(), u_camera_position, "u_camera_position", gfx::uniform_type::Vec4);
284
285 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
286 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
287 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
288 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
289 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
290 cache_uniform(program.get(), s_tex[5], "s_tex5", gfx::uniform_type::Sampler);
291 cache_uniform(program.get(), s_tex[6], "s_tex6", gfx::uniform_type::Sampler);
292 cache_uniform(program.get(), s_irradiance, "s_irradiance", gfx::uniform_type::Sampler);
293 cache_uniform(program.get(), s_ssil, "s_ssil", gfx::uniform_type::Sampler);
294 }
295 gfx::program::uniform_ptr u_light_data;
296 gfx::program::uniform_ptr u_camera_position;
297 std::array<gfx::program::uniform_ptr, 7> s_tex;
298 gfx::program::uniform_ptr s_irradiance;
300
301 std::unique_ptr<gpu_program> program;
302
303 } indirect_lighting_program_;
304
305 struct debug_visualization_program : uniforms_cache
306 {
307 void cache_uniforms()
308 {
309 cache_uniform(program.get(), u_params, "u_params", gfx::uniform_type::Vec4);
310 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
311 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
312 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
313 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
314 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
315 cache_uniform(program.get(), s_tex[5], "s_tex5", gfx::uniform_type::Sampler);
316 cache_uniform(program.get(), s_tex[6], "s_tex6", gfx::uniform_type::Sampler);
317 cache_uniform(program.get(), s_tex[7], "s_tex7", gfx::uniform_type::Sampler);
318 }
319
321 std::array<gfx::program::uniform_ptr, 8> s_tex;
322
323 std::unique_ptr<gpu_program> program;
324
325 } debug_visualization_program_;
326
327 struct irradiance_pass_result
328 {
329 gfx::texture::ptr irradiance_tex;
330 math::vec3 global_color = {1.0f, 1.0f, 1.0f};
331 float global_intensity = 0.0f;
332 };
333 auto run_irradiance_pass(scene& scn, gfx::render_view& rview) -> irradiance_pass_result;
334
335 auto get_light_program(const light& l) const -> const color_lighting&;
336 auto get_light_program_no_shadows(const light& l) const -> const color_lighting&;
337 void submit_pbr_material(geom_program& program, const pbr_material& mat);
338 void submit_batched_geometry(gfx::render_pass& pass, const camera& camera);
339
340 color_lighting color_lighting_[uint8_t(light_type::count)][uint8_t(sm_depth::count)][uint8_t(sm_impl::count)];
341 color_lighting color_lighting_no_shadow_[uint8_t(light_type::count)];
342
343 asset_handle<gfx::texture> ibl_brdf_lut_;
344
345 // Static mesh batching system
346 batch_collector batch_collector_;
347
348public:
349
350private:
352 void snapshot_prev_depth(gfx::render_view& rview, const usize32_t& viewport_size);
353
354 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
355 int debug_pass_{-1};
356
357};
358
359} // namespace rendering
360} // namespace unravel
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:62
auto run_indirect_lighting_pass(scene &scn, const camera &camera, gfx::render_view &rview, bool apply_reflection, delta_t dt) -> gfx::frame_buffer::ptr
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, layer_mask render_mask=layer_mask{layer_reserved::everything_layer})
Definition pipeline.cpp:651
auto deinit(rtti::context &ctx) -> bool
void set_debug_pass(int pass) override
Definition pipeline.cpp:646
auto run_taa_pass(const camera &camera, 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_direct_lighting_pass(scene &scn, const camera &camera, gfx::render_view &rview, bool apply_shadows, delta_t dt) -> gfx::frame_buffer::ptr
void run_ssr_pass(const camera &camera, gfx::render_view &rview, const gfx::frame_buffer::ptr &previous_frame_source, const run_params &rparams)
void run_auto_exposure_pass(gfx::render_view &rview, const gfx::frame_buffer::ptr &input, const run_params &rparams, delta_t dt)
void run_reflection_probe_pass(scene &scn, const camera &camera, gfx::render_view &rview, bool apply_probes, delta_t dt)
void run_debug_visualization_pass(const camera &camera, gfx::render_view &rview, const gfx::frame_buffer::ptr &output)
void build_shadows(scene &scn, const camera &camera, delta_t dt, visibility_flags query=visibility_query::not_specified, layer_mask render_mask=layer_mask{layer_reserved::everything_layer})
Definition pipeline.cpp:539
pipeline_steps
Bitmask for pipeline::run_params::pflags (deferred path only).
Definition pipeline.h:45
void build_reflections(scene &scn, const camera &camera, delta_t dt)
Definition pipeline.cpp:424
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:797
void run_assao_pass(const camera &camera, gfx::render_view &rview, delta_t dt, const run_params &rparams)
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_bloom_pass(gfx::render_view &rview, const gfx::frame_buffer::ptr &input, const run_params &rparams) -> gfx::frame_buffer::ptr
auto run_hiz_pass(const camera &camera, gfx::render_view &rview, const run_params &params, const usize32_t &viewport_size, delta_t dt) -> bool
Builds or drops Hi-Z + related depth history. true if SSIL/SSR may use HiZ this frame.
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:615
void run_ssil_pass(const camera &camera, gfx::render_view &rview, const run_params &rparams)
@ not_specified
No specific visibility query.
Definition pipeline.h:105
@ camera
Main camera / viewport rendering (post-processing, UI, probe build, etc.).
uint32_t visibility_flags
Type alias for visibility flags.
Definition pipeline.h:111
std::chrono::duration< float > delta_t
const aiScene * scene
hpp::small_vector< visibility_data > visibility_set_models_t
Definition pipeline.h:52
batch_collector_t< batch_key > batch_collector
@ everything_layer
Definition layer_mask.h:16
Thread-safe handle to an asset.
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:70
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.