Unravel Engine C++ Reference
Loading...
Searching...
No Matches
light.cpp
Go to the documentation of this file.
1#include "light.hpp"
3
6
7namespace unravel
8{
10{
11
12
13 auto directional_predicate_entt = entt::property_predicate<bool>(
14 [](const entt::meta_any& obj)
15 {
16 auto data = obj.try_cast<light>();
17 if(!data)
18 {
19 return false;
20 }
21 return data->type == light_type::directional;
22 });
23 auto point_predicate_entt = entt::property_predicate<bool>(
24 [](const entt::meta_any& obj)
25 {
26 auto data = obj.try_cast<light>();
27 if(!data)
28 {
29 return false;
30 }
31 return data->type == light_type::point;
32 });
33 auto spot_predicate_entt = entt::property_predicate<bool>(
34 [](const entt::meta_any& obj)
35 {
36 auto data = obj.try_cast<light>();
37 if(!data)
38 {
39 return false;
40 }
41 return data->type == light_type::spot;
42 });
43
44 auto casts_shadows_predicate_entt = entt::property_predicate<bool>(
45 [](const entt::meta_any& obj)
46 {
47 auto data = obj.try_cast<light>();
48 if(!data)
49 {
50 return false;
51 }
52 return data->casts_shadows;
53 });
54 auto casts_shadows_and_is_directional_predicate_entt = entt::property_predicate<bool>(
55 [](const entt::meta_any& obj)
56 {
57 auto data = obj.try_cast<light>();
58 if(!data)
59 {
60 return false;
61 }
62 return data->casts_shadows && data->type == light_type::directional;
63 });
64
65 auto casts_shadows_and_is_point_predicate_entt = entt::property_predicate<bool>(
66 [](const entt::meta_any& obj)
67 {
68 auto data = obj.try_cast<light>();
69 if(!data)
70 {
71 return false;
72 }
73 return data->casts_shadows && data->type == light_type::point;
74 });
75
76 auto casts_shadows_and_is_spot_predicate_entt = entt::property_predicate<bool>(
77 [](const entt::meta_any& obj)
78 {
79 auto data = obj.try_cast<light>();
80 if(!data)
81 {
82 return false;
83 }
84 return data->casts_shadows && data->type == light_type::spot;
85 });
86
87 entt::meta_factory<light::spot_shadowmap_params>{}
88 .type("light::spot_shadowmap_params"_hs)
90 entt::attribute{"name", "light::spot_shadowmap_params"},
91 entt::attribute{"pretty_name", "Spot Shadowmap Params"},
92 });
93
94 entt::meta_factory<light::spot>{}
95 .type("light::spot"_hs)
97 entt::attribute{"name", "light::spot"},
98 entt::attribute{"pretty_name", "Spot"},
99 })
100 .data<&light::spot::set_range, &light::spot::get_range>("range"_hs)
102 entt::attribute{"name", "range"},
103 entt::attribute{"pretty_name", "Range"},
104 entt::attribute{"min", 0.1f},
105 entt::attribute{"tooltip", "Light's range from its origin."},
106 })
107 .data<&light::spot::set_inner_angle, &light::spot::get_inner_angle>("inner_angle"_hs)
109 entt::attribute{"name", "inner_angle"},
110 entt::attribute{"pretty_name", "Inner Angle"},
111 entt::attribute{"min", 1.0f},
112 entt::attribute{"max", 85.0f},
113 entt::attribute{"step", 0.1f},
114 entt::attribute{"tooltip", "Spot light inner cone angle."},
115 })
116 .data<&light::spot::set_outer_angle, &light::spot::get_outer_angle>("outer_angle"_hs)
118 entt::attribute{"name", "outer_angle"},
119 entt::attribute{"pretty_name", "Outer Angle"},
120 entt::attribute{"min", 1.0f},
121 entt::attribute{"max", 90.0f},
122 entt::attribute{"step", 0.1f},
123 entt::attribute{"tooltip", "Spot light outer cone angle."},
124 });
125
126 entt::meta_factory<light::point_shadowmap_params>{}
127 .type("light::point_shadowmap_params"_hs)
129 entt::attribute{"name", "light::point_shadowmap_params"},
130 entt::attribute{"pretty_name", "Point Shadowmap Params"},
131 })
132 .data<&light::point_shadowmap_params::fov_x_adjust>("fov_x_adjust"_hs)
134 entt::attribute{"name", "fov_x_adjust"},
135 entt::attribute{"pretty_name", "FovX Adjust"},
136 entt::attribute{"min", -20.0f},
137 entt::attribute{"max", 20.0f},
138 entt::attribute{"step", 0.0001f},
139 entt::attribute{"tooltip", "Shadowmap field of view adjust."},
140 })
141 .data<&light::point_shadowmap_params::fov_y_adjust>("fov_y_adjust"_hs)
143 entt::attribute{"name", "fov_y_adjust"},
144 entt::attribute{"pretty_name", "FovY Adjust"},
145 entt::attribute{"min", -20.0f},
146 entt::attribute{"max", 20.0f},
147 entt::attribute{"step", 0.0001f},
148 entt::attribute{"tooltip", "Shadowmap field of view adjust."},
149 })
150 .data<&light::point_shadowmap_params::stencil_pack>("stencil_pack"_hs)
152 entt::attribute{"name", "stencil_pack"},
153 entt::attribute{"pretty_name", "Stencil Pack"},
154 entt::attribute{"tooltip", "Shadowmap stencil packing algorithm."},
155 });
156
157 entt::meta_factory<light::point>{}
158 .type("point"_hs)
160 entt::attribute{"name", "point"},
161 entt::attribute{"pretty_name", "Point"},
162 })
163 .data<&light::point::range>("range"_hs)
165 entt::attribute{"name", "range"},
166 entt::attribute{"pretty_name", "Range"},
167 entt::attribute{"min", 0.1f},
168 entt::attribute{"tooltip", "Light's range from its origin."},
169 })
170 .data<&light::point::exponent_falloff>("exponent_falloff"_hs)
172 entt::attribute{"name", "exponent_falloff"},
173 entt::attribute{"pretty_name", "Exponent Falloff"},
174 entt::attribute{"min", 0.1f},
175 entt::attribute{"max", 10.0f},
176 entt::attribute{"tooltip", "The falloff factor nearing the range edge."},
177 });
178
179 entt::meta_factory<light::directional_shadowmap_params>{}
180 .type("light::directional_shadowmap_params"_hs)
182 entt::attribute{"name", "light::directional_shadowmap_params"},
183 entt::attribute{"pretty_name", "Directional Shadowmap Params"},
184 })
185 .data<&light::directional_shadowmap_params::num_splits>("splits"_hs)
187 entt::attribute{"name", "splits"},
188 entt::attribute{"pretty_name", "Splits"},
189 entt::attribute{"min", 1},
190 entt::attribute{"max", 4},
191 entt::attribute{"tooltip", "Number of cascades."},
192 })
193 .data<&light::directional_shadowmap_params::split_distribution>("distribution"_hs)
195 entt::attribute{"name", "distribution"},
196 entt::attribute{"pretty_name", "Distribution"},
197 entt::attribute{"min", 0.0f},
198 entt::attribute{"max", 1.0f},
199 entt::attribute{"step", 0.001f},
200 entt::attribute{"tooltip", "?"},
201 })
202 .data<&light::directional_shadowmap_params::stabilize>("stabilize"_hs)
204 entt::attribute{"name", "stabilize"},
205 entt::attribute{"pretty_name", "Stabilize"},
206 entt::attribute{"tooltip", "Stabilize the shadowmaps."},
207 });
208
209 entt::meta_factory<light::directional>{}
210 .type("light::directional"_hs)
212 entt::attribute{"name", "directional"},
213 entt::attribute{"pretty_name", "Directional"},
214 });
215
216 entt::meta_factory<light_type>{}
217 .type("light_type"_hs)
219 entt::attribute{"name", "light_type"},
220 entt::attribute{"pretty_name", "Light Type"},
221 })
222 .data<light_type::spot>("spot"_hs)
224 entt::attribute{"name", "spot"},
225 entt::attribute{"pretty_name", "Spot"}
226 })
227 .data<light_type::point>("point"_hs)
229 entt::attribute{"name", "point"},
230 entt::attribute{"pretty_name", "Point"}
231 })
232 .data<light_type::directional>("directional"_hs)
234 entt::attribute{"name", "directional"},
235 entt::attribute{"pretty_name", "Directional"}
236 });
237
238 entt::meta_factory<sm_depth>{}
239 .type("sm_depth"_hs)
241 entt::attribute{"name", "sm_depth"},
242 entt::attribute{"pretty_name", "Shadowmap Depth"},
243 })
244 .data<sm_depth::invz>("invz"_hs)
246 entt::attribute{"name", "invz"},
247 entt::attribute{"pretty_name", "InvZ"}
248 })
249 .data<sm_depth::linear>("linear"_hs)
251 entt::attribute{"name", "linear"},
252 entt::attribute{"pretty_name", "Linear"}
253 });
254
255 entt::meta_factory<sm_impl>{}
256 .type("sm_impl"_hs)
258 entt::attribute{"name", "sm_impl"},
259 entt::attribute{"pretty_name", "Shadowmap Implementation"},
260 })
261 .data<sm_impl::hard>("hard"_hs)
263 entt::attribute{"name", "hard"},
264 entt::attribute{"pretty_name", "Hard"}
265 })
266 .data<sm_impl::pcf>("pcf"_hs)
268 entt::attribute{"name", "pcf"},
269 entt::attribute{"pretty_name", "Pcf"}
270 })
271 .data<sm_impl::pcss>("pcss"_hs)
273 entt::attribute{"name", "pcss"},
274 entt::attribute{"pretty_name", "Pcss"}
275 })
276 .data<sm_impl::vsm>("vsm"_hs)
278 entt::attribute{"name", "vsm"},
279 entt::attribute{"pretty_name", "Vsm"}
280 })
281 .data<sm_impl::esm>("esm"_hs)
283 entt::attribute{"name", "esm"},
284 entt::attribute{"pretty_name", "Esm"}
285 });
286
287 // Predicates for sm_impl types
288 auto sm_impl_hard_predicate_entt = entt::property_predicate<bool>(
289 [](const entt::meta_any& obj)
290 {
291 auto data = obj.try_cast<light::shadowmap_params>();
292 if(!data)
293 {
294 return false;
295 }
296 return data->type == sm_impl::hard;
297 });
298 auto sm_impl_pcf_predicate_entt = entt::property_predicate<bool>(
299 [](const entt::meta_any& obj)
300 {
301 auto data = obj.try_cast<light::shadowmap_params>();
302 if(!data)
303 {
304 return false;
305 }
306 return data->type == sm_impl::pcf;
307 });
308 auto sm_impl_pcss_predicate_entt = entt::property_predicate<bool>(
309 [](const entt::meta_any& obj)
310 {
311 auto data = obj.try_cast<light::shadowmap_params>();
312 if(!data)
313 {
314 return false;
315 }
316 return data->type == sm_impl::pcss;
317 });
318 auto sm_impl_vsm_predicate_entt = entt::property_predicate<bool>(
319 [](const entt::meta_any& obj)
320 {
321 auto data = obj.try_cast<light::shadowmap_params>();
322 if(!data)
323 {
324 return false;
325 }
326 return data->type == sm_impl::vsm;
327 });
328 auto sm_impl_esm_predicate_entt = entt::property_predicate<bool>(
329 [](const entt::meta_any& obj)
330 {
331 auto data = obj.try_cast<light::shadowmap_params>();
332 if(!data)
333 {
334 return false;
335 }
336 return data->type == sm_impl::esm;
337 });
338
339 // Reflection for hard_impl_params
340 entt::meta_factory<light::shadowmap_params::hard_impl_params>{}
341 .type("light::shadowmap_params::hard_impl_params"_hs)
343 entt::attribute{"name", "hard_impl_params"},
344 entt::attribute{"pretty_name", "Hard Implementation Params"},
345 });
346
347 // Reflection for pcf_impl_params
348 entt::meta_factory<light::shadowmap_params::pcf_impl_params>{}
349 .type("light::shadowmap_params::pcf_impl_params"_hs)
351 entt::attribute{"name", "pcf_impl_params"},
352 entt::attribute{"pretty_name", "PCF Implementation Params"},
353 })
354 .data<&light::shadowmap_params::pcf_impl_params::x_offset>("x_offset"_hs)
356 entt::attribute{"name", "x_offset"},
357 entt::attribute{"pretty_name", "X Offset"},
358 entt::attribute{"min", 0.0f},
359 entt::attribute{"max", 3.0f},
360 entt::attribute{"step", 0.01f},
361 entt::attribute{"tooltip", "Offset along the x-axis for PCF sampling."},
362 })
363 .data<&light::shadowmap_params::pcf_impl_params::y_offset>("y_offset"_hs)
365 entt::attribute{"name", "y_offset"},
366 entt::attribute{"pretty_name", "Y Offset"},
367 entt::attribute{"min", 0.0f},
368 entt::attribute{"max", 3.0f},
369 entt::attribute{"step", 0.01f},
370 entt::attribute{"tooltip", "Offset along the y-axis for PCF sampling."},
371 });
372
373 // Reflection for pcss_impl_params
374 entt::meta_factory<light::shadowmap_params::pcss_impl_params>{}
375 .type("light::shadowmap_params::pcss_impl_params"_hs)
377 entt::attribute{"name", "pcss_impl_params"},
378 entt::attribute{"pretty_name", "PCSS Implementation Params"},
379 })
380 .data<&light::shadowmap_params::pcss_impl_params::penumbra_x_offset>("penumbra_x_offset"_hs)
382 entt::attribute{"name", "penumbra_x_offset"},
383 entt::attribute{"pretty_name", "Penumbra X Offset"},
384 entt::attribute{"min", 0.0f},
385 entt::attribute{"max", 10.0f},
386 entt::attribute{"step", 0.01f},
387 entt::attribute{"tooltip", "Offset along the x-axis for PCSS sampling."},
388 })
389 .data<&light::shadowmap_params::pcss_impl_params::penumbra_y_offset>("penumbra_y_offset"_hs)
391 entt::attribute{"name", "penumbra_y_offset"},
392 entt::attribute{"pretty_name", "Penumbra Y Offset"},
393 entt::attribute{"min", 0.0f},
394 entt::attribute{"max", 10.0f},
395 entt::attribute{"step", 0.01f},
396 entt::attribute{"tooltip", "Offset along the y-axis for PCSS sampling."},
397 });
398
399 // Reflection for vsm_impl_params
400 entt::meta_factory<light::shadowmap_params::vsm_impl_params>{}
401 .type("light::shadowmap_params::vsm_impl_params"_hs)
403 entt::attribute{"name", "vsm_impl_params"},
404 entt::attribute{"pretty_name", "VSM Implementation Params"},
405 })
406 .data<&light::shadowmap_params::vsm_impl_params::min_variance>("min_variance"_hs)
408 entt::attribute{"name", "min_variance"},
409 entt::attribute{"pretty_name", "Min Variance"},
410 entt::attribute{"min", 0.0f},
411 entt::attribute{"max", 0.1f},
412 entt::attribute{"step", 0.00001f},
413 entt::attribute{"tooltip", "Minimum variance for VSM filtering."},
414 })
415 .data<&light::shadowmap_params::vsm_impl_params::depth_multiplier>("depth_multiplier"_hs)
417 entt::attribute{"name", "depth_multiplier"},
418 entt::attribute{"pretty_name", "Depth Multiplier"},
419 entt::attribute{"min", 1.0f},
420 entt::attribute{"max", 1000.0f},
421 entt::attribute{"step", 1.0f},
422 entt::attribute{"tooltip", "Depth multiplier for VSM."},
423 })
424 .data<&light::shadowmap_params::vsm_impl_params::do_blur>("do_blur"_hs)
426 entt::attribute{"name", "do_blur"},
427 entt::attribute{"pretty_name", "Blur Shadow Map"},
428 entt::attribute{"tooltip", "Whether to blur the shadow map."},
429 })
430 .data<&light::shadowmap_params::vsm_impl_params::blur_x_offset>("blur_x_offset"_hs)
432 entt::attribute{"name", "blur_x_offset"},
433 entt::attribute{"pretty_name", "Blur X Offset"},
434 entt::attribute{"min", 0.0f},
435 entt::attribute{"max", 3.0f},
436 entt::attribute{"step", 0.01f},
437 entt::attribute{"tooltip", "Blur offset along the x-axis."},
438 })
439 .data<&light::shadowmap_params::vsm_impl_params::blur_y_offset>("blur_y_offset"_hs)
441 entt::attribute{"name", "blur_y_offset"},
442 entt::attribute{"pretty_name", "Blur Y Offset"},
443 entt::attribute{"min", 0.0f},
444 entt::attribute{"max", 3.0f},
445 entt::attribute{"step", 0.01f},
446 entt::attribute{"tooltip", "Blur offset along the y-axis."},
447 });
448
449 // Reflection for esm_impl_params
450 entt::meta_factory<light::shadowmap_params::esm_impl_params>{}
451 .type("light::shadowmap_params::esm_impl_params"_hs)
453 entt::attribute{"name", "esm_impl_params"},
454 entt::attribute{"pretty_name", "ESM Implementation Params"},
455 })
456 .data<&light::shadowmap_params::esm_impl_params::hardness>("hardness"_hs)
458 entt::attribute{"name", "hardness"},
459 entt::attribute{"pretty_name", "ESM Hardness"},
460 entt::attribute{"min", 0.0f},
461 entt::attribute{"max", 1.0f},
462 entt::attribute{"step", 0.01f},
463 entt::attribute{"tooltip", "ESM hardness parameter."},
464 })
465 .data<&light::shadowmap_params::esm_impl_params::depth_multiplier>("depth_multiplier"_hs)
467 entt::attribute{"name", "depth_multiplier"},
468 entt::attribute{"pretty_name", "Depth Multiplier"},
469 entt::attribute{"min", 1.0f},
470 entt::attribute{"max", 15000.0f},
471 entt::attribute{"step", 1.0f},
472 entt::attribute{"tooltip", "Depth multiplier for ESM."},
473 })
474 .data<&light::shadowmap_params::esm_impl_params::do_blur>("do_blur"_hs)
476 entt::attribute{"name", "do_blur"},
477 entt::attribute{"pretty_name", "Blur Shadow Map"},
478 entt::attribute{"tooltip", "Whether to blur the shadow map."},
479 })
480 .data<&light::shadowmap_params::esm_impl_params::blur_x_offset>("blur_x_offset"_hs)
482 entt::attribute{"name", "blur_x_offset"},
483 entt::attribute{"pretty_name", "Blur X Offset"},
484 entt::attribute{"min", 0.0f},
485 entt::attribute{"max", 3.0f},
486 entt::attribute{"step", 0.01f},
487 entt::attribute{"tooltip", "Blur offset along the x-axis."},
488 })
489 .data<&light::shadowmap_params::esm_impl_params::blur_y_offset>("blur_y_offset"_hs)
491 entt::attribute{"name", "blur_y_offset"},
492 entt::attribute{"pretty_name", "Blur Y Offset"},
493 entt::attribute{"min", 0.0f},
494 entt::attribute{"max", 3.0f},
495 entt::attribute{"step", 0.01f},
496 entt::attribute{"tooltip", "Blur offset along the y-axis."},
497 });
498
499 entt::meta_factory<sm_resolution>{}
500 .type("sm_resolution"_hs)
502 entt::attribute{"name", "sm_resolution"},
503 entt::attribute{"pretty_name", "Shadowmap Resolution"},
504 })
505 .data<sm_resolution::low>("low"_hs)
507 entt::attribute{"name", "low"},
508 entt::attribute{"pretty_name", "Low"}
509 })
510 .data<sm_resolution::medium>("medium"_hs)
512 entt::attribute{"name", "medium"},
513 entt::attribute{"pretty_name", "Medium"}
514 })
515 .data<sm_resolution::high>("high"_hs)
517 entt::attribute{"name", "high"},
518 entt::attribute{"pretty_name", "High"}
519 })
520 .data<sm_resolution::very_high>("very_high"_hs)
522 entt::attribute{"name", "very_high"},
523 entt::attribute{"pretty_name", "Very High"}
524 });
525
526 entt::meta_factory<light::shadowmap_params>{}
527 .type("light::shadowmap_params"_hs)
529 entt::attribute{"name", "shadowmap_params"},
530 entt::attribute{"pretty_name", "Shadowmap Params"},
531 })
532 .data<&light::shadowmap_params::type>("type"_hs)
534 entt::attribute{"name", "type"},
535 entt::attribute{"pretty_name", "Type"},
536 entt::attribute{"tooltip", "Shadowmap implementation type."},
537 })
538 .data<&light::shadowmap_params::depth>("depth"_hs)
540 entt::attribute{"name", "depth"},
541 entt::attribute{"pretty_name", "Depth"},
542 entt::attribute{"tooltip", "Shadowmap depth pack algorithm."},
543 })
544 .data<&light::shadowmap_params::resolution>("resolution"_hs)
546 entt::attribute{"name", "resolution"},
547 entt::attribute{"pretty_name", "Resolution"},
548 entt::attribute{"tooltip", "Shadowmap resolution."},
549 })
550 .data<&light::shadowmap_params::bias>("bias"_hs)
552 entt::attribute{"name", "bias"},
553 entt::attribute{"pretty_name", "Bias"},
554 entt::attribute{"min", 0.0f},
555 entt::attribute{"max", 0.01f},
556 entt::attribute{"step", 0.00001f},
557 entt::attribute{"tooltip", "Shadowmap bias offset."},
558 })
559 .data<&light::shadowmap_params::normal_bias>("normal_bias"_hs)
561 entt::attribute{"name", "normal_bias"},
562 entt::attribute{"pretty_name", "Normal Bias"},
563 entt::attribute{"min", 0.0f},
564 entt::attribute{"max", 0.5f},
565 entt::attribute{"step", 0.00001f},
566 entt::attribute{"tooltip", "Shadowmap normal bias offset"},
567 })
568 .data<&light::shadowmap_params::near_plane>("near_plane"_hs)
570 entt::attribute{"name", "near_plane"},
571 entt::attribute{"pretty_name", "Near Plane"},
572 entt::attribute{"min", 0.01f},
573 entt::attribute{"max", 10.0f},
574 entt::attribute{"tooltip", "Shadowmap near plane"},
575 })
576 .data<&light::shadowmap_params::far_plane>("far_plane"_hs)
578 entt::attribute{"name", "far_plane"},
579 entt::attribute{"pretty_name", "Far Plane"},
580 entt::attribute{"min", 0.01f},
581 entt::attribute{"max", 10000.0f},
582 entt::attribute{"tooltip", "Shadowmap far plane"},
583 })
584 .data<&light::shadowmap_params::show_coverage>("show_coverage"_hs)
586 entt::attribute{"name", "show_coverage"},
587 entt::attribute{"pretty_name", "Show Coverage"},
588 entt::attribute{"tooltip", "Show shadowmap coverage in view."},
589 })
590 .data<&light::shadowmap_params::hard>("hard"_hs)
592 entt::attribute{"name", "hard"},
593 entt::attribute{"pretty_name", "Hard"},
594 // entt::attribute{"flattable", true},
595 entt::attribute{"predicate", sm_impl_hard_predicate_entt},
596 })
597 .data<&light::shadowmap_params::pcf>("pcf"_hs)
599 entt::attribute{"name", "pcf"},
600 entt::attribute{"pretty_name", "PCF"},
601 // entt::attribute{"flattable", true},
602 entt::attribute{"predicate", sm_impl_pcf_predicate_entt},
603 })
604 .data<&light::shadowmap_params::pcss>("pcss"_hs)
606 entt::attribute{"name", "pcss"},
607 entt::attribute{"pretty_name", "PCSS"},
608 // entt::attribute{"flattable", true},
609 entt::attribute{"predicate", sm_impl_pcss_predicate_entt},
610 })
611 .data<&light::shadowmap_params::vsm>("vsm"_hs)
613 entt::attribute{"name", "vsm"},
614 entt::attribute{"pretty_name", "VSM"},
615 // entt::attribute{"flattable", true},
616 entt::attribute{"predicate", sm_impl_vsm_predicate_entt},
617 })
618 .data<&light::shadowmap_params::esm>("esm"_hs)
620 entt::attribute{"name", "esm"},
621 entt::attribute{"pretty_name", "ESM"},
622 // entt::attribute{"flattable", true},
623 entt::attribute{"predicate", sm_impl_esm_predicate_entt},
624 });
625
626
627 auto contact_shadow_enabled_predicate_entt = entt::property_predicate<bool>(
628 [](const entt::meta_any& obj)
629 {
630 auto data = obj.try_cast<light::contact_shadow_params>();
631 if(!data)
632 {
633 return false;
634 }
635 return data->enabled;
636 });
637
638 entt::meta_factory<light::contact_shadow_params>{}
639 .type("light::contact_shadow_params"_hs)
641 entt::attribute{"name", "contact_shadow_params"},
642 entt::attribute{"pretty_name", "Contact Shadow Params"},
643 })
644 .data<&light::contact_shadow_params::enabled>("enabled"_hs)
646 entt::attribute{"name", "enabled"},
647 entt::attribute{"pretty_name", "Enabled"},
648 entt::attribute{"tooltip", "Enable screen-space contact shadows for fine detail at object contact points."},
649 })
650 .data<&light::contact_shadow_params::ray_length>("ray_length"_hs)
652 entt::attribute{"name", "ray_length"},
653 entt::attribute{"pretty_name", "Ray Length"},
654 entt::attribute{"min", 0.01f},
655 entt::attribute{"max", 2.0f},
656 entt::attribute{"step", 0.01f},
657 entt::attribute{"tooltip", "Maximum ray distance in view-space units. Shorter = tighter contact detail, longer = catches more occluders."},
658 entt::attribute{"predicate", contact_shadow_enabled_predicate_entt},
659 })
660 .data<&light::contact_shadow_params::thickness>("thickness"_hs)
662 entt::attribute{"name", "thickness"},
663 entt::attribute{"pretty_name", "Hit Thickness"},
664 entt::attribute{"min", 0.0f},
665 entt::attribute{"max", 2.0f},
666 entt::attribute{"step", 0.005f},
667 entt::attribute{"tooltip", "View-space depth tolerance for a ray hit. Zero = automatic (15% of ray length)."},
668 entt::attribute{"predicate", contact_shadow_enabled_predicate_entt},
669 })
670 .data<&light::contact_shadow_params::n_dot_l_fade_start>("n_dot_l_fade_start"_hs)
672 entt::attribute{"name", "n_dot_l_fade_start"},
673 entt::attribute{"pretty_name", "N·L Fade Start"},
674 entt::attribute{"min", 0.0f},
675 entt::attribute{"max", 1.0f},
676 entt::attribute{"step", 0.01f},
677 entt::attribute{"tooltip", "Contact shadow ramps in from this N·L (smoothstep low edge)."},
678 entt::attribute{"predicate", contact_shadow_enabled_predicate_entt},
679 })
680 .data<&light::contact_shadow_params::n_dot_l_fade_end>("n_dot_l_fade_end"_hs)
682 entt::attribute{"name", "n_dot_l_fade_end"},
683 entt::attribute{"pretty_name", "N·L Fade End"},
684 entt::attribute{"min", 0.0f},
685 entt::attribute{"max", 1.0f},
686 entt::attribute{"step", 0.01f},
687 entt::attribute{"tooltip", "Full contact shadow strength at or above this N·L (smoothstep high edge)."},
688 entt::attribute{"predicate", contact_shadow_enabled_predicate_entt},
689 })
690 .data<&light::contact_shadow_params::normal_facing_reject>("normal_facing_reject"_hs)
692 entt::attribute{"name", "normal_facing_reject"},
693 entt::attribute{"pretty_name", "Normal Facing Reject"},
694 entt::attribute{"min", -1.0f},
695 entt::attribute{"max", 1.0f},
696 entt::attribute{"step", 0.05f},
697 entt::attribute{"tooltip", "Reject hits when reconstructed occluder normal faces the light above this cosine. -1 disables."},
698 entt::attribute{"predicate", contact_shadow_enabled_predicate_entt},
699 });
700
701 entt::meta_factory<light>{}
702 .type("light"_hs)
704 entt::attribute{"name", "light"},
705 entt::attribute{"pretty_name", "Light"},
706 })
707 .data<&light::color>("color"_hs)
709 entt::attribute{"name", "color"},
710 entt::attribute{"pretty_name", "Color"}
711 })
712 .data<&light::intensity>("intensity"_hs)
714 entt::attribute{"name", "intensity"},
715 entt::attribute{"pretty_name", "Intensity"},
716 entt::attribute{"min", 0.0f},
717 entt::attribute{"step", 0.05f},
718 })
719 .data<&light::type>("type"_hs)
721 entt::attribute{"name", "type"},
722 entt::attribute{"pretty_name", "Type"}
723 })
724 .data<&light::directional_data>("directional_data"_hs)
726 entt::attribute{"name", "directional_data"},
727 entt::attribute{"pretty_name", "Directional"},
728 entt::attribute{"flattable", true},
729 entt::attribute{"predicate", directional_predicate_entt}
730 })
731 .data<&light::point_data>("point_data"_hs)
733 entt::attribute{"name", "point_data"},
734 entt::attribute{"pretty_name", "Point"},
735 entt::attribute{"flattable", true},
736 entt::attribute{"predicate", point_predicate_entt}
737 })
738 .data<&light::spot_data>("spot_data"_hs)
740 entt::attribute{"name", "spot_data"},
741 entt::attribute{"pretty_name", "Spot"},
742 entt::attribute{"flattable", true},
743 entt::attribute{"predicate", spot_predicate_entt}
744 })
745 .data<&light::casts_shadows>("casts_shadows"_hs)
747 entt::attribute{"name", "casts_shadows"},
748 entt::attribute{"pretty_name", "Casts Shadows"}
749 })
750 .data<&light::shadow_params>("shadow_params"_hs)
752 entt::attribute{"name", "shadow_params"},
753 entt::attribute{"pretty_name", "Common Shadow Params"},
754 entt::attribute{"tooltip", "Shadow map parameters."},
755 entt::attribute{"predicate", casts_shadows_predicate_entt}
756 })
757 .data<&light::directional_shadow_params>("directional_shadow_params"_hs)
759 entt::attribute{"name", "directional_shadow_params"},
760 entt::attribute{"pretty_name", "Directional Shadow Params"},
761 entt::attribute{"tooltip", "Directional light shadow map parameters."},
762 entt::attribute{"predicate", casts_shadows_and_is_directional_predicate_entt}
763
764 })
765 .data<&light::point_shadow_params>("point_shadow_params"_hs)
767 entt::attribute{"name", "point_shadow_params"},
768 entt::attribute{"pretty_name", "Point Shadow Params"},
769 entt::attribute{"tooltip", "Point light shadow map parameters."},
770 entt::attribute{"predicate", casts_shadows_and_is_point_predicate_entt}
771
772 })
773 .data<&light::spot_shadow_params>("spot_shadow_params"_hs)
775 entt::attribute{"name", "spot_shadow_params"},
776 entt::attribute{"pretty_name", "Spot Shadow Params"},
777 entt::attribute{"tooltip", "Spot light shadow map parameters."},
778 entt::attribute{"predicate", casts_shadows_and_is_spot_predicate_entt}
779
780 })
781 .data<&light::contact_shadow>("contact_shadow"_hs)
783 entt::attribute{"name", "contact_shadow"},
784 entt::attribute{"pretty_name", "Contact Shadow"},
785 entt::attribute{"tooltip", "Screen-space contact shadows for fine shadow detail at object contact points."},
786 });
787}
788
794
796{
797 try_save(ar, ser20::make_nvp("range", obj.range));
798 try_save(ar, ser20::make_nvp("inner_angle", obj.inner_angle));
799 try_save(ar, ser20::make_nvp("outer_angle", obj.outer_angle));
800}
803
805{
806 try_save(ar, ser20::make_nvp("fov_x_adjust", obj.fov_x_adjust));
807 try_save(ar, ser20::make_nvp("fov_y_adjust", obj.fov_y_adjust));
808 try_save(ar, ser20::make_nvp("stencil_pack", obj.stencil_pack));
809}
812
814{
815 try_save(ar, ser20::make_nvp("range", obj.range));
816 try_save(ar, ser20::make_nvp("exponent_falloff", obj.exponent_falloff));
817}
820
822{
823 try_save(ar, ser20::make_nvp("num_splits", obj.num_splits));
824 try_save(ar, ser20::make_nvp("split_distribution", obj.split_distribution));
825 try_save(ar, ser20::make_nvp("stabilize", obj.stabilize));
826}
829
835
837{
838 try_save(ar, ser20::make_nvp("type", obj.type));
839 try_save(ar, ser20::make_nvp("depth", obj.depth));
840 try_save(ar, ser20::make_nvp("resolution", obj.resolution));
841 try_save(ar, ser20::make_nvp("bias", obj.bias));
842 try_save(ar, ser20::make_nvp("normal_bias", obj.normal_bias));
843 try_save(ar, ser20::make_nvp("near_plane", obj.near_plane));
844 try_save(ar, ser20::make_nvp("far_plane", obj.far_plane));
845 try_save(ar, ser20::make_nvp("show_coverage", obj.show_coverage));
846
847 // Serialize union members based on type
848 switch(obj.type)
849 {
850 case sm_impl::hard:
851 // Hard shadows don't have parameters
852 break;
853 case sm_impl::pcf:
854 try_save(ar, ser20::make_nvp("pcf_x_offset", obj.pcf.x_offset));
855 try_save(ar, ser20::make_nvp("pcf_y_offset", obj.pcf.y_offset));
856 break;
857 case sm_impl::pcss:
858 try_save(ar, ser20::make_nvp("pcss_penumbra_x_offset", obj.pcss.penumbra_x_offset));
859 try_save(ar, ser20::make_nvp("pcss_penumbra_y_offset", obj.pcss.penumbra_y_offset));
860 break;
861 case sm_impl::vsm:
862 try_save(ar, ser20::make_nvp("vsm_min_variance", obj.vsm.min_variance));
863 try_save(ar, ser20::make_nvp("vsm_depth_multiplier", obj.vsm.depth_multiplier));
864 try_save(ar, ser20::make_nvp("vsm_do_blur", obj.vsm.do_blur));
865 if(obj.vsm.do_blur)
866 {
867 try_save(ar, ser20::make_nvp("vsm_blur_x_offset", obj.vsm.blur_x_offset));
868 try_save(ar, ser20::make_nvp("vsm_blur_y_offset", obj.vsm.blur_y_offset));
869 }
870 break;
871 case sm_impl::esm:
872 try_save(ar, ser20::make_nvp("esm_hardness", obj.esm.hardness));
873 try_save(ar, ser20::make_nvp("esm_depth_multiplier", obj.esm.depth_multiplier));
874 try_save(ar, ser20::make_nvp("esm_do_blur", obj.esm.do_blur));
875 if(obj.esm.do_blur)
876 {
877 try_save(ar, ser20::make_nvp("esm_blur_x_offset", obj.esm.blur_x_offset));
878 try_save(ar, ser20::make_nvp("esm_blur_y_offset", obj.esm.blur_y_offset));
879 }
880 break;
881 default:
882 break;
883 }
884}
887
889{
890 try_save(ar, ser20::make_nvp("enabled", obj.enabled));
891 try_save(ar, ser20::make_nvp("ray_length", obj.ray_length));
892 try_save(ar, ser20::make_nvp("thickness", obj.thickness));
893 try_save(ar, ser20::make_nvp("n_dot_l_fade_start", obj.n_dot_l_fade_start));
894 try_save(ar, ser20::make_nvp("n_dot_l_fade_end", obj.n_dot_l_fade_end));
895 try_save(ar, ser20::make_nvp("normal_facing_reject", obj.normal_facing_reject));
896}
899
901{
902 try_save(ar, ser20::make_nvp("type", obj.type));
903 try_save(ar, ser20::make_nvp("intensity", obj.intensity));
904 try_save(ar, ser20::make_nvp("color", obj.color));
905 try_save(ar, ser20::make_nvp("casts_shadows", obj.casts_shadows));
906
907 try_save(ar, ser20::make_nvp("shadow_params", obj.shadow_params));
908 try_save(ar, ser20::make_nvp("contact_shadow", obj.contact_shadow));
909
910 if(obj.type == light_type::spot)
911 {
912 try_save(ar, ser20::make_nvp("spot_data", obj.spot_data));
913 try_save(ar, ser20::make_nvp("spot_shadow_params", obj.spot_shadow_params));
914 }
915 else if(obj.type == light_type::point)
916 {
917 try_save(ar, ser20::make_nvp("point_data", obj.point_data));
918 try_save(ar, ser20::make_nvp("point_shadow_params", obj.point_shadow_params));
919 }
920 else if(obj.type == light_type::directional)
921 {
922 try_save(ar, ser20::make_nvp("directional_data", obj.directional_data));
923 try_save(ar, ser20::make_nvp("directional_shadow_params", obj.directional_shadow_params));
924 }
925}
928
934
936{
937 try_load(ar, ser20::make_nvp("range", obj.range));
938 try_load(ar, ser20::make_nvp("inner_angle", obj.inner_angle));
939 try_load(ar, ser20::make_nvp("outer_angle", obj.outer_angle));
940}
943
945{
946 try_load(ar, ser20::make_nvp("fov_x_adjust", obj.fov_x_adjust));
947 try_load(ar, ser20::make_nvp("fov_y_adjust", obj.fov_y_adjust));
948 try_load(ar, ser20::make_nvp("stencil_pack", obj.stencil_pack));
949}
952
954{
955 try_load(ar, ser20::make_nvp("range", obj.range));
956 try_load(ar, ser20::make_nvp("exponent_falloff", obj.exponent_falloff));
957}
960
962{
963 try_load(ar, ser20::make_nvp("num_splits", obj.num_splits));
964 try_load(ar, ser20::make_nvp("split_distribution", obj.split_distribution));
965 try_load(ar, ser20::make_nvp("stabilize", obj.stabilize));
966}
969
975
977{
978 try_load(ar, ser20::make_nvp("type", obj.type));
979 try_load(ar, ser20::make_nvp("depth", obj.depth));
980 try_load(ar, ser20::make_nvp("resolution", obj.resolution));
981 try_load(ar, ser20::make_nvp("bias", obj.bias));
982 try_load(ar, ser20::make_nvp("normal_bias", obj.normal_bias));
983 try_load(ar, ser20::make_nvp("near_plane", obj.near_plane));
984 try_load(ar, ser20::make_nvp("far_plane", obj.far_plane));
985 try_load(ar, ser20::make_nvp("show_coverage", obj.show_coverage));
986
987 // Initialize union based on type
988 switch(obj.type)
989 {
990 case sm_impl::hard:
991 // Hard shadows don't have parameters
992 break;
993 case sm_impl::pcf:
994 try_load(ar, ser20::make_nvp("pcf_x_offset", obj.pcf.x_offset));
995 try_load(ar, ser20::make_nvp("pcf_y_offset", obj.pcf.y_offset));
996 break;
997 case sm_impl::pcss:
998 try_load(ar, ser20::make_nvp("pcss_penumbra_x_offset", obj.pcss.penumbra_x_offset));
999 try_load(ar, ser20::make_nvp("pcss_penumbra_y_offset", obj.pcss.penumbra_y_offset));
1000 break;
1001 case sm_impl::vsm:
1002 try_load(ar, ser20::make_nvp("vsm_min_variance", obj.vsm.min_variance));
1003 try_load(ar, ser20::make_nvp("vsm_depth_multiplier", obj.vsm.depth_multiplier));
1004 try_load(ar, ser20::make_nvp("vsm_do_blur", obj.vsm.do_blur));
1005 if(obj.vsm.do_blur)
1006 {
1007 try_load(ar, ser20::make_nvp("vsm_blur_x_offset", obj.vsm.blur_x_offset));
1008 try_load(ar, ser20::make_nvp("vsm_blur_y_offset", obj.vsm.blur_y_offset));
1009 }
1010 break;
1011 case sm_impl::esm:
1012 try_load(ar, ser20::make_nvp("esm_hardness", obj.esm.hardness));
1013 try_load(ar, ser20::make_nvp("esm_depth_multiplier", obj.esm.depth_multiplier));
1014 try_load(ar, ser20::make_nvp("esm_do_blur", obj.esm.do_blur));
1015 if(obj.esm.do_blur)
1016 {
1017 try_load(ar, ser20::make_nvp("esm_blur_x_offset", obj.esm.blur_x_offset));
1018 try_load(ar, ser20::make_nvp("esm_blur_y_offset", obj.esm.blur_y_offset));
1019 }
1020 break;
1021 default:
1022 // Default to PCF if type is unknown
1023 break;
1024 }
1025}
1028
1030{
1031 try_load(ar, ser20::make_nvp("enabled", obj.enabled));
1032 try_load(ar, ser20::make_nvp("ray_length", obj.ray_length));
1033 try_load(ar, ser20::make_nvp("thickness", obj.thickness));
1034 try_load(ar, ser20::make_nvp("n_dot_l_fade_start", obj.n_dot_l_fade_start));
1035 try_load(ar, ser20::make_nvp("n_dot_l_fade_end", obj.n_dot_l_fade_end));
1036 try_load(ar, ser20::make_nvp("normal_facing_reject", obj.normal_facing_reject));
1037}
1040
1042{
1043 try_load(ar, ser20::make_nvp("type", obj.type));
1044 try_load(ar, ser20::make_nvp("intensity", obj.intensity));
1045 try_load(ar, ser20::make_nvp("color", obj.color));
1046 try_load(ar, ser20::make_nvp("casts_shadows", obj.casts_shadows));
1047 try_load(ar, ser20::make_nvp("shadow_params", obj.shadow_params));
1048 try_load(ar, ser20::make_nvp("contact_shadow", obj.contact_shadow));
1049
1050 if(obj.type == light_type::spot)
1051 {
1052 try_load(ar, ser20::make_nvp("spot_data", obj.spot_data));
1053 try_load(ar, ser20::make_nvp("spot_shadow_params", obj.spot_shadow_params));
1054 }
1055 else if(obj.type == light_type::point)
1056 {
1057 try_load(ar, ser20::make_nvp("point_data", obj.point_data));
1058 try_load(ar, ser20::make_nvp("point_shadow_params", obj.point_shadow_params));
1059 }
1060 else if(obj.type == light_type::directional)
1061 {
1062 try_load(ar, ser20::make_nvp("directional_data", obj.directional_data));
1063 try_load(ar, ser20::make_nvp("directional_shadow_params", obj.directional_shadow_params));
1064 }
1065}
1068} // namespace unravel
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 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)
auto try_load(Archive &ar, ser20::NameValuePair< T > &&t, const hpp::source_location &loc=hpp::source_location::current()) -> bool
Struct representing contact shadow parameters. Screen-space ray-marched shadows that add fine detail ...
Definition light.h:345
bool enabled
Whether contact shadows are enabled for this light.
Definition light.h:347
Struct representing directional light specific properties.
Definition light.h:185
Struct representing point light specific properties.
Definition light.h:160
Struct representing common shadow map parameters.
Definition light.h:218
sm_impl type
Implementation type for shadow mapping.
Definition light.h:222
Struct representing spot light specific properties.
Definition light.h:95
Struct representing a light.
Definition light.h:87
bool casts_shadows
Whether the light casts shadows.
Definition light.h:212
light_type type
The type of the light.
Definition light.h:89