Unravel Engine C++ Reference
Loading...
Searching...
No Matches
ssr_component.cpp
Go to the documentation of this file.
1#include "ssr_component.hpp"
3
6
7namespace unravel
8{
9
11{
12 entt::meta_factory<trace_resolution>{}
13 .type("trace_resolution"_hs)
15 entt::attribute{"name", "trace_resolution"},
16 entt::attribute{"pretty_name", "Trace Resolution"},
17 })
18 .data<trace_resolution::full>("full"_hs)
20 entt::attribute{"name", "full"},
21 entt::attribute{"pretty_name", "Full"},
22 })
23 .data<trace_resolution::half>("half"_hs)
25 entt::attribute{"name", "half"},
26 entt::attribute{"pretty_name", "Half (1/2)"},
27 })
28 .data<trace_resolution::quarter>("quarter"_hs)
30 entt::attribute{"name", "quarter"},
31 entt::attribute{"pretty_name", "Quarter (1/4)"},
32 });
33}
34
36{
37 using fidelityfx_settings = ssr_pass::fidelityfx_ssr_settings;
41
42 auto cone_tracing_predicate_entt = entt::property_predicate<bool>([](const entt::meta_any& obj)
43 {
44 auto data = obj.try_cast<fidelityfx_settings>();
45 return data->enable_cone_tracing;
46 });
47
48 auto temporal_predicate_entt = entt::property_predicate<bool>([](const entt::meta_any& obj)
49 {
50 if(auto data = obj.try_cast<fidelityfx_settings>())
51 {
52 return data->enable_temporal_accumulation;
53 }
54 return false;
55 });
56
57 auto spatial_denoise_predicate_entt = entt::property_predicate<bool>([](const entt::meta_any& obj)
58 {
59 if(auto data = obj.try_cast<fidelityfx_settings>())
60 {
61 return data->enable_spatial_denoise;
62 }
63 return false;
64 });
65
66 entt::meta_factory<cone_tracing_settings>{}
67 .type("ssr_pass::fidelityfx_ssr_settings::cone_tracing_settings"_hs)
69 entt::attribute{"name", "ssr_pass::fidelityfx_ssr_settings::cone_tracing_settings"},
70 entt::attribute{"pretty_name", "Cone Tracing Settings"},
71 })
72 .data<&cone_tracing_settings::cone_angle_bias>("cone_angle_bias"_hs)
74 entt::attribute{"name", "cone_angle_bias"},
75 entt::attribute{"pretty_name", "Cone Angle Bias"},
76 entt::attribute{"min", 0.001f},
77 entt::attribute{"max", 0.1f},
78 entt::attribute{"tooltip", "Controls cone growth rate for glossy reflections"},
79 })
80 .data<&cone_tracing_settings::max_mip_level>("max_mip_level"_hs)
82 entt::attribute{"name", "max_mip_level"},
83 entt::attribute{"pretty_name", "Max Mip Level"},
84 entt::attribute{"min", 1},
85 entt::attribute{"max", 10},
86 entt::attribute{"tooltip", "Number of blur mip levels - 1"},
87 })
88 .data<&cone_tracing_settings::blur_base_sigma>("blur_base_sigma"_hs)
90 entt::attribute{"name", "blur_base_sigma"},
91 entt::attribute{"pretty_name", "Blur Base Sigma"},
92 entt::attribute{"min", 0.1f},
93 entt::attribute{"max", 5.0f},
94 entt::attribute{"tooltip", "Base blur sigma for mip generation (CPU-side only)"},
95 });
96
97 // -------------------------------------------------------------------------
98 // Temporal Accumulation Settings (matches ApplyTemporalAccumulation v2)
99 // -------------------------------------------------------------------------
100
101 entt::meta_factory<temporal_settings>{}
102 .type("ssr_pass::fidelityfx_ssr_settings::temporal_settings"_hs)
104 entt::attribute{"name", "ssr_pass::fidelityfx_ssr_settings::temporal_settings"},
105 entt::attribute{"pretty_name", "Temporal Accumulation Settings"},
106 })
107 .data<&temporal_settings::history_strength>("history_strength"_hs)
109 entt::attribute{"name", "history_strength"},
110 entt::attribute{"pretty_name", "History Strength"},
111 entt::attribute{"min", 0.0f},
112 entt::attribute{"max", 1.0f},
113 entt::attribute{"tooltip", "Controls how long reflections keep history.\n0 = real-time only · 1 = maximum denoise"},
114 })
115 .data<&temporal_settings::depth_threshold>("depth_threshold"_hs)
117 entt::attribute{"name", "depth_threshold"},
118 entt::attribute{"pretty_name", "Edge Threshold"},
119 entt::attribute{"min", 0.000f},
120 entt::attribute{"max", 0.030f},
121 entt::attribute{"tooltip", "Depth difference allowed before history is discarded.\nLower = crisper edges, higher = smoother but risk of bleed"},
122 })
123 .data<&temporal_settings::roughness_sensitivity>("roughness_sensitivity"_hs)
125 entt::attribute{"name", "roughness_sensitivity"},
126 entt::attribute{"pretty_name", "Material Sensitivity"},
127 entt::attribute{"min", 0.0f},
128 entt::attribute{"max", 1.0f},
129 entt::attribute{"tooltip", "How strongly rough surfaces shorten history.\n0 = same for every material · 1 = glossy keeps more history"},
130 })
131 .data<&temporal_settings::motion_scale_pixels>("motion_scale_pixels"_hs)
133 entt::attribute{"name", "motion_scale_pixels"},
134 entt::attribute{"pretty_name", "Motion Scale Pixels"},
135 entt::attribute{"min", 0.0f},
136 entt::attribute{"max", 1000.0f},
137 entt::attribute{"tooltip", "Motion scale in pixels"},
138 })
139 .data<&temporal_settings::normal_dot_threshold>("normal_dot_threshold"_hs)
141 entt::attribute{"name", "normal_dot_threshold"},
142 entt::attribute{"pretty_name", "Normal Dot Threshold"},
143 entt::attribute{"min", 0.0f},
144 entt::attribute{"max", 1.0f},
145 entt::attribute{"tooltip", "Normal dot threshold for motion detection"},
146 })
147 .data<&temporal_settings::max_accum_frames>("max_accum_frames"_hs)
149 entt::attribute{"name", "max_accum_frames"},
150 entt::attribute{"pretty_name", "Max Accum Frames"},
151 entt::attribute{"min", 1},
152 entt::attribute{"max", 16},
153 entt::attribute{"tooltip", "Maximum temporal accumulation frames"},
154 });
155
156 // -------------------------------------------------------------------------
157 // Spatial Denoise Settings (a-trous wavelet filter before temporal resolve)
158 // -------------------------------------------------------------------------
159 entt::meta_factory<spatial_denoise_settings>{}
160 .type("ssr_pass::fidelityfx_ssr_settings::spatial_denoise_settings"_hs)
162 entt::attribute{"name", "ssr_pass::fidelityfx_ssr_settings::spatial_denoise_settings"},
163 entt::attribute{"pretty_name", "Spatial Denoise Settings"},
164 })
165 .data<&spatial_denoise_settings::depth_sigma>("depth_sigma"_hs)
167 entt::attribute{"name", "depth_sigma"},
168 entt::attribute{"pretty_name", "Depth Sigma"},
169 entt::attribute{"min", 0.005f},
170 entt::attribute{"max", 0.05f},
171 entt::attribute{"tooltip", "Depth edge-stopping threshold. Lower = stricter edges, higher = looser"},
172 })
173 .data<&spatial_denoise_settings::normal_power>("normal_power"_hs)
175 entt::attribute{"name", "normal_power"},
176 entt::attribute{"pretty_name", "Normal Power"},
177 entt::attribute{"min", 16.0f},
178 entt::attribute{"max", 128.0f},
179 entt::attribute{"tooltip", "Normal edge-stopping exponent. Higher = stricter edges"},
180 })
181 .data<&spatial_denoise_settings::luma_sigma>("luma_sigma"_hs)
183 entt::attribute{"name", "luma_sigma"},
184 entt::attribute{"pretty_name", "Luma Sigma"},
185 entt::attribute{"min", 0.3f},
186 entt::attribute{"max", 2.0f},
187 entt::attribute{"tooltip", "Luminance edge-stopping threshold. Lower = sharper, higher = smoother"},
188 })
189 .data<&spatial_denoise_settings::passes>("passes"_hs)
191 entt::attribute{"name", "passes"},
192 entt::attribute{"pretty_name", "Passes"},
193 entt::attribute{"min", 1},
194 entt::attribute{"max", 5},
195 entt::attribute{"tooltip", "Number of a-trous filter passes. More passes = wider blur reach but higher cost"},
196 });
197
198 entt::meta_factory<fidelityfx_settings>{}
199 .type("ssr_pass::fidelityfx_ssr_settings"_hs)
201 entt::attribute{"name", "ssr_pass::fidelityfx_ssr_settings"},
202 entt::attribute{"pretty_name", "FidelityFX SSR Settings"},
203 })
204 .data<&fidelityfx_settings::max_rays>("max_rays"_hs)
206 entt::attribute{"name", "max_rays"},
207 entt::attribute{"pretty_name", "Max Rays"},
208 entt::attribute{"min", 1},
209 entt::attribute{"max", 64},
210 entt::attribute{"tooltip", "Maximum rays for rough surfaces (future: cone tracing)"},
211 })
212 .data<&fidelityfx_settings::max_steps>("max_steps"_hs)
214 entt::attribute{"name", "max_steps"},
215 entt::attribute{"pretty_name", "Max Steps"},
216 entt::attribute{"min", 8},
217 entt::attribute{"max", 200},
218 entt::attribute{"tooltip", "Maximum ray marching steps for hierarchical traversal"},
219 })
220 .data<&fidelityfx_settings::depth_tolerance>("depth_tolerance"_hs)
222 entt::attribute{"name", "depth_tolerance"},
223 entt::attribute{"pretty_name", "Depth Tolerance"},
224 entt::attribute{"min", 0.01f},
225 entt::attribute{"max", 2.0f},
226 entt::attribute{"tooltip", "Depth tolerance for hit validation"},
227 })
228 .data<&fidelityfx_settings::brightness>("brightness"_hs)
230 entt::attribute{"name", "brightness"},
231 entt::attribute{"pretty_name", "Brightness"},
232 entt::attribute{"min", 0.1f},
233 entt::attribute{"max", 3.0f},
234 entt::attribute{"tooltip", "Reflection brightness multiplier"},
235 })
236 .data<&fidelityfx_settings::facing_reflections_fading>("facing_reflections_fading"_hs)
238 entt::attribute{"name", "facing_reflections_fading"},
239 entt::attribute{"pretty_name", "Facing Reflections Fading"},
240 entt::attribute{"min", 0.0f},
241 entt::attribute{"max", 1.0f},
242 entt::attribute{"tooltip", "Fade factor for camera-facing reflections"},
243 })
244 .data<&fidelityfx_settings::roughness_depth_tolerance>("roughness_depth_tolerance"_hs)
246 entt::attribute{"name", "roughness_depth_tolerance"},
247 entt::attribute{"pretty_name", "Roughness Depth Tolerance"},
248 entt::attribute{"min", 0.0f},
249 entt::attribute{"max", 2.0f},
250 entt::attribute{"tooltip", "Additional depth tolerance for rough surfaces"},
251 })
252 .data<&fidelityfx_settings::fade_in_start>("fade_in_start"_hs)
254 entt::attribute{"name", "fade_in_start"},
255 entt::attribute{"pretty_name", "Fade In Start"},
256 entt::attribute{"min", 0.0f},
257 entt::attribute{"max", 1.0f},
258 entt::attribute{"tooltip", "Screen edge fade start"},
259 })
260 .data<&fidelityfx_settings::fade_in_end>("fade_in_end"_hs)
262 entt::attribute{"name", "fade_in_end"},
263 entt::attribute{"pretty_name", "Fade In End"},
264 entt::attribute{"min", 0.0f},
265 entt::attribute{"max", 1.0f},
266 entt::attribute{"tooltip", "Screen edge fade end"},
267 })
268 .data<&fidelityfx_settings::resolution>("resolution"_hs)
270 entt::attribute{"name", "resolution"},
271 entt::attribute{"pretty_name", "Trace Resolution"},
272 entt::attribute{"tooltip", "Downscale divisor for SSR trace buffers.\nSSR is capped at Half at runtime - Quarter degrades Hi-Z traversal, temporal clamp and the denoiser severely."},
273 })
274 // .data<&fidelityfx_settings::enable_cone_tracing>("enable_cone_tracing"_hs)
275 // .custom<entt::attributes>(entt::attributes{
276 // entt::attribute{"name", "enable_cone_tracing"},
277 // entt::attribute{"pretty_name", "Enable Cone Tracing"},
278 // entt::attribute{"tooltip", "Enable cone tracing for glossy reflections"},
279 // })
280 // .data<&fidelityfx_settings::cone_tracing>("cone_tracing"_hs)
281 // .custom<entt::attributes>(entt::attributes{
282 // entt::attribute{"name", "cone_tracing"},
283 // entt::attribute{"predicate", cone_tracing_predicate_entt},
284 // entt::attribute{"pretty_name", "Cone Tracing"},
285 // entt::attribute{"tooltip", "Cone tracing specific settings"},
286 // entt::attribute{"flattable", true},
287 // })
288 .data<&fidelityfx_settings::enable_spatial_denoise>("enable_spatial_denoise"_hs)
290 entt::attribute{"name", "enable_spatial_denoise"},
291 entt::attribute{"pretty_name", "Enable Spatial Denoise"},
292 entt::attribute{"tooltip", "Enable spatial denoising (a-trous wavelet) before temporal resolve"},
293 })
294 .data<&fidelityfx_settings::spatial_denoise>("spatial_denoise"_hs)
296 entt::attribute{"name", "spatial_denoise"},
297 entt::attribute{"predicate", spatial_denoise_predicate_entt},
298 entt::attribute{"pretty_name", "Spatial Denoise"},
299 entt::attribute{"tooltip", "Spatial denoise settings (edge-preserving a-trous filter)"},
300 // entt::attribute{"flattable", true},
301 })
302 .data<&fidelityfx_settings::enable_temporal_accumulation>("enable_temporal_accumulation"_hs)
304 entt::attribute{"name", "enable_temporal_accumulation"},
305 entt::attribute{"pretty_name", "Enable Temporal"},
306 entt::attribute{"tooltip", "Enable temporal accumulation to reduce noise over multiple frames"},
307 })
308 .data<&fidelityfx_settings::temporal>("temporal"_hs)
310 entt::attribute{"name", "temporal"},
311 entt::attribute{"predicate", temporal_predicate_entt},
312 entt::attribute{"pretty_name", "Temporal Accumulation"},
313 entt::attribute{"tooltip", "Temporal accumulation settings"},
314 // entt::attribute{"flattable", true},
315 });
316
317
318}
319
321{
322 using ssr_settings = ssr_pass::ssr_settings;
323
324
325 entt::meta_factory<ssr_settings>{}
326 .type("ssr_pass::ssr_settings"_hs)
328 entt::attribute{"name", "ssr_pass::ssr_settings"},
329 entt::attribute{"pretty_name", "SSR Settings"},
330 })
331 .data<&ssr_settings::fidelityfx>("fidelityfx"_hs)
333 entt::attribute{"name", "fidelityfx"},
334 entt::attribute{"pretty_name", "FidelityFX Settings"},
335 entt::attribute{"tooltip", "Settings for AMD FidelityFX SSSR implementation"},
336 entt::attribute{"flattable", true},
337 });
338}
339
340// Serialization for cone_tracing_settings
342{
343 try_save(ar, ser20::make_nvp("cone_angle_bias", obj.cone_angle_bias));
344 try_save(ar, ser20::make_nvp("max_mip_level", obj.max_mip_level));
345 try_save(ar, ser20::make_nvp("blur_base_sigma", obj.blur_base_sigma));
346}
349
351{
352 try_load(ar, ser20::make_nvp("cone_angle_bias", obj.cone_angle_bias));
353 try_load(ar, ser20::make_nvp("max_mip_level", obj.max_mip_level));
354 try_load(ar, ser20::make_nvp("blur_base_sigma", obj.blur_base_sigma));
355}
358
359// Serialization for temporal_settings
361{
362 try_save(ar, ser20::make_nvp("history_strength", obj.history_strength));
363 try_save(ar, ser20::make_nvp("depth_threshold", obj.depth_threshold));
364 try_save(ar, ser20::make_nvp("roughness_sensitivity", obj.roughness_sensitivity));
365 try_save(ar, ser20::make_nvp("motion_scale_pixels", obj.motion_scale_pixels));
366 try_save(ar, ser20::make_nvp("normal_dot_threshold", obj.normal_dot_threshold));
367 try_save(ar, ser20::make_nvp("max_accum_frames", obj.max_accum_frames));
368}
371
373{
374 try_load(ar, ser20::make_nvp("history_strength", obj.history_strength));
375 try_load(ar, ser20::make_nvp("depth_threshold", obj.depth_threshold));
376 try_load(ar, ser20::make_nvp("roughness_sensitivity", obj.roughness_sensitivity));
377 try_load(ar, ser20::make_nvp("motion_scale_pixels", obj.motion_scale_pixels));
378 try_load(ar, ser20::make_nvp("normal_dot_threshold", obj.normal_dot_threshold));
379 try_load(ar, ser20::make_nvp("max_accum_frames", obj.max_accum_frames));
380}
383
384// Serialization for spatial_denoise_settings
386{
387 try_save(ar, ser20::make_nvp("depth_sigma", obj.depth_sigma));
388 try_save(ar, ser20::make_nvp("normal_power", obj.normal_power));
389 try_save(ar, ser20::make_nvp("luma_sigma", obj.luma_sigma));
390 try_save(ar, ser20::make_nvp("passes", obj.passes));
391}
394
396{
397 try_load(ar, ser20::make_nvp("depth_sigma", obj.depth_sigma));
398 try_load(ar, ser20::make_nvp("normal_power", obj.normal_power));
399 try_load(ar, ser20::make_nvp("luma_sigma", obj.luma_sigma));
400 try_load(ar, ser20::make_nvp("passes", obj.passes));
401}
404
405// Serialization for fidelityfx_ssr_settings
407{
408 try_save(ar, ser20::make_nvp("max_steps", obj.max_steps));
409 try_save(ar, ser20::make_nvp("max_rays", obj.max_rays));
410 try_save(ar, ser20::make_nvp("depth_tolerance", obj.depth_tolerance));
411 try_save(ar, ser20::make_nvp("brightness", obj.brightness));
412 try_save(ar, ser20::make_nvp("facing_reflections_fading", obj.facing_reflections_fading));
413 try_save(ar, ser20::make_nvp("roughness_depth_tolerance", obj.roughness_depth_tolerance));
414 try_save(ar, ser20::make_nvp("fade_in_start", obj.fade_in_start));
415 try_save(ar, ser20::make_nvp("fade_in_end", obj.fade_in_end));
416 try_save(ar, ser20::make_nvp("resolution", obj.resolution));
417 try_save(ar, ser20::make_nvp("enable_cone_tracing", obj.enable_cone_tracing));
418 try_save(ar, ser20::make_nvp("cone_tracing", obj.cone_tracing));
419 try_save(ar, ser20::make_nvp("enable_temporal_accumulation", obj.enable_temporal_accumulation));
420 try_save(ar, ser20::make_nvp("temporal", obj.temporal));
421 try_save(ar, ser20::make_nvp("enable_spatial_denoise", obj.enable_spatial_denoise));
422 try_save(ar, ser20::make_nvp("spatial_denoise", obj.spatial_denoise));
423}
426
428{
429 try_load(ar, ser20::make_nvp("max_steps", obj.max_steps));
430 try_load(ar, ser20::make_nvp("max_rays", obj.max_rays));
431 try_load(ar, ser20::make_nvp("depth_tolerance", obj.depth_tolerance));
432 try_load(ar, ser20::make_nvp("brightness", obj.brightness));
433 try_load(ar, ser20::make_nvp("facing_reflections_fading", obj.facing_reflections_fading));
434 try_load(ar, ser20::make_nvp("roughness_depth_tolerance", obj.roughness_depth_tolerance));
435 try_load(ar, ser20::make_nvp("fade_in_start", obj.fade_in_start));
436 try_load(ar, ser20::make_nvp("fade_in_end", obj.fade_in_end));
437 // Backwards compat: legacy scenes store the old boolean under `enable_half_res`.
438 // Try the new enum field first; fall back to the bool when missing.
439 if(!try_load(ar, ser20::make_nvp("resolution", obj.resolution)))
440 {
441 bool legacy_half_res = false;
442 if(try_load(ar, ser20::make_nvp("enable_half_res", legacy_half_res)))
443 {
444 obj.resolution = legacy_half_res ? trace_resolution::half : trace_resolution::full;
445 }
446 }
447 try_load(ar, ser20::make_nvp("enable_cone_tracing", obj.enable_cone_tracing));
448 try_load(ar, ser20::make_nvp("cone_tracing", obj.cone_tracing));
449 try_load(ar, ser20::make_nvp("enable_temporal_accumulation", obj.enable_temporal_accumulation));
450 try_load(ar, ser20::make_nvp("temporal", obj.temporal));
451 try_load(ar, ser20::make_nvp("enable_spatial_denoise", obj.enable_spatial_denoise));
452 try_load(ar, ser20::make_nvp("spatial_denoise", obj.spatial_denoise));
453}
456
457// Serialization for ssr_settings
459{
460 try_save(ar, ser20::make_nvp("fidelityfx", obj.fidelityfx));
461}
464
466{
467 try_load(ar, ser20::make_nvp("fidelityfx", obj.fidelityfx));
468}
471
473{
474
475 entt::meta_factory<ssr_component>{}
476 .type("ssr_component"_hs)
478 entt::attribute{"name", "ssr_component"},
479 entt::attribute{"category", "RENDERING"},
480 entt::attribute{"pretty_name", "SSR"},
481 })
482 .func<&component_meta<ssr_component>::exists>("component_exists"_hs)
483 .func<&component_meta<ssr_component>::add>("component_add"_hs)
484 .func<&component_meta<ssr_component>::remove>("component_remove"_hs)
485 .func<&component_meta<ssr_component>::save>("component_save"_hs)
486 .func<&component_meta<ssr_component>::load>("component_load"_hs)
487 .data<&ssr_component::enabled>("enabled"_hs)
488 .custom<entt::attributes>(entt::attributes{
489 entt::attribute{"name", "enabled"},
490 entt::attribute{"pretty_name", "Enabled"},
491 entt::attribute{"tooltip", "Enable/disable Screen Space Reflections"},
492 })
493 .data<&ssr_component::settings>("settings"_hs)
495 entt::attribute{"name", "settings"},
496 entt::attribute{"pretty_name", "Settings"},
497 entt::attribute{"flattable", true},
498 });
499}
500
502{
503 try_save(ar, ser20::make_nvp("enabled", obj.enabled));
504 try_save(ar, ser20::make_nvp("settings", obj.settings));
505}
508
510{
511 try_load(ar, ser20::make_nvp("enabled", obj.enabled));
512 try_load(ar, ser20::make_nvp("settings", obj.settings));
513}
516} // namespace unravel
bool enabled
Whether SSR is enabled.
auto property_predicate(property_predicate_t< T > predicate) -> property_predicate_t< T >
Definition reflection.h:89
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
#define REFLECT(cls)
Definition reflection.h:149
#define REFLECT_INLINE(cls)
Definition reflection.h:144
#define SAVE_INSTANTIATE(cls, Archive)
#define LOAD(cls)
auto try_save(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
#define LOAD_INSTANTIATE(cls, Archive)
#define SAVE(cls)
#define LOAD_INLINE(cls)
#define SAVE_INLINE(cls)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Spatial denoise parameters (a-trous wavelet filter between trace and temporal resolve)
Definition ssr_pass.h:64
Combined SSR settings.
Definition ssr_pass.h:77