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(
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(
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(
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(
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(
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(
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(
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 entt::meta_factory<sm_resolution>{}
288 .type("sm_resolution"_hs)
290 entt::attribute{"name", "sm_resolution"},
291 entt::attribute{"pretty_name", "Shadowmap Resolution"},
292 })
293 .data<sm_resolution::low>("low"_hs)
295 entt::attribute{"name", "low"},
296 entt::attribute{"pretty_name", "Low"}
297 })
298 .data<sm_resolution::medium>("medium"_hs)
300 entt::attribute{"name", "medium"},
301 entt::attribute{"pretty_name", "Medium"}
302 })
303 .data<sm_resolution::high>("high"_hs)
305 entt::attribute{"name", "high"},
306 entt::attribute{"pretty_name", "High"}
307 })
308 .data<sm_resolution::very_high>("very_high"_hs)
310 entt::attribute{"name", "very_high"},
311 entt::attribute{"pretty_name", "Very High"}
312 });
313
314 entt::meta_factory<light::shadowmap_params>{}
315 .type("light::shadowmap_params"_hs)
317 entt::attribute{"name", "shadowmap_params"},
318 entt::attribute{"pretty_name", "Shadowmap Params"},
319 })
320 .data<&light::shadowmap_params::type>("type"_hs)
322 entt::attribute{"name", "type"},
323 entt::attribute{"pretty_name", "Type"},
324 entt::attribute{"tooltip", "Shadowmap implementation type."},
325 })
326 .data<&light::shadowmap_params::depth>("depth"_hs)
328 entt::attribute{"name", "depth"},
329 entt::attribute{"pretty_name", "Depth"},
330 entt::attribute{"tooltip", "Shadowmap depth pack algorithm."},
331 })
332 .data<&light::shadowmap_params::resolution>("resolution"_hs)
334 entt::attribute{"name", "resolution"},
335 entt::attribute{"pretty_name", "Resolution"},
336 entt::attribute{"tooltip", "Shadowmap resolution."},
337 })
338 .data<&light::shadowmap_params::bias>("bias"_hs)
340 entt::attribute{"name", "bias"},
341 entt::attribute{"pretty_name", "Bias"},
342 entt::attribute{"min", 0.0f},
343 entt::attribute{"max", 0.01f},
344 entt::attribute{"step", 0.00001f},
345 entt::attribute{"tooltip", "Shadowmap bias offset."},
346 })
347 .data<&light::shadowmap_params::normal_bias>("normal_bias"_hs)
349 entt::attribute{"name", "normal_bias"},
350 entt::attribute{"pretty_name", "Normal Bias"},
351 entt::attribute{"min", 0.0f},
352 entt::attribute{"max", 0.25f},
353 entt::attribute{"step", 0.00001f},
354 entt::attribute{"tooltip", "Shadowmap normal bias offset"},
355 })
356 .data<&light::shadowmap_params::near_plane>("near_plane"_hs)
358 entt::attribute{"name", "near_plane"},
359 entt::attribute{"pretty_name", "Near Plane"},
360 entt::attribute{"min", 0.01f},
361 entt::attribute{"max", 10.0f},
362 entt::attribute{"tooltip", "Shadowmap near plane"},
363 })
364 .data<&light::shadowmap_params::far_plane>("far_plane"_hs)
366 entt::attribute{"name", "far_plane"},
367 entt::attribute{"pretty_name", "Far Plane"},
368 entt::attribute{"min", 0.01f},
369 entt::attribute{"max", 10000.0f},
370 entt::attribute{"tooltip", "Shadowmap far plane"},
371 })
372 .data<&light::shadowmap_params::show_coverage>("show_coverage"_hs)
374 entt::attribute{"name", "show_coverage"},
375 entt::attribute{"pretty_name", "Show Coverage"},
376 entt::attribute{"tooltip", "Show shadowmap coverage in view."},
377 });
378
379
380 entt::meta_factory<light>{}
381 .type("light"_hs)
383 entt::attribute{"name", "light"},
384 entt::attribute{"pretty_name", "Light"},
385 })
386 .data<&light::color>("color"_hs)
388 entt::attribute{"name", "color"},
389 entt::attribute{"pretty_name", "Color"}
390 })
391 .data<&light::intensity>("intensity"_hs)
393 entt::attribute{"name", "intensity"},
394 entt::attribute{"pretty_name", "Intensity"}
395 })
396 .data<&light::ambient_intensity>("ambient_intensity"_hs)
398 entt::attribute{"name", "ambient_intensity"},
399 entt::attribute{"pretty_name", "Ambient Intensity"},
400 entt::attribute{"min", 0.0f},
401 entt::attribute{"max", 0.5f},
402 entt::attribute{"step", 0.01f},
403 })
404 .data<&light::type>("type"_hs)
406 entt::attribute{"name", "type"},
407 entt::attribute{"pretty_name", "Type"}
408 })
409 .data<&light::directional_data>("directional_data"_hs)
411 entt::attribute{"name", "directional_data"},
412 entt::attribute{"pretty_name", "Directional"},
413 entt::attribute{"flattable", true},
414 entt::attribute{"predicate", directional_predicate_entt}
415 })
416 .data<&light::point_data>("point_data"_hs)
418 entt::attribute{"name", "point_data"},
419 entt::attribute{"pretty_name", "Point"},
420 entt::attribute{"flattable", true},
421 entt::attribute{"predicate", point_predicate_entt}
422 })
423 .data<&light::spot_data>("spot_data"_hs)
425 entt::attribute{"name", "spot_data"},
426 entt::attribute{"pretty_name", "Spot"},
427 entt::attribute{"flattable", true},
428 entt::attribute{"predicate", spot_predicate_entt}
429 })
430 .data<&light::casts_shadows>("casts_shadows"_hs)
432 entt::attribute{"name", "casts_shadows"},
433 entt::attribute{"pretty_name", "Casts Shadows"}
434 })
435 .data<&light::shadow_params>("shadow_params"_hs)
437 entt::attribute{"name", "shadow_params"},
438 entt::attribute{"pretty_name", "Common Shadow Params"},
439 entt::attribute{"tooltip", "Shadow map parameters."},
440 entt::attribute{"predicate", casts_shadows_predicate_entt}
441 })
442 .data<&light::directional_shadow_params>("directional_shadow_params"_hs)
444 entt::attribute{"name", "directional_shadow_params"},
445 entt::attribute{"pretty_name", "Directional Shadow Params"},
446 entt::attribute{"tooltip", "Directional light shadow map parameters."},
447 entt::attribute{"predicate", casts_shadows_and_is_directional_predicate_entt}
448
449 })
450 .data<&light::point_shadow_params>("point_shadow_params"_hs)
452 entt::attribute{"name", "point_shadow_params"},
453 entt::attribute{"pretty_name", "Point Shadow Params"},
454 entt::attribute{"tooltip", "Point light shadow map parameters."},
455 entt::attribute{"predicate", casts_shadows_and_is_point_predicate_entt}
456
457 })
458 .data<&light::spot_shadow_params>("spot_shadow_params"_hs)
460 entt::attribute{"name", "spot_shadow_params"},
461 entt::attribute{"pretty_name", "Spot Shadow Params"},
462 entt::attribute{"tooltip", "Spot light shadow map parameters."},
463 entt::attribute{"predicate", casts_shadows_and_is_spot_predicate_entt}
464
465 });
466}
467
473
475{
476 try_save(ar, ser20::make_nvp("range", obj.range));
477 try_save(ar, ser20::make_nvp("inner_angle", obj.inner_angle));
478 try_save(ar, ser20::make_nvp("outer_angle", obj.outer_angle));
479}
482
484{
485 try_save(ar, ser20::make_nvp("fov_x_adjust", obj.fov_x_adjust));
486 try_save(ar, ser20::make_nvp("fov_y_adjust", obj.fov_y_adjust));
487 try_save(ar, ser20::make_nvp("stencil_pack", obj.stencil_pack));
488}
491
493{
494 try_save(ar, ser20::make_nvp("range", obj.range));
495 try_save(ar, ser20::make_nvp("exponent_falloff", obj.exponent_falloff));
496}
499
501{
502 try_save(ar, ser20::make_nvp("num_splits", obj.num_splits));
503 try_save(ar, ser20::make_nvp("split_distribution", obj.split_distribution));
504 try_save(ar, ser20::make_nvp("stabilize", obj.stabilize));
505}
508
514
516{
517 try_save(ar, ser20::make_nvp("type", obj.type));
518 try_save(ar, ser20::make_nvp("depth", obj.depth));
519 try_save(ar, ser20::make_nvp("resolution", obj.resolution));
520 try_save(ar, ser20::make_nvp("bias", obj.bias));
521 try_save(ar, ser20::make_nvp("normal_bias", obj.normal_bias));
522 try_save(ar, ser20::make_nvp("near_plane", obj.near_plane));
523 try_save(ar, ser20::make_nvp("far_plane", obj.far_plane));
524
525
526}
529
531{
532 try_save(ar, ser20::make_nvp("type", obj.type));
533 try_save(ar, ser20::make_nvp("intensity", obj.intensity));
534 try_save(ar, ser20::make_nvp("ambient_intensity", obj.ambient_intensity));
535 try_save(ar, ser20::make_nvp("color", obj.color));
536 try_save(ar, ser20::make_nvp("casts_shadows", obj.casts_shadows));
537
538 try_save(ar, ser20::make_nvp("shadow_params", obj.shadow_params));
539
540 if(obj.type == light_type::spot)
541 {
542 try_save(ar, ser20::make_nvp("spot_data", obj.spot_data));
543 try_save(ar, ser20::make_nvp("spot_shadow_params", obj.spot_shadow_params));
544 }
545 else if(obj.type == light_type::point)
546 {
547 try_save(ar, ser20::make_nvp("point_data", obj.point_data));
548 try_save(ar, ser20::make_nvp("point_shadow_params", obj.point_shadow_params));
549 }
550 else if(obj.type == light_type::directional)
551 {
552 try_save(ar, ser20::make_nvp("directional_data", obj.directional_data));
553 try_save(ar, ser20::make_nvp("directional_shadow_params", obj.directional_shadow_params));
554 }
555}
558
564
566{
567 try_load(ar, ser20::make_nvp("range", obj.range));
568 try_load(ar, ser20::make_nvp("inner_angle", obj.inner_angle));
569 try_load(ar, ser20::make_nvp("outer_angle", obj.outer_angle));
570}
573
575{
576 try_load(ar, ser20::make_nvp("fov_x_adjust", obj.fov_x_adjust));
577 try_load(ar, ser20::make_nvp("fov_y_adjust", obj.fov_y_adjust));
578 try_load(ar, ser20::make_nvp("stencil_pack", obj.stencil_pack));
579}
582
584{
585 try_load(ar, ser20::make_nvp("range", obj.range));
586 try_load(ar, ser20::make_nvp("exponent_falloff", obj.exponent_falloff));
587}
590
592{
593 try_load(ar, ser20::make_nvp("num_splits", obj.num_splits));
594 try_load(ar, ser20::make_nvp("split_distribution", obj.split_distribution));
595 try_load(ar, ser20::make_nvp("stabilize", obj.stabilize));
596}
599
605
607{
608 try_load(ar, ser20::make_nvp("type", obj.type));
609 try_load(ar, ser20::make_nvp("depth", obj.depth));
610 try_load(ar, ser20::make_nvp("resolution", obj.resolution));
611 try_load(ar, ser20::make_nvp("bias", obj.bias));
612 try_load(ar, ser20::make_nvp("normal_bias", obj.normal_bias));
613 try_load(ar, ser20::make_nvp("near_plane", obj.near_plane));
614 try_load(ar, ser20::make_nvp("far_plane", obj.far_plane));
615}
618
620{
621 try_load(ar, ser20::make_nvp("type", obj.type));
622 try_load(ar, ser20::make_nvp("intensity", obj.intensity));
623 try_load(ar, ser20::make_nvp("ambient_intensity", obj.ambient_intensity));
624 try_load(ar, ser20::make_nvp("color", obj.color));
625 try_load(ar, ser20::make_nvp("casts_shadows", obj.casts_shadows));
626 try_load(ar, ser20::make_nvp("shadow_params", obj.shadow_params));
627
628 if(obj.type == light_type::spot)
629 {
630 try_load(ar, ser20::make_nvp("spot_data", obj.spot_data));
631 try_load(ar, ser20::make_nvp("spot_shadow_params", obj.spot_shadow_params));
632 }
633 else if(obj.type == light_type::point)
634 {
635 try_load(ar, ser20::make_nvp("point_data", obj.point_data));
636 try_load(ar, ser20::make_nvp("point_shadow_params", obj.point_shadow_params));
637 }
638 else if(obj.type == light_type::directional)
639 {
640 try_load(ar, ser20::make_nvp("directional_data", obj.directional_data));
641 try_load(ar, ser20::make_nvp("directional_shadow_params", obj.directional_shadow_params));
642 }
643}
646} // namespace unravel
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 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 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:221
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:215
light_type type
The type of the light.
Definition light.h:89