29 const math::vec3&
scale,
30 const math::vec3& view_origin,
41 probe_.sphere_data.range * math::max(
scale.x, math::max(
scale.y,
scale.z)),
48 float w2 = math::pow(
scale.x * probe_.box_data.extents.x * 2.0f, 2.0f);
49 float h2 = math::pow(
scale.y * probe_.box_data.extents.y * 2.0f, 2.0f);
50 float l2 = math::pow(
scale.z * probe_.box_data.extents.z * 2.0f, 2.0f);
51 float d2 = w2 + h2 + l2;
52 float d = math::sqrt(d2);
72 return face_rviews_[idx];
77 auto& tex = rview_.tex_get_or_emplace(
"CUBEMAP");
83 tex = std::make_shared<gfx::texture>(
size,
87 BGFX_TEXTURE_COMPUTE_WRITE |BGFX_TEXTURE_BLIT_DST | BGFX_TEXTURE_RT);
95 auto& tex = rview_.tex_get_or_emplace(
"CUBEMAP_PREFILTERED");
101 tex = std::make_shared<gfx::texture>(
size,
105 BGFX_TEXTURE_COMPUTE_WRITE | BGFX_TEXTURE_BLIT_DST | BGFX_TEXTURE_RT);
113 auto& fbo = face_rviews_[face].fbo_get_or_emplace(
"CUBEMAP");
114 auto& tex = face_rviews_[face].tex_get_or_emplace(
"CUBEMAP_FACE");
121 tex = std::make_shared<gfx::texture>(
size,
126 BGFX_TEXTURE_BLIT_DST | BGFX_TEXTURE_RT | BGFX_TEXTURE_COMPUTE_WRITE);
134 fbo = std::make_shared<gfx::frame_buffer>();
135 fbo->populate({att});
145 if(!has_pending_bake_)
149 time_since_last_refresh_ += dt;
150 if(time_since_last_refresh_ >= update_interval_)
153 has_pending_bake_ =
true;
154 time_since_last_refresh_ = 0.0f;
162 bool fully_generated =
true;
163 for(
auto&
frame : generated_frame_)
165 fully_generated &=
frame != uint64_t(-1);
172 for(
auto&
frame : generated_frame_)
174 frame = uint64_t(-1);
176 first_generation_ =
false;
177 has_pending_bake_ =
false;
178 time_since_last_refresh_ = 0.0f;
181 generated_faces_count_ = 0;
217 if(update_mode_ == mode)
224 const auto previous = update_mode_;
226 time_since_last_refresh_ = 0.0f;
241 if(!has_pending_bake_)
246 bool generated =
true;
247 for(
size_t i = 0; i < generated_frame_.size(); ++i)
256 if(!has_pending_bake_)
263 if(!first_generation_)
265 if(faces_per_frame_ > 0 && generated_faces_count_ >= faces_per_frame_)
271 return generated_frame_[face] != uint64_t(-1);
275 generated_frame_[face] =
frame;
276 generated_faces_count_++;
282 for(
auto&
frame : generated_frame_)
284 frame = uint64_t(-1);
286 generated_faces_count_ = 0;
287 has_pending_bake_ =
true;
288 time_since_last_refresh_ = 0.0f;
290 if(force_full_first_frame)
294 first_generation_ =
true;
300 return has_pending_bake_;
305 if(!has_pending_bake_)
310 for(
const auto frame : generated_frame_)
312 if(
frame != uint64_t(-1))
323 if(!has_pending_bake_)
328 for(
const auto frame : generated_frame_)
330 if(
frame == uint64_t(-1))
341 if(resolution_ == resolution)
347 resolution_ = resolution;
358 if(capture_sky_ == capture)
364 capture_sky_ = capture;
374 if(capture_shadows_ == capture)
380 capture_shadows_ = capture;
gfx::texture_format format
std::shared_ptr< texture > ptr
Provides storage for common representation of spherical bounding volume, and wraps up common function...
auto is_dirty() const -> bool
Returns true if the probe has pending or in-flight cubemap generation work.
auto compute_projected_sphere_rect(irect32_t &rect, const math::vec3 &position, const math::vec3 &scale, const math::vec3 &view_origin, const math::transform &view, const math::transform &proj) const -> int
Computes the projected sphere rectangle.
void mark_dirty(bool force_full_first_frame=false)
Requests the probe to rebuild its cubemap.
void set_capture_sky(bool capture)
Sets whether the atmospheric sky pass runs during cubemap capture. Disable for interior/local probes ...
auto get_cubemap_fbo(size_t face) -> const gfx::frame_buffer::ptr &
Gets the cubemap frame buffer object (FBO).
auto get_bounds() const -> math::bbox
Gets the bounding box of the probe object.
auto is_bake_complete() const -> bool
Returns true when all six cubemap faces have been rendered in the current bake cycle.
auto get_probe() const -> const reflection_probe &
Gets the reflection probe object.
void set_resolution(probe_resolution resolution)
Sets the cubemap face resolution. Triggers a rebuild when changed.
auto get_cubemap_prefiltered() -> const gfx::texture::ptr &
Gets the cubemap texture.
void set_capture_shadows(bool capture)
Sets whether shadow maps are built and sampled during cubemap capture.
void update(float dt)
Advances the probe's update bookkeeping. Called once per frame by reflection_probe_system.
auto is_bake_cycle_unstarted() const -> bool
Returns true when a bake has been requested but no cubemap face has been emitted yet.
void set_generation_frame(size_t face, uint64_t frame)
marks the genrerated face this frame
void set_update_mode(probe_update_mode mode)
Sets the probe's update policy. Switching INTO on_demand leaves the current bake state as-is; switchi...
auto get_render_view(size_t idx) -> gfx::render_view &
Gets the render view.
auto already_generated() const -> bool
Check if the cubemap was generated this frame.
auto get_cubemap() -> const gfx::texture::ptr &
void set_probe(const reflection_probe &probe)
Sets the reflection probe object.
bgfx::TextureFormat::Enum texture_format
auto needs_recreate(const gfx::frame_buffer::ptr &fbo, const usize32_t &size) -> bool
std::uint32_t compute_projected_sphere_rect(std::int32_t &left, std::int32_t &right, std::int32_t &top, std::int32_t &bottom, const glm::vec3 &sphere_center, float radius, const glm::vec3 &view_origin, const glm::mat4 &view, const glm::mat4 &proj)
probe_update_mode
Enum class describing when a reflection probe refreshes its cubemap.
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.
@ sphere
Sphere type reflection probe.
@ box
Box type reflection probe.
std::vector< float > scale
std::shared_ptr< gfx::texture > texture
Texture handle.
std::uint16_t layer
Cubemap side or depth layer/slice.
Storage for box vector values and wraps up common functionality.
vec3 max
The maximum vector value of the bounding box.
bbox & from_sphere(const vec3 ¢er, float radius)
Calculates the bounding box based on the sphere specified.
vec3 min
The minimum vector value of the bounding box.
void touch()
Marks the component as 'touched'.
math::vec3 extents
Extents of the box projection.
float range
Range of the sphere projection.
Structure representing a reflection probe.
probe_type type
Type of the reflection probe.
box box_data
Data describing box projection.
sphere sphere_data
Data describing sphere projection.