Unravel Engine C++ Reference
Loading...
Searching...
No Matches
reflection_probe_component.cpp
Go to the documentation of this file.
4
7
8namespace unravel
9{
11{
12 auto realtime_predicate_entt = entt::property_predicate<bool>(
13 [](const entt::meta_any& obj)
14 {
15 auto data = obj.try_cast<reflection_probe_component>();
16 return data != nullptr && data->get_update_mode() == probe_update_mode::realtime;
17 });
18
19 entt::meta_factory<reflection_probe_component>{}
20 .type("reflection_probe_component"_hs)
22 entt::attribute{"name", "reflection_probe_component"},
23 entt::attribute{"category", "LIGHTING"},
24 entt::attribute{"pretty_name", "Reflection Probe"},
25 })
26 .func<&component_meta<reflection_probe_component>::exists>("component_exists"_hs)
27 .func<&component_meta<reflection_probe_component>::add>("component_add"_hs)
28 .func<&component_meta<reflection_probe_component>::remove>("component_remove"_hs)
29 .func<&component_meta<reflection_probe_component>::save>("component_save"_hs)
30 .func<&component_meta<reflection_probe_component>::load>("component_load"_hs)
32 .custom<entt::attributes>(entt::attributes{
33 entt::attribute{"name", "probe"},
34 entt::attribute{"pretty_name", "Probe"},
35 })
36 .data<&reflection_probe_component::set_update_mode, &reflection_probe_component::get_update_mode>("update_mode"_hs)
38 entt::attribute{"name", "update_mode"},
39 entt::attribute{"pretty_name", "Update Mode"},
40 entt::attribute{"group", "Update"},
41 entt::attribute{"tooltip",
42 "On Demand: never refreshes until explicitly requested (runtime default, cheapest)."
43 "\nOnce: bakes a single time on load or after edits, then stops."
44 "\nRealtime: refreshes continuously, time-sliced by Faces Per Frame and Update Interval."},
45 })
46 .data<&reflection_probe_component::set_update_interval, &reflection_probe_component::get_update_interval>("update_interval"_hs)
48 entt::attribute{"name", "update_interval"},
49 entt::attribute{"pretty_name", "Update Interval (s)"},
50 entt::attribute{"group", "Update"},
51 entt::attribute{"tooltip",
52 "Seconds between refreshes when Update Mode is Realtime. 0 means every available frame."},
53 entt::attribute{"min", 0.0f},
54 entt::attribute{"predicate", realtime_predicate_entt},
55 })
56 .data<&reflection_probe_component::set_faces_per_frame, &reflection_probe_component::get_faces_per_frame>("faces_per_frame"_hs)
58 entt::attribute{"name", "faces_per_frame"},
59 entt::attribute{"pretty_name", "Faces Per Frame"},
60 entt::attribute{"group", "Update"},
61 entt::attribute{"tooltip",
62 "Number of cubemap faces to refresh per frame while a bake is in progress. "
63 "Higher values finish bakes faster but cost more per frame. "
64 "Only applies while the probe is dirty; probes at rest cost nothing."},
65 entt::attribute{"min", 1},
66 entt::attribute{"max", 6},
67 })
68 .data<&reflection_probe_component::set_apply_prefilter, &reflection_probe_component::get_apply_prefilter>("apply_prefilter"_hs)
70 entt::attribute{"name", "apply_prefilter"},
71 entt::attribute{"pretty_name", "Apply Prefilter"},
72 entt::attribute{"group", "Update"},
73 entt::attribute{"tooltip", "Enables prefiltering which improves quality but may impact performance"},
74 })
75 .data<&reflection_probe_component::set_resolution, &reflection_probe_component::get_resolution>("resolution"_hs)
77 entt::attribute{"name", "resolution"},
78 entt::attribute{"pretty_name", "Resolution"},
79 entt::attribute{"group", "Capture"},
80 entt::attribute{"tooltip", "Cubemap face resolution in pixels. Higher values improve quality but increase bake cost and memory."},
81 })
82 .data<&reflection_probe_component::set_capture_sky, &reflection_probe_component::get_capture_sky>("capture_sky"_hs)
84 entt::attribute{"name", "capture_sky"},
85 entt::attribute{"pretty_name", "Capture Sky"},
86 entt::attribute{"group", "Capture"},
87 entt::attribute{"tooltip",
88 "When enabled, the atmospheric sky pass is rendered into the cubemap. "
89 "Disable for interior or local probes that should only reflect nearby geometry."},
90 })
91 .data<&reflection_probe_component::set_capture_shadows, &reflection_probe_component::get_capture_shadows>("capture_shadows"_hs)
93 entt::attribute{"name", "capture_shadows"},
94 entt::attribute{"pretty_name", "Capture Shadows"},
95 entt::attribute{"group", "Capture"},
96 entt::attribute{"tooltip",
97 "When enabled, shadow maps are built and sampled during cubemap capture. "
98 "Disable to reduce bake cost when shadows are not needed in reflections."},
99 });
100}
101
103{
104 try_save(ar, ser20::make_nvp("probe", obj.get_probe()));
105 try_save(ar, ser20::make_nvp("update_mode", obj.get_update_mode()));
106 try_save(ar, ser20::make_nvp("update_interval", obj.get_update_interval()));
107 try_save(ar, ser20::make_nvp("faces_per_frame", obj.get_faces_per_frame()));
108 try_save(ar, ser20::make_nvp("apply_prefilter", obj.get_apply_prefilter()));
109 try_save(ar, ser20::make_nvp("resolution", obj.get_resolution()));
110 try_save(ar, ser20::make_nvp("capture_sky", obj.get_capture_sky()));
111 try_save(ar, ser20::make_nvp("capture_shadows", obj.get_capture_shadows()));
112}
115
117{
118 // Load update_mode before the probe so that set_probe's on_demand gate sees the correct mode.
119 probe_update_mode update_mode = obj.get_update_mode();
120 if(try_load(ar, ser20::make_nvp("update_mode", update_mode)))
121 {
122 obj.set_update_mode(update_mode);
123 }
124
125 float update_interval = obj.get_update_interval();
126 if(try_load(ar, ser20::make_nvp("update_interval", update_interval)))
127 {
128 obj.set_update_interval(update_interval);
129 }
130
131 reflection_probe probe;
132 if(try_load(ar, ser20::make_nvp("probe", probe)))
133 {
134 obj.set_probe(probe);
135 }
136
137 size_t faces_per_frame = obj.get_faces_per_frame();
138 if(try_load(ar, ser20::make_nvp("faces_per_frame", faces_per_frame)))
139 {
140 obj.set_faces_per_frame(faces_per_frame);
141 }
142
143 bool apply_prefilter = false;
144 if(try_load(ar, ser20::make_nvp("apply_prefilter", apply_prefilter)))
145 {
146 obj.set_apply_prefilter(apply_prefilter);
147 }
148
149 probe_resolution resolution = obj.get_resolution();
150 if(try_load(ar, ser20::make_nvp("resolution", resolution)))
151 {
152 obj.set_resolution(resolution);
153 }
154
155 bool capture_sky = obj.get_capture_sky();
156 if(try_load(ar, ser20::make_nvp("capture_sky", capture_sky)))
157 {
158 obj.set_capture_sky(capture_sky);
159 }
160
161 bool capture_shadows = obj.get_capture_shadows();
162 if(try_load(ar, ser20::make_nvp("capture_shadows", capture_shadows)))
163 {
164 obj.set_capture_shadows(capture_shadows);
165 }
166}
169} // namespace unravel
Class that contains core reflection probe data, used for rendering and other purposes.
auto get_probe() const -> const reflection_probe &
Gets the reflection probe object.
auto get_update_mode() const -> probe_update_mode
Gets the probe's update policy.
void set_probe(const reflection_probe &probe)
Sets the reflection probe object.
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
probe_update_mode
Enum class describing when a reflection probe refreshes its cubemap.
probe_resolution
Fixed cubemap face resolutions supported by reflection probes.
#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
Structure representing a reflection probe.