Unravel Engine C++ Reference
Loading...
Searching...
No Matches
ssil_pass.h
Go to the documentation of this file.
1#pragma once
2
6#include <graphics/texture.h>
8#include "trace_resolution.h"
9
10namespace unravel
11{
12
14{
15public:
18 {
19 float depth_sigma = 0.02f;
20 float normal_power = 64.0f;
27 float luma_sigma = 4.0f;
28
29 int passes = 4;
42 int max_step = 16;
43 };
44
47 {
48 float history_strength = 0.9f;
52 float depth_threshold = 0.2f;
65 };
66
97
112
113 auto init(rtti::context& ctx) -> bool;
114
121 auto run(gfx::render_view& rview, const run_params& params) -> gfx::texture::ptr;
122
125
126private:
127 auto run_trace(gfx::render_view& rview, const run_params& params) -> gfx::frame_buffer::ptr;
128
129 auto run_spatial_denoise(gfx::render_view& rview,
130 const gfx::frame_buffer::ptr& ssil_curr,
131 const gfx::frame_buffer::ptr& g_buffer,
132 const gfx::texture::ptr& moments,
133 const camera* cam,
135
144 auto run_temporal_resolve(gfx::render_view& rview,
145 gfx::frame_buffer::ptr ssil_input,
146 const gfx::frame_buffer::ptr& g_buffer,
147 const gfx::texture::ptr& prev_depth,
148 const camera* cam,
149 const ssil_settings& settings,
150 gfx::frame_buffer::ptr& out_result_fb,
151 gfx::texture::ptr& out_moments_tex) -> bool;
152
155 auto run_upsample(gfx::render_view& rview,
156 const gfx::frame_buffer::ptr& ssil_input,
157 const gfx::frame_buffer::ptr& g_buffer,
158 const camera* cam,
160
161 auto create_or_update_ssil_fb(gfx::render_view& rview,
162 const std::string& name,
163 const gfx::frame_buffer::ptr& reference,
165 uint64_t extra_flags = 0) -> gfx::frame_buffer::ptr;
166
167 auto create_or_update_ssil_tex(gfx::render_view& rview,
168 const std::string& name,
169 const gfx::frame_buffer::ptr& reference,
171 uint64_t extra_flags = 0) -> gfx::texture::ptr;
172
175 auto create_or_update_ssil_fb_mrt(gfx::render_view& rview,
176 const std::string& fbo_name,
177 const std::string& color_tex_name,
178 const std::string& moments_tex_name,
179 const gfx::frame_buffer::ptr& reference,
181 uint64_t extra_flags = 0) -> gfx::frame_buffer::ptr;
182
185 void release_history_resources(gfx::render_view& rview);
186
190 void release_denoise_resources(gfx::render_view& rview);
191
192 // Trace program (fullscreen fragment shader)
193 struct trace_program : uniforms_cache
194 {
195 gpu_program::ptr program;
196 gfx::program::uniform_ptr u_ssil_params;
197 gfx::program::uniform_ptr u_ssil_params2;
199 gfx::program::uniform_ptr u_ssil_params3;
201 gfx::program::uniform_ptr u_ssil_resolution;
205 gfx::program::uniform_ptr s_emissive;
207 gfx::program::uniform_ptr s_prev_ssil;
208 gfx::program::uniform_ptr s_irradiance;
209
210 void cache_uniforms()
211 {
212 cache_uniform(program.get(), u_ssil_params, "u_ssil_params", gfx::uniform_type::Vec4);
213 cache_uniform(program.get(), u_ssil_params2, "u_ssil_params2", gfx::uniform_type::Vec4);
214 cache_uniform(program.get(), u_ssil_params3, "u_ssil_params3", gfx::uniform_type::Vec4);
215 cache_uniform(program.get(), u_ssil_resolution, "u_ssil_resolution", gfx::uniform_type::Vec4);
216 cache_uniform(program.get(), s_color, "s_color", gfx::uniform_type::Sampler);
217 cache_uniform(program.get(), s_normal, "s_normal", gfx::uniform_type::Sampler);
218 cache_uniform(program.get(), s_hiz, "s_hiz", gfx::uniform_type::Sampler);
219 cache_uniform(program.get(), s_emissive, "s_emissive", gfx::uniform_type::Sampler);
220 cache_uniform(program.get(), s_albedo, "s_albedo", gfx::uniform_type::Sampler);
221 cache_uniform(program.get(), s_prev_ssil, "s_prev_ssil", gfx::uniform_type::Sampler);
222 cache_uniform(program.get(), s_irradiance, "s_irradiance", gfx::uniform_type::Sampler);
223 }
224
225 auto is_valid() const -> bool { return program && program->is_valid(); }
226 } trace_program_;
227
228 // Spatial denoise compute program
229 struct denoise_program : uniforms_cache
230 {
231 gpu_program::ptr program;
232 gfx::program::uniform_ptr u_denoise_params;
233 gfx::program::uniform_ptr u_denoise_params2;
234 gfx::program::uniform_ptr s_ssil_input;
237 gfx::program::uniform_ptr s_ssil_moments;
238 gfx::program::uniform_ptr s_ssil_variance;
239
240 void cache_uniforms()
241 {
242 cache_uniform(program.get(), u_denoise_params, "u_denoise_params", gfx::uniform_type::Vec4);
243 cache_uniform(program.get(), u_denoise_params2, "u_denoise_params2", gfx::uniform_type::Vec4);
244 cache_uniform(program.get(), s_ssil_input, "s_ssil_input", gfx::uniform_type::Sampler);
245 cache_uniform(program.get(), s_normal, "s_normal", gfx::uniform_type::Sampler);
246 cache_uniform(program.get(), s_depth, "s_depth", gfx::uniform_type::Sampler);
247 cache_uniform(program.get(), s_ssil_moments, "s_ssil_moments", gfx::uniform_type::Sampler);
248 cache_uniform(program.get(), s_ssil_variance, "s_ssil_variance", gfx::uniform_type::Sampler);
249 }
250
251 auto is_valid() const -> bool { return program && program->is_valid(); }
252 } denoise_program_;
253
254 // Geometry-aware 2x downsample compute program. Produces the half-resolution input the
255 // wide a-trous passes run on (see cs_ssil_downsample.sc).
256 struct downsample_program : uniforms_cache
257 {
258 gpu_program::ptr program;
259 gfx::program::uniform_ptr u_downsample_params;
260 gfx::program::uniform_ptr s_ssil_input;
263 gfx::program::uniform_ptr s_ssil_variance;
264
265 void cache_uniforms()
266 {
267 cache_uniform(program.get(), u_downsample_params, "u_downsample_params", gfx::uniform_type::Vec4);
268 cache_uniform(program.get(), s_ssil_input, "s_ssil_input", gfx::uniform_type::Sampler);
269 cache_uniform(program.get(), s_normal, "s_normal", gfx::uniform_type::Sampler);
270 cache_uniform(program.get(), s_depth, "s_depth", gfx::uniform_type::Sampler);
271 cache_uniform(program.get(), s_ssil_variance, "s_ssil_variance", gfx::uniform_type::Sampler);
272 }
273
274 auto is_valid() const -> bool { return program && program->is_valid(); }
275 } downsample_program_;
276
277 // Temporal resolve program (fullscreen fragment shader)
278 struct temporal_program : uniforms_cache
279 {
280 gpu_program::ptr program;
281 gfx::program::uniform_ptr u_temporal_params;
283 gfx::program::uniform_ptr u_temporal_params2;
284 gfx::program::uniform_ptr u_temporal_resolution;
285 gfx::program::uniform_ptr u_prev_view_proj;
286 gfx::program::uniform_ptr s_ssil_curr;
287 gfx::program::uniform_ptr s_ssil_history;
289 gfx::program::uniform_ptr s_prev_depth;
290 gfx::program::uniform_ptr s_ssil_moments_history;
293
294 void cache_uniforms()
295 {
296 cache_uniform(program.get(), u_temporal_params, "u_temporal_params", gfx::uniform_type::Vec4);
297 cache_uniform(program.get(), u_temporal_params2, "u_temporal_params2", gfx::uniform_type::Vec4);
298 cache_uniform(program.get(), u_temporal_resolution, "u_temporal_resolution", gfx::uniform_type::Vec4);
299 cache_uniform(program.get(), u_prev_view_proj, "u_prev_view_proj", gfx::uniform_type::Mat4);
300 cache_uniform(program.get(), s_ssil_curr, "s_ssil_curr", gfx::uniform_type::Sampler);
301 cache_uniform(program.get(), s_ssil_history, "s_ssil_history", gfx::uniform_type::Sampler);
302 cache_uniform(program.get(), s_depth, "s_depth", gfx::uniform_type::Sampler);
303 cache_uniform(program.get(), s_prev_depth, "s_prev_depth", gfx::uniform_type::Sampler);
304 cache_uniform(program.get(), s_ssil_moments_history, "s_ssil_moments_history", gfx::uniform_type::Sampler);
305 cache_uniform(program.get(), s_normal, "s_normal", gfx::uniform_type::Sampler);
306 }
307
308 auto is_valid() const -> bool { return program && program->is_valid(); }
309 } temporal_program_;
310
311 // Joint-bilateral upsample program (fullscreen fragment shader)
312 struct upsample_program : uniforms_cache
313 {
314 gpu_program::ptr program;
315 gfx::program::uniform_ptr u_upsample_params;
316 gfx::program::uniform_ptr s_ssil_input;
319
320 void cache_uniforms()
321 {
322 cache_uniform(program.get(), u_upsample_params, "u_upsample_params", gfx::uniform_type::Vec4);
323 cache_uniform(program.get(), s_ssil_input, "s_ssil_input", gfx::uniform_type::Sampler);
324 cache_uniform(program.get(), s_normal, "s_normal", gfx::uniform_type::Sampler);
325 cache_uniform(program.get(), s_depth, "s_depth", gfx::uniform_type::Sampler);
326 }
327
328 auto is_valid() const -> bool { return program && program->is_valid(); }
329 } upsample_program_;
330};
331
332} // namespace unravel
Class representing a camera. Contains functionality for manipulating and updating a camera....
Definition camera.h:62
std::shared_ptr< gpu_program > ptr
Definition gpu_program.h:19
auto run(gfx::render_view &rview, const run_params &params) -> gfx::texture::ptr
void release_resources(gfx::render_view &rview)
Releases all GPU resources owned by this pass from the render_view.
auto init(rtti::context &ctx) -> bool
Definition ssil_pass.cpp:13
std::string name
Definition hub.cpp:33
std::shared_ptr< uniform > uniform_ptr
Definition program.h:19
gfx::texture::ptr prev_depth
Definition ssil_pass.h:103
gfx::texture::ptr irradiance_sh
Definition ssil_pass.h:108
gfx::texture::ptr prev_ssil
Definition ssil_pass.h:104
gfx::frame_buffer::ptr g_buffer
Definition ssil_pass.h:100
gfx::texture::ptr hiz_buffer
Definition ssil_pass.h:101
gfx::texture::ptr direct_lighting
Definition ssil_pass.h:102
Spatial denoise parameters (a-trous wavelet filter)
Definition ssil_pass.h:18
spatial_denoise_settings spatial_denoise
Definition ssil_pass.h:92
Temporal accumulation parameters.
Definition ssil_pass.h:47
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.