Browse Source

Improve sphere light interface

master
C. J. Howard 11 months ago
parent
commit
11a42b4af3
5 changed files with 88 additions and 21 deletions
  1. +3
    -3
      src/engine/render/passes/material-pass.cpp
  2. +9
    -0
      src/engine/scene/sphere-light.cpp
  3. +46
    -9
      src/engine/scene/sphere-light.hpp
  4. +8
    -8
      src/engine/scene/spot-light.hpp
  5. +22
    -1
      src/game/states/nest-view-state.cpp

+ 3
- 3
src/engine/render/passes/material-pass.cpp View File

@ -396,7 +396,7 @@ void material_pass::evaluate_lighting(const render::context& ctx)
spot_light_cutoffs.resize(spot_light_count);
}
spot_light_colors[index] = spot_light.get_luminous_flux() * ctx.camera->get_exposure_normalization();
spot_light_colors[index] = spot_light.get_luminous_power() * ctx.camera->get_exposure_normalization();
spot_light_positions[index] = spot_light.get_translation();
spot_light_directions[index] = spot_light.get_direction();
spot_light_cutoffs[index] = spot_light.get_cosine_cutoff();
@ -419,7 +419,7 @@ void material_pass::evaluate_lighting(const render::context& ctx)
point_light_positions.resize(point_light_count);
}
point_light_colors[index] = sphere_light.get_luminous_flux() * ctx.camera->get_exposure_normalization();
point_light_colors[index] = sphere_light.get_spectral_luminous_power() * ctx.camera->get_exposure_normalization();
point_light_positions[index] = sphere_light.get_translation();
}
else
@ -433,7 +433,7 @@ void material_pass::evaluate_lighting(const render::context& ctx)
sphere_light_positions_radii.resize(sphere_light_count);
}
sphere_light_colors[index] = sphere_light.get_luminous_flux() * ctx.camera->get_exposure_normalization();
sphere_light_colors[index] = sphere_light.get_spectral_luminous_power() * ctx.camera->get_exposure_normalization();
const auto& position = sphere_light.get_translation();
auto& position_radius = sphere_light_positions_radii[index];

+ 9
- 0
src/engine/scene/sphere-light.cpp View File

@ -18,9 +18,18 @@
*/
#include <engine/scene/sphere-light.hpp>
#include <engine/math/numbers.hpp>
namespace scene {
float sphere_light::get_luminance() const noexcept
{
return m_luminous_power / (4.0f * m_radius * m_radius * math::sqr_pi<float>);
}
math::vector<float, 3> sphere_light::get_spectral_luminance() const noexcept
{
return m_color * get_luminance();
}
} // namespace scene

+ 46
- 9
src/engine/scene/sphere-light.hpp View File

@ -38,13 +38,25 @@ public:
}
/**
* Sets the luminous flux of the sphere light.
* Sets the color of the sphere light.
*
* @param luminous_flux Luminous flux, in *lm*.
* @param color Light color.
*/
inline void set_luminous_flux(const math::vector<float, 3>& luminous_flux) noexcept
inline void set_color(const math::vector<float, 3>& color) noexcept
{
m_luminous_flux = luminous_flux;
m_color = color;
update_spectral_luminous_power();
}
/**
* Sets the luminous power of the sphere light.
*
* @param luminous_power Luminous power.
*/
inline void set_luminous_power(float luminous_power) noexcept
{
m_luminous_power = luminous_power;
update_spectral_luminous_power();
}
/**
@ -57,10 +69,22 @@ public:
m_radius = radius;
}
/// Returns the luminous flux of the sphere light, in *lm*.
[[nodiscard]] inline const math::vector<float, 3>& get_luminous_flux() const noexcept
/// Returns the color of the sphere light.
[[nodiscard]] inline const math::vector<float, 3>& get_color() const noexcept
{
return m_color;
}
/// Returns the luminous power of the sphere light.
[[nodiscard]] inline float get_luminous_power() const noexcept
{
return m_luminous_flux;
return m_luminous_power;
}
/// Returns the spectral luminous power of the sphere light.
[[nodiscard]] inline const math::vector<float, 3>& get_spectral_luminous_power() const noexcept
{
return m_spectral_luminous_power;
}
/// Returns the radius of the sphere light.
@ -68,10 +92,23 @@ public:
{
return m_radius;
}
/// Calculates and returns the luminance of the sphere light.
[[nodiscard]] float get_luminance() const noexcept;
/// Calculates and returns the spectral luminance of the sphere light.
[[nodiscard]] math::vector<float, 3> get_spectral_luminance() const noexcept;
private:
math::vector<float, 3> m_luminous_flux{0.0f, 0.0f, 0.0f};
float m_radius{0.0f};
inline void update_spectral_luminous_power() noexcept
{
m_spectral_luminous_power = m_color * m_luminous_power;
}
math::vector<float, 3> m_color{1.0f, 1.0f, 1.0f};
float m_luminous_power{};
math::vector<float, 3> m_spectral_luminous_power{};
float m_radius{};
};
} // namespace scene

+ 8
- 8
src/engine/scene/spot-light.hpp View File

@ -39,19 +39,19 @@ public:
}
/**
* Sets the luminous flux of the spot light.
* Sets the luminous power of the spot light.
*
* @param luminous_flux Luminous flux, in *lm*.
* @param luminous_power Luminous power, in *lm*.
*/
inline void set_luminous_flux(const math::vector<float, 3>& luminous_flux) noexcept
inline void set_luminous_power(const math::vector<float, 3>& luminous_power) noexcept
{
m_luminous_flux = luminous_flux;
m_luminous_power = luminous_power;
}
/// Returns the luminous flux of the spot light, in *lm*.
[[nodiscard]] inline const math::vector<float, 3>& get_luminous_flux() const noexcept
/// Returns the luminous power of the spot light, in *lm*.
[[nodiscard]] inline const math::vector<float, 3>& get_luminous_power() const noexcept
{
return m_luminous_flux;
return m_luminous_power;
}
/**
@ -82,7 +82,7 @@ public:
private:
void transformed() override;
math::vector<float, 3> m_luminous_flux{0.0f, 0.0f, 0.0f};
math::vector<float, 3> m_luminous_power{0.0f, 0.0f, 0.0f};
math::vector<float, 3> m_direction{0.0f, 0.0f, -1.0f};
math::vector<float, 2> m_cutoff{math::pi<float>, math::pi<float>};
math::vector<float, 2> m_cosine_cutoff{-1.0f, -1.0f};

+ 22
- 1
src/game/states/nest-view-state.cpp View File

@ -128,7 +128,8 @@ nest_view_state::nest_view_state(::game& ctx):
// Create sphere light
ctx.underground_sphere_light = std::make_unique<scene::sphere_light>();
ctx.underground_sphere_light->set_luminous_flux(float3{0.8f, 0.88f, 1.0f} * 250.0f);
ctx.underground_sphere_light->set_color({0.8f, 0.88f, 1.0f});
ctx.underground_sphere_light->set_luminous_power(300.0f);
ctx.underground_sphere_light->set_radius(3.0f);
ctx.underground_sphere_light->set_translation(float3{-13.0f, 7.0f, -6.0f});
ctx.underground_scene->add_object(*ctx.underground_sphere_light);
@ -180,6 +181,26 @@ nest_view_state::nest_view_state(::game& ctx):
}
);
// Create light sphere
auto light_sphere_model = ctx.resource_manager->load<render::model>("light-sphere.mdl");
auto light_sphere_material = std::make_shared<render::material>(*light_sphere_model->get_groups().front().material);
static_cast<render::material_float3&>(*light_sphere_material->get_variable("emissive")).set(ctx.underground_sphere_light->get_spectral_luminance());
auto light_sphere_static_mesh = std::make_shared<scene::static_mesh>(light_sphere_model);
light_sphere_static_mesh->set_material(0, light_sphere_material);
auto light_sphere_eid = ctx.entity_registry->create();
ctx.entity_registry->emplace<scene_component>(light_sphere_eid, std::move(light_sphere_static_mesh), std::uint8_t{2});
ctx.entity_registry->patch<scene_component>
(
light_sphere_eid,
[&](auto& component)
{
component.object->set_translation(ctx.underground_sphere_light->get_translation());
component.object->set_scale(math::vector<float, 3>{1, 1, 1} * ctx.underground_sphere_light->get_radius());
}
);
// Disable UI color clear
ctx.ui_clear_pass->set_cleared_buffers(false, true, false);

Loading…
Cancel
Save