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>
11
17
18namespace unravel
19{
20namespace rendering
21{
22
23class deferred : public pipeline
24{
25public:
26 deferred();
27 ~deferred();
28
29 auto init(rtti::context& ctx) -> bool override;
30 auto deinit(rtti::context& ctx) -> bool;
31
33 -> gfx::frame_buffer::ptr override;
34
35 void run_pipeline(const gfx::frame_buffer::ptr& output,
36 scene& scn,
37 const camera& camera,
38 gfx::render_view& rview,
39 delta_t dt,
40 const run_params& params,
42 void set_debug_pass(int pass) override;
43
56
57 using pipeline_flags = uint32_t;
58
60 scene& scn,
61 const camera& camera,
62 gfx::render_view& rview,
63 delta_t dt,
64 const run_params& params,
65 pipeline_flags pflags,
67
68 void run_g_buffer_pass(const visibility_set_models_t& visibility_set,
69 const camera& camera,
70 gfx::render_view& rview,
71 delta_t dt);
72
73 void run_assao_pass(const visibility_set_models_t& visibility_set,
74 const camera& camera,
75 gfx::render_view& rview,
76 delta_t dt,
77 const run_params& rparams);
78
79 auto run_lighting_pass(scene& scn, const camera& camera, gfx::render_view& rview, bool apply_shadows, delta_t dt)
81
82
84
86 scene& scn,
87 const camera& camera,
88 gfx::render_view& rview,
90
91 auto run_ssr_pass(const camera& camera, gfx::render_view& rview, const gfx::frame_buffer::ptr& output,
92 const run_params& rparams)
94
96 const run_params& rparams)
98
100 const run_params& rparams)
103 gfx::render_view& rview,
104 const gfx::frame_buffer::ptr& output);
105
106 void build_reflections(scene& scn, const camera& camera, delta_t dt);
107
109
111
112private:
113 struct ref_probe_program : uniforms_cache
114 {
115 void cache_uniforms()
116 {
117 cache_uniform(program.get(), u_data0, "u_data0", gfx::uniform_type::Vec4);
118 cache_uniform(program.get(), u_data1, "u_data1", gfx::uniform_type::Vec4);
119 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
120 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
121 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
122 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
123 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
124 cache_uniform(program.get(), s_tex_cube, "s_tex_cube", gfx::uniform_type::Sampler);
125 }
126
129
130 std::array<gfx::program::uniform_ptr, 5> s_tex;
131 gfx::program::uniform_ptr s_tex_cube;
132
133 std::unique_ptr<gpu_program> program;
134 };
135
136 struct box_ref_probe_program : ref_probe_program
137 {
138 void cache_uniforms()
139 {
140 ref_probe_program::cache_uniforms();
141
142 cache_uniform(program.get(), u_data2, "u_data2", gfx::uniform_type::Vec4);
143 cache_uniform(program.get(), u_inv_world, "u_inv_world", gfx::uniform_type::Mat4);
144 }
145 gfx::program::uniform_ptr u_inv_world;
147
148 } box_ref_probe_program_;
149
150 struct sphere_ref_probe_program : ref_probe_program
151 {
152 } sphere_ref_probe_program_;
153
154 struct geom_program : uniforms_cache
155 {
156 void cache_uniforms()
157 {
158 cache_uniform(program.get(), s_tex_color, "s_tex_color", gfx::uniform_type::Sampler);
159 cache_uniform(program.get(), s_tex_normal, "s_tex_normal", gfx::uniform_type::Sampler);
160 cache_uniform(program.get(), s_tex_roughness, "s_tex_roughness", gfx::uniform_type::Sampler);
161 cache_uniform(program.get(), s_tex_metalness, "s_tex_metalness", gfx::uniform_type::Sampler);
162 cache_uniform(program.get(), s_tex_ao, "s_tex_ao", gfx::uniform_type::Sampler);
163 cache_uniform(program.get(), s_tex_emissive, "s_tex_emissive", gfx::uniform_type::Sampler);
164
165 cache_uniform(program.get(), u_base_color, "u_base_color", gfx::uniform_type::Vec4);
166 cache_uniform(program.get(), u_subsurface_color, "u_subsurface_color", gfx::uniform_type::Vec4);
167 cache_uniform(program.get(), u_emissive_color, "u_emissive_color", gfx::uniform_type::Vec4);
168 cache_uniform(program.get(), u_surface_data, "u_surface_data", gfx::uniform_type::Vec4);
169 cache_uniform(program.get(), u_tiling, "u_tiling", gfx::uniform_type::Vec4);
170 cache_uniform(program.get(), u_dither_threshold, "u_dither_threshold", gfx::uniform_type::Vec4);
171 cache_uniform(program.get(), u_surface_data2, "u_surface_data2", gfx::uniform_type::Vec4);
172
173 cache_uniform(program.get(), u_camera_wpos, "u_camera_wpos", gfx::uniform_type::Vec4);
174 cache_uniform(program.get(), u_camera_clip_planes, "u_camera_clip_planes", gfx::uniform_type::Vec4);
175 cache_uniform(program.get(), u_lod_params, "u_lod_params", gfx::uniform_type::Vec4);
176 }
177
178 gfx::program::uniform_ptr s_tex_color;
179 gfx::program::uniform_ptr s_tex_normal;
180 gfx::program::uniform_ptr s_tex_roughness;
181 gfx::program::uniform_ptr s_tex_metalness;
183 gfx::program::uniform_ptr s_tex_emissive;
184
185 gfx::program::uniform_ptr u_base_color;
186 gfx::program::uniform_ptr u_subsurface_color;
187 gfx::program::uniform_ptr u_emissive_color;
188 gfx::program::uniform_ptr u_surface_data;
190 gfx::program::uniform_ptr u_dither_threshold;
191 gfx::program::uniform_ptr u_surface_data2;
192
193 gfx::program::uniform_ptr u_camera_wpos;
194 gfx::program::uniform_ptr u_camera_clip_planes;
195 gfx::program::uniform_ptr u_lod_params;
196
197 std::unique_ptr<gpu_program> program;
198 };
199
200 geom_program geom_program_;
201 geom_program geom_program_skinned_;
202 geom_program geom_program_instanced_;
203
204 struct color_lighting : uniforms_cache
205 {
206 void cache_uniforms()
207 {
208 cache_uniform(program.get(), u_light_position, "u_light_position", gfx::uniform_type::Vec4);
209 cache_uniform(program.get(), u_light_direction, "u_light_direction", gfx::uniform_type::Vec4);
210 cache_uniform(program.get(), u_light_data, "u_light_data", gfx::uniform_type::Vec4);
211 cache_uniform(program.get(), u_light_color_intensity, "u_light_color_intensity", gfx::uniform_type::Vec4);
212 cache_uniform(program.get(), u_camera_position, "u_camera_position", gfx::uniform_type::Vec4);
213
214 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
215 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
216 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
217 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
218 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
219 cache_uniform(program.get(), s_tex[5], "s_tex5", gfx::uniform_type::Sampler);
220 cache_uniform(program.get(), s_tex[6], "s_tex6", gfx::uniform_type::Sampler);
221 }
222 gfx::program::uniform_ptr u_light_position;
223 gfx::program::uniform_ptr u_light_direction;
224 gfx::program::uniform_ptr u_light_data;
225 gfx::program::uniform_ptr u_light_color_intensity;
226 gfx::program::uniform_ptr u_camera_position;
227 std::array<gfx::program::uniform_ptr, 7> s_tex;
228
229 std::shared_ptr<gpu_program> program;
230 };
231
232 struct debug_visualization_program : uniforms_cache
233 {
234 void cache_uniforms()
235 {
236 cache_uniform(program.get(), u_params, "u_params", gfx::uniform_type::Vec4);
237 cache_uniform(program.get(), s_tex[0], "s_tex0", gfx::uniform_type::Sampler);
238 cache_uniform(program.get(), s_tex[1], "s_tex1", gfx::uniform_type::Sampler);
239 cache_uniform(program.get(), s_tex[2], "s_tex2", gfx::uniform_type::Sampler);
240 cache_uniform(program.get(), s_tex[3], "s_tex3", gfx::uniform_type::Sampler);
241 cache_uniform(program.get(), s_tex[4], "s_tex4", gfx::uniform_type::Sampler);
242 cache_uniform(program.get(), s_tex[5], "s_tex5", gfx::uniform_type::Sampler);
243 }
244
246 std::array<gfx::program::uniform_ptr, 6> s_tex;
247
248 std::unique_ptr<gpu_program> program;
249
250 } debug_visualization_program_;
251
252 auto get_light_program(const light& l) const -> const color_lighting&;
253 auto get_light_program_no_shadows(const light& l) const -> const color_lighting&;
254 void submit_pbr_material(geom_program& program, const pbr_material& mat);
255 void submit_batched_geometry(gfx::render_pass& pass, const camera& camera);
256 void collect_model_for_batching(const model& model_asset, const math::mat4& world_transform, const pose_mat4& submesh_transforms, uint32_t lod_index, float lod_param);
257
258 color_lighting color_lighting_[uint8_t(light_type::count)][uint8_t(sm_depth::count)][uint8_t(sm_impl::count)];
259 color_lighting color_lighting_no_shadow_[uint8_t(light_type::count)];
260
261 asset_handle<gfx::texture> ibl_brdf_lut_;
262
263 // Static mesh batching system
264 batch_collector batch_collector_;
265
266public:
267
268private:
269
270 std::shared_ptr<int> sentinel_ = std::make_shared<int>(0);
271 int debug_pass_{-1};
272
273};
274
275} // namespace rendering
276} // 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:943
void run_reflection_probe_pass(scene &scn, const camera &camera, gfx::render_view &rview, delta_t dt)
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:971
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:608
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:91
uint32_t visibility_flags
Type alias for visibility flags.
Definition pipeline.h:98
std::chrono::duration< float > delta_t
hpp::small_vector< entt::handle > visibility_set_models_t
Definition pipeline.h:48
@ 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.