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 using fidelityfx_settings = ssr_pass::fidelityfx_ssr_settings;
15
16 auto cone_tracing_predicate_entt = entt::property_predicate([](const entt::meta_any& obj)
17 {
18 auto data = obj.try_cast<fidelityfx_settings>();
19 return data->enable_cone_tracing;
20 });
21
22 auto temporal_predicate_entt = entt::property_predicate([](const entt::meta_any& obj) -> bool
23 {
24 if(auto data = obj.try_cast<fidelityfx_settings>())
25 {
26 return data->enable_temporal_accumulation;
27 }
28 return false;
29 });
30
31 entt::meta_factory<cone_tracing_settings>{}
32 .type("ssr_pass::fidelityfx_ssr_settings::cone_tracing_settings"_hs)
34 entt::attribute{"name", "ssr_pass::fidelityfx_ssr_settings::cone_tracing_settings"},
35 entt::attribute{"pretty_name", "Cone Tracing Settings"},
36 })
37 .data<&cone_tracing_settings::cone_angle_bias>("cone_angle_bias"_hs)
39 entt::attribute{"name", "cone_angle_bias"},
40 entt::attribute{"pretty_name", "Cone Angle Bias"},
41 entt::attribute{"min", 0.001f},
42 entt::attribute{"max", 0.1f},
43 entt::attribute{"tooltip", "Controls cone growth rate for glossy reflections"},
44 })
45 .data<&cone_tracing_settings::max_mip_level>("max_mip_level"_hs)
47 entt::attribute{"name", "max_mip_level"},
48 entt::attribute{"pretty_name", "Max Mip Level"},
49 entt::attribute{"min", 1},
50 entt::attribute{"max", 10},
51 entt::attribute{"tooltip", "Number of blur mip levels - 1"},
52 })
53 .data<&cone_tracing_settings::blur_base_sigma>("blur_base_sigma"_hs)
55 entt::attribute{"name", "blur_base_sigma"},
56 entt::attribute{"pretty_name", "Blur Base Sigma"},
57 entt::attribute{"min", 0.1f},
58 entt::attribute{"max", 5.0f},
59 entt::attribute{"tooltip", "Base blur sigma for mip generation (CPU-side only)"},
60 });
61
62 // -------------------------------------------------------------------------
63 // Temporal Accumulation Settings (matches ApplyTemporalAccumulation v2)
64 // -------------------------------------------------------------------------
65
66 entt::meta_factory<temporal_settings>{}
67 .type("ssr_pass::fidelityfx_ssr_settings::temporal_settings"_hs)
69 entt::attribute{"name", "ssr_pass::fidelityfx_ssr_settings::temporal_settings"},
70 entt::attribute{"pretty_name", "Temporal Accumulation Settings"},
71 })
72 .data<&temporal_settings::history_strength>("history_strength"_hs)
74 entt::attribute{"name", "history_strength"},
75 entt::attribute{"pretty_name", "History Strength"},
76 entt::attribute{"min", 0.0f},
77 entt::attribute{"max", 1.0f},
78 entt::attribute{"tooltip", "Controls how long reflections keep history.\n0 = real-time only · 1 = maximum denoise"},
79 })
80 .data<&temporal_settings::depth_threshold>("depth_threshold"_hs)
82 entt::attribute{"name", "depth_threshold"},
83 entt::attribute{"pretty_name", "Edge Threshold"},
84 entt::attribute{"min", 0.000f},
85 entt::attribute{"max", 0.030f},
86 entt::attribute{"tooltip", "Depth difference allowed before history is discarded.\nLower = crisper edges, higher = smoother but risk of bleed"},
87 })
88 .data<&temporal_settings::roughness_sensitivity>("roughness_sensitivity"_hs)
90 entt::attribute{"name", "roughness_sensitivity"},
91 entt::attribute{"pretty_name", "Material Sensitivity"},
92 entt::attribute{"min", 0.0f},
93 entt::attribute{"max", 1.0f},
94 entt::attribute{"tooltip", "How strongly rough surfaces shorten history.\n0 = same for every material · 1 = glossy keeps more history"},
95 })
96 .data<&temporal_settings::motion_scale_pixels>("motion_scale_pixels"_hs)
98 entt::attribute{"name", "motion_scale_pixels"},
99 entt::attribute{"pretty_name", "Motion Scale Pixels"},
100 entt::attribute{"min", 0.0f},
101 entt::attribute{"max", 1000.0f},
102 entt::attribute{"tooltip", "Motion scale in pixels"},
103 })
104 .data<&temporal_settings::normal_dot_threshold>("normal_dot_threshold"_hs)
106 entt::attribute{"name", "normal_dot_threshold"},
107 entt::attribute{"pretty_name", "Normal Dot Threshold"},
108 entt::attribute{"min", 0.0f},
109 entt::attribute{"max", 1.0f},
110 entt::attribute{"tooltip", "Normal dot threshold for motion detection"},
111 })
112 .data<&temporal_settings::max_accum_frames>("max_accum_frames"_hs)
114 entt::attribute{"name", "max_accum_frames"},
115 entt::attribute{"pretty_name", "Max Accum Frames"},
116 entt::attribute{"min", 1},
117 entt::attribute{"max", 16},
118 entt::attribute{"tooltip", "Maximum accumulation frames"},
119 });
120
121
122 entt::meta_factory<fidelityfx_settings>{}
123 .type("ssr_pass::fidelityfx_ssr_settings"_hs)
125 entt::attribute{"name", "ssr_pass::fidelityfx_ssr_settings"},
126 entt::attribute{"pretty_name", "FidelityFX SSR Settings"},
127 })
128 .data<&fidelityfx_settings::max_steps>("max_steps"_hs)
130 entt::attribute{"name", "max_steps"},
131 entt::attribute{"pretty_name", "Max Steps"},
132 entt::attribute{"min", 8},
133 entt::attribute{"max", 200},
134 entt::attribute{"tooltip", "Maximum ray marching steps for hierarchical traversal"},
135 })
136 .data<&fidelityfx_settings::max_rays>("max_rays"_hs)
138 entt::attribute{"name", "max_rays"},
139 entt::attribute{"pretty_name", "Max Rays"},
140 entt::attribute{"min", 1},
141 entt::attribute{"max", 64},
142 entt::attribute{"tooltip", "Maximum rays for rough surfaces (future: cone tracing)"},
143 })
144 .data<&fidelityfx_settings::depth_tolerance>("depth_tolerance"_hs)
146 entt::attribute{"name", "depth_tolerance"},
147 entt::attribute{"pretty_name", "Depth Tolerance"},
148 entt::attribute{"min", 0.01f},
149 entt::attribute{"max", 2.0f},
150 entt::attribute{"tooltip", "Depth tolerance for hit validation"},
151 })
152 .data<&fidelityfx_settings::brightness>("brightness"_hs)
154 entt::attribute{"name", "brightness"},
155 entt::attribute{"pretty_name", "Brightness"},
156 entt::attribute{"min", 0.1f},
157 entt::attribute{"max", 3.0f},
158 entt::attribute{"tooltip", "Reflection brightness multiplier"},
159 })
160 .data<&fidelityfx_settings::facing_reflections_fading>("facing_reflections_fading"_hs)
162 entt::attribute{"name", "facing_reflections_fading"},
163 entt::attribute{"pretty_name", "Facing Reflections Fading"},
164 entt::attribute{"min", 0.0f},
165 entt::attribute{"max", 1.0f},
166 entt::attribute{"tooltip", "Fade factor for camera-facing reflections"},
167 })
168 .data<&fidelityfx_settings::roughness_depth_tolerance>("roughness_depth_tolerance"_hs)
170 entt::attribute{"name", "roughness_depth_tolerance"},
171 entt::attribute{"pretty_name", "Roughness Depth Tolerance"},
172 entt::attribute{"min", 0.0f},
173 entt::attribute{"max", 2.0f},
174 entt::attribute{"tooltip", "Additional depth tolerance for rough surfaces"},
175 })
176 .data<&fidelityfx_settings::fade_in_start>("fade_in_start"_hs)
178 entt::attribute{"name", "fade_in_start"},
179 entt::attribute{"pretty_name", "Fade In Start"},
180 entt::attribute{"min", 0.0f},
181 entt::attribute{"max", 1.0f},
182 entt::attribute{"tooltip", "Screen edge fade start"},
183 })
184 .data<&fidelityfx_settings::fade_in_end>("fade_in_end"_hs)
186 entt::attribute{"name", "fade_in_end"},
187 entt::attribute{"pretty_name", "Fade In End"},
188 entt::attribute{"min", 0.0f},
189 entt::attribute{"max", 1.0f},
190 entt::attribute{"tooltip", "Screen edge fade end"},
191 })
192 .data<&fidelityfx_settings::enable_half_res>("enable_half_res"_hs)
194 entt::attribute{"name", "enable_half_res"},
195 entt::attribute{"pretty_name", "Enable Half Res"},
196 entt::attribute{"tooltip", "Enable half resolution for SSR buffers"},
197 })
198 .data<&fidelityfx_settings::enable_cone_tracing>("enable_cone_tracing"_hs)
200 entt::attribute{"name", "enable_cone_tracing"},
201 entt::attribute{"pretty_name", "Enable Cone Tracing"},
202 entt::attribute{"tooltip", "Enable cone tracing for glossy reflections"},
203 })
204 .data<&fidelityfx_settings::cone_tracing>("cone_tracing"_hs)
206 entt::attribute{"name", "cone_tracing"},
207 entt::attribute{"predicate", cone_tracing_predicate_entt},
208 entt::attribute{"pretty_name", "Cone Tracing"},
209 entt::attribute{"tooltip", "Cone tracing specific settings"},
210 entt::attribute{"flattable", true},
211 })
212 .data<&fidelityfx_settings::enable_temporal_accumulation>("enable_temporal_accumulation"_hs)
214 entt::attribute{"name", "enable_temporal_accumulation"},
215 entt::attribute{"pretty_name", "Enable Temporal Accumulation"},
216 entt::attribute{"tooltip", "Enable temporal accumulation to reduce noise over multiple frames"},
217 })
218 .data<&fidelityfx_settings::temporal>("temporal"_hs)
220 entt::attribute{"name", "temporal"},
221 entt::attribute{"predicate", temporal_predicate_entt},
222 entt::attribute{"pretty_name", "Temporal Accumulation"},
223 entt::attribute{"tooltip", "Temporal accumulation settings"},
224 entt::attribute{"flattable", true},
225 });
226
227}
228
230{
231 using ssr_settings = ssr_pass::ssr_settings;
232
233
234 entt::meta_factory<ssr_settings>{}
235 .type("ssr_pass::ssr_settings"_hs)
237 entt::attribute{"name", "ssr_pass::ssr_settings"},
238 entt::attribute{"pretty_name", "SSR Settings"},
239 })
240 .data<&ssr_settings::fidelityfx>("fidelityfx"_hs)
242 entt::attribute{"name", "fidelityfx"},
243 entt::attribute{"pretty_name", "FidelityFX Settings"},
244 entt::attribute{"tooltip", "Settings for AMD FidelityFX SSSR implementation"},
245 entt::attribute{"flattable", true},
246 });
247}
248
249// Serialization for cone_tracing_settings
251{
252 try_save(ar, ser20::make_nvp("cone_angle_bias", obj.cone_angle_bias));
253 try_save(ar, ser20::make_nvp("max_mip_level", obj.max_mip_level));
254 try_save(ar, ser20::make_nvp("blur_base_sigma", obj.blur_base_sigma));
255}
258
260{
261 try_load(ar, ser20::make_nvp("cone_angle_bias", obj.cone_angle_bias));
262 try_load(ar, ser20::make_nvp("max_mip_level", obj.max_mip_level));
263 try_load(ar, ser20::make_nvp("blur_base_sigma", obj.blur_base_sigma));
264}
267
268// Serialization for temporal_settings
270{
271 try_save(ar, ser20::make_nvp("history_strength", obj.history_strength));
272 try_save(ar, ser20::make_nvp("depth_threshold", obj.depth_threshold));
273 try_save(ar, ser20::make_nvp("roughness_sensitivity", obj.roughness_sensitivity));
274 try_save(ar, ser20::make_nvp("motion_scale_pixels", obj.motion_scale_pixels));
275 try_save(ar, ser20::make_nvp("normal_dot_threshold", obj.normal_dot_threshold));
276 try_save(ar, ser20::make_nvp("max_accum_frames", obj.max_accum_frames));
277}
280
282{
283 try_load(ar, ser20::make_nvp("history_strength", obj.history_strength));
284 try_load(ar, ser20::make_nvp("depth_threshold", obj.depth_threshold));
285 try_load(ar, ser20::make_nvp("roughness_sensitivity", obj.roughness_sensitivity));
286 try_load(ar, ser20::make_nvp("motion_scale_pixels", obj.motion_scale_pixels));
287 try_load(ar, ser20::make_nvp("normal_dot_threshold", obj.normal_dot_threshold));
288 try_load(ar, ser20::make_nvp("max_accum_frames", obj.max_accum_frames));
289}
292
293// Serialization for fidelityfx_ssr_settings
295{
296 try_save(ar, ser20::make_nvp("max_steps", obj.max_steps));
297 try_save(ar, ser20::make_nvp("max_rays", obj.max_rays));
298 try_save(ar, ser20::make_nvp("depth_tolerance", obj.depth_tolerance));
299 try_save(ar, ser20::make_nvp("brightness", obj.brightness));
300 try_save(ar, ser20::make_nvp("facing_reflections_fading", obj.facing_reflections_fading));
301 try_save(ar, ser20::make_nvp("roughness_depth_tolerance", obj.roughness_depth_tolerance));
302 try_save(ar, ser20::make_nvp("fade_in_start", obj.fade_in_start));
303 try_save(ar, ser20::make_nvp("fade_in_end", obj.fade_in_end));
304 try_save(ar, ser20::make_nvp("enable_half_res", obj.enable_half_res));
305 try_save(ar, ser20::make_nvp("enable_cone_tracing", obj.enable_cone_tracing));
306 try_save(ar, ser20::make_nvp("cone_tracing", obj.cone_tracing));
307 try_save(ar, ser20::make_nvp("enable_temporal_accumulation", obj.enable_temporal_accumulation));
308 try_save(ar, ser20::make_nvp("temporal", obj.temporal));
309}
312
314{
315 try_load(ar, ser20::make_nvp("max_steps", obj.max_steps));
316 try_load(ar, ser20::make_nvp("max_rays", obj.max_rays));
317 try_load(ar, ser20::make_nvp("depth_tolerance", obj.depth_tolerance));
318 try_load(ar, ser20::make_nvp("brightness", obj.brightness));
319 try_load(ar, ser20::make_nvp("facing_reflections_fading", obj.facing_reflections_fading));
320 try_load(ar, ser20::make_nvp("roughness_depth_tolerance", obj.roughness_depth_tolerance));
321 try_load(ar, ser20::make_nvp("fade_in_start", obj.fade_in_start));
322 try_load(ar, ser20::make_nvp("fade_in_end", obj.fade_in_end));
323 try_load(ar, ser20::make_nvp("enable_half_res", obj.enable_half_res));
324 try_load(ar, ser20::make_nvp("enable_cone_tracing", obj.enable_cone_tracing));
325 try_load(ar, ser20::make_nvp("cone_tracing", obj.cone_tracing));
326 try_load(ar, ser20::make_nvp("enable_temporal_accumulation", obj.enable_temporal_accumulation));
327 try_load(ar, ser20::make_nvp("temporal", obj.temporal));
328}
331
332// Serialization for ssr_settings
334{
335 try_save(ar, ser20::make_nvp("fidelityfx", obj.fidelityfx));
336}
339
341{
342 try_load(ar, ser20::make_nvp("fidelityfx", obj.fidelityfx));
343}
346
348{
349
350 entt::meta_factory<ssr_component>{}
351 .type("ssr_component"_hs)
353 entt::attribute{"name", "ssr_component"},
354 entt::attribute{"category", "RENDERING"},
355 entt::attribute{"pretty_name", "SSR"},
356 })
357 .func<&component_meta<ssr_component>::exists>("component_exists"_hs)
358 .func<&component_meta<ssr_component>::add>("component_add"_hs)
359 .func<&component_meta<ssr_component>::remove>("component_remove"_hs)
360 .func<&component_meta<ssr_component>::save>("component_save"_hs)
361 .func<&component_meta<ssr_component>::load>("component_load"_hs)
362 .data<&ssr_component::enabled>("enabled"_hs)
363 .custom<entt::attributes>(entt::attributes{
364 entt::attribute{"name", "enabled"},
365 entt::attribute{"pretty_name", "Enabled"},
366 entt::attribute{"tooltip", "Enable/disable Screen Space Reflections"},
367 })
368 .data<&ssr_component::settings>("settings"_hs)
370 entt::attribute{"name", "settings"},
371 entt::attribute{"pretty_name", "Settings"},
372 entt::attribute{"flattable", true},
373 });
374}
375
377{
378 try_save(ar, ser20::make_nvp("enabled", obj.enabled));
379 try_save(ar, ser20::make_nvp("settings", obj.settings));
380}
383
385{
386 try_load(ar, ser20::make_nvp("enabled", obj.enabled));
387 try_load(ar, ser20::make_nvp("settings", obj.settings));
388}
391} // namespace unravel
bool enabled
Whether SSR is enabled.
attributes::value_type attribute
Definition reflection.h:19
std::map< std::string, meta_any > attributes
Definition reflection.h:18
auto property_predicate(property_predicate_t predicate) -> property_predicate_t
BinaryInputArchive iarchive_binary_t
simd::JSONOutputArchive oarchive_associative_t
BinaryOutputArchive oarchive_binary_t
simd::JSONInputArchive iarchive_associative_t
#define REFLECT(cls)
Definition reflection.h:133
#define REFLECT_INLINE(cls)
Definition reflection.h:128
#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
Combined SSR settings.
Definition ssr_pass.h:62