29 update_shadow_cascade_distances();
39 m_shadow_caster = caster;
44 m_shadow_framebuffer = std::move(framebuffer);
45 if (m_shadow_framebuffer)
47 if (!m_shadow_texture)
49 m_shadow_texture = std::make_shared<gl::texture_2d>
51 std::static_pointer_cast<gl::image_view_2d>(m_shadow_framebuffer->attachments().front().image_view),
52 std::make_shared<gl::sampler>
69 m_shadow_texture->set_image_view(std::static_pointer_cast<gl::image_view_2d>(m_shadow_framebuffer->attachments().front().image_view));
74 m_shadow_texture =
nullptr;
81 update_shadow_scale_bias_matrices();
87 update_shadow_scale_bias_matrices();
88 update_shadow_cascade_distances();
94 update_shadow_cascade_distances();
99 m_shadow_fade_range = range;
104 m_shadow_cascade_distribution = weight;
105 update_shadow_cascade_distances();
108 void directional_light::transformed()
113 void directional_light::color_updated()
115 m_colored_illuminance = m_color * m_illuminance;
118 void directional_light::illuminance_updated()
120 m_colored_illuminance = m_color * m_illuminance;
123 void directional_light::update_shadow_scale_bias_matrices()
131 for (
unsigned int i = 0;
i < m_shadow_cascade_count; ++
i)
134 m_shadow_scale_bias_matrices[
i] =
math::translate(
math::fvec3{
static_cast<float>(
i % 2) * 0.5f,
static_cast<float>(i / 2) * 0.5f, 0.0f}) * m;
138 void directional_light::update_shadow_cascade_distances()
140 if (!m_shadow_cascade_count)
145 m_shadow_cascade_distances[m_shadow_cascade_count - 1] = m_shadow_max_distance;
146 for (
unsigned int i = 0;
i < m_shadow_cascade_count - 1; ++
i)
148 const auto weight =
static_cast<float>(
i + 1) /
static_cast<float>(m_shadow_cascade_count);
151 const auto linear_distance = m_shadow_max_distance * weight;
157 m_shadow_cascade_distances[
i] = linear_distance;
void set_shadow_fade_range(float range) noexcept
Sets the distance from the maximum shadow distance at which shadows will begin to fade out.
void set_direction(const math::fvec3 &direction)
Sets the direction of the directional light.
void set_shadow_framebuffer(std::shared_ptr< gl::framebuffer > framebuffer) noexcept
Sets the shadow map framebuffer.
void set_shadow_cascade_count(unsigned int count) noexcept
Sets the number of shadow cascades.
void set_shadow_max_distance(float distance) noexcept
Sets the maximum distance from a camera's near clipping plane up to which shadows are visible.
directional_light()
Creates a directional light.
void set_shadow_bias(float bias) noexcept
Sets the shadow bias factor for reducing self-shadowing.
void set_shadow_caster(bool caster) noexcept
Enables or disables shadow casting.
void set_shadow_cascade_distribution(float weight) noexcept
Sets the shadow cascade distribution.
void set_rotation(const quaternion_type &rotation)
Sets the rotation of the object.
constexpr const quaternion_type & get_rotation() const noexcept
Returns the rotation of the object.
constexpr int count(T x) noexcept
Returns the number of set bits in a value, known as a population count or Hamming weight.
@ clamp_to_border
Clamp to border wrap mode.
@ linear
Linear filtering.
@ linear
Linear filtering.
@ greater
Comparison evaluates reference > test.
constexpr mat4< T > translate(const vec3< T > &v)
Constructs a translation matrix.
constexpr vector< T, N > max(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the maximum elements of two vectors.
quaternion< T > rotation(const vec3< T > &from, const vec3< T > &to, T tolerance=T{1e-6})
Constructs a quaternion representing the minimum rotation from one direction to another direction.
constexpr mat4< T > scale(const vec3< T > &v)
Constructs a scale matrix.
T distance(const vector< T, N > &p0, const vector< T, N > &p1)
Calculates the distance between two points.
constexpr vector< T, N > min(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the minimum elements of two vectors.