Unravel Engine C++ Reference
Loading...
Searching...
No Matches
reflection_probe.h
Go to the documentation of this file.
1#pragma once
2#include <engine/engine_export.h>
3
4#include <math/math.h>
5
6#include <cstdint>
7
8namespace unravel
9{
13enum class probe_type : std::uint8_t
14{
16 box = 0,
18 sphere = 1
19};
20
24enum class reflect_method : std::uint8_t
25{
27 environment = 0,
29 static_only = 1
30};
31
38enum class probe_update_mode : std::uint8_t
39{
42 on_demand = 0,
44 once = 1,
47 realtime = 2
48};
49
53enum class probe_resolution : std::uint8_t
54{
55 res_16 = 0,
56 res_32,
57 res_64,
58 res_128,
59 res_256,
60 res_512,
62
63 count
64};
65
69inline auto probe_resolution_to_size(probe_resolution resolution) -> std::uint16_t
70{
71 switch(resolution)
72 {
74 return 16;
76 return 32;
78 return 64;
80 return 128;
82 return 256;
84 return 512;
86 return 1024;
87 default:
88 return 256;
89 }
90}
91
96{
100 struct box
101 {
103 math::vec3 extents = {5.0, 5.0f, 5.0f};
106 };
107
111 struct sphere
112 {
114 float range = 5.0f;
115 };
116
117 auto get_face_extents(uint32_t face, const math::transform& transform) const -> float
118 {
119 const auto& scale = transform.get_scale();
120
122 {
123 auto max_scale = math::max(scale.x, math::max(scale.y, scale.z));
124 return sphere_data.range * max_scale;
125 }
126
127 if(type == probe_type::box)
128 {
129 auto scaled_extents = box_data.extents * scale;
130 return math::max(scaled_extents.x, math::max(scaled_extents.y, scaled_extents.z));
131 }
132
133 return {};
134 }
135
136 auto get_max_range() const -> float
137 {
139 {
140 return sphere_data.range;
141 }
142 else if(type == probe_type::box)
143 {
144 return math::max(box_data.extents.x, math::max(box_data.extents.y, box_data.extents.z));
145 }
146 return 0.0f;
147 }
148
154 float intensity = 1.0f;
159};
160
168inline auto operator==(const reflection_probe& pr1, const reflection_probe& pr2) -> bool
169{
170 return pr1.type == pr2.type && pr1.method == pr2.method &&
171 math::equal(pr1.intensity, pr2.intensity, math::epsilon<float>()) &&
172 math::all(math::equal(pr1.box_data.extents, pr2.box_data.extents, math::epsilon<float>())) &&
173 math::equal(pr1.box_data.transition_distance, pr2.box_data.transition_distance, math::epsilon<float>()) &&
174 math::equal(pr1.sphere_data.range, pr2.sphere_data.range, math::epsilon<float>());
175}
176
184inline auto operator!=(const reflection_probe& pr1, const reflection_probe& pr2) -> bool
185{
186 return !(pr1 == pr2);
187}
188
189} // namespace unravel
General purpose transformation class designed to maintain each component of the transformation separa...
Definition transform.hpp:27
probe_update_mode
Enum class describing when a reflection probe refreshes its cubemap.
@ once
Bakes once on load (or when edited in the editor), then stops refreshing until marked dirty.
probe_resolution
Fixed cubemap face resolutions supported by reflection probes.
auto probe_resolution_to_size(probe_resolution resolution) -> std::uint16_t
Converts a probe_resolution enum value to its pixel size.
probe_type
Enum class representing the type of reflection probe.
@ sphere
Sphere type reflection probe.
@ box
Box type reflection probe.
reflect_method
Enum class representing the reflection method.
@ environment
Environment reflection method.
@ static_only
Static-only reflection method.
auto operator!=(const reflection_probe &pr1, const reflection_probe &pr2) -> bool
Inequality operator for reflection_probe.
auto operator==(const reflection_probe &pr1, const reflection_probe &pr2) -> bool
Equality operator for reflection_probe.
std::vector< float > scale
Structure representing box projection data.
math::vec3 extents
Extents of the box projection.
float transition_distance
Transition distance for the box projection.
Structure representing sphere projection data.
float range
Range of the sphere projection.
Structure representing a reflection probe.
auto get_face_extents(uint32_t face, const math::transform &transform) const -> float
auto get_max_range() const -> float
probe_type type
Type of the reflection probe.
reflect_method method
Reflection method.
box box_data
Data describing box projection.
sphere sphere_data
Data describing sphere projection.