27 const math::vec3& position,
28 const math::vec3&
scale,
29 const math::vec3& view_origin,
40 probe_.sphere_data.range * math::max(
scale.x, math::max(
scale.y,
scale.z)),
47 float w2 = math::pow(
scale.x * probe_.box_data.extents.x * 2.0f, 2.0f);
48 float h2 = math::pow(
scale.y * probe_.box_data.extents.y * 2.0f, 2.0f);
49 float l2 = math::pow(
scale.z * probe_.box_data.extents.z * 2.0f, 2.0f);
50 float d2 = w2 + h2 + l2;
51 float d = math::sqrt(d2);
76 auto& tex = rview_[0].tex_get_or_emplace(
"CUBEMAP");
79 constexpr uint16_t
size = 256;
80 tex = std::make_shared<gfx::texture>(
size,
83 gfx::texture_format::RGBA8,
84 BGFX_TEXTURE_COMPUTE_WRITE |BGFX_TEXTURE_BLIT_DST | BGFX_TEXTURE_RT);
92 auto& tex = rview_[0].tex_get_or_emplace(
"CUBEMAP_PREFILTERED");
95 constexpr uint16_t
size = 256;
96 tex = std::make_shared<gfx::texture>(
size,
99 gfx::texture_format::RGBA8,
100 BGFX_TEXTURE_COMPUTE_WRITE | BGFX_TEXTURE_BLIT_DST | BGFX_TEXTURE_RT);
108 auto& fbo = rview_[face].fbo_get_or_emplace(
"CUBEMAP");
111 auto& tex = rview_[face].tex_get_or_emplace(
"CUBEMAP_FACE");
114 constexpr uint16_t
size = 256;
115 tex = std::make_shared<gfx::texture>(
size,
119 gfx::texture_format::RGBA8,
120 BGFX_TEXTURE_BLIT_DST | BGFX_TEXTURE_RT);
128 fbo = std::make_shared<gfx::frame_buffer>();
129 fbo->populate({att});
140 bool fully_generated =
true;
141 for(
auto&
frame : generated_frame_)
143 fully_generated &=
frame != uint64_t(-1);
149 for(
auto&
frame : generated_frame_)
151 frame = uint64_t(-1);
157 first_generation_ =
false;
159 generated_faces_count_ = 0;
181 bool generated =
true;
182 for(
size_t i = 0; i < generated_frame_.size(); ++i)
192 if(!first_generation_)
194 if(generated_faces_count_ == faces_per_frame_)
201 return generated_frame_[face] != uint64_t(-1);
205 generated_frame_[face] =
frame;
206 generated_faces_count_++;
std::shared_ptr< texture > ptr
Provides storage for common representation of spherical bounding volume, and wraps up common function...
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.
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 get_probe() const -> const reflection_probe &
Gets the reflection probe object.
void update()
Updates the reflection probe component.
auto get_cubemap_prefiltered() -> const gfx::texture::ptr &
Gets the cubemap texture.
void set_generation_frame(size_t face, uint64_t frame)
marks the genrerated face this frame
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.
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)
@ sphere
Sphere type reflection probe.
@ box
Box type reflection probe.
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.