24 #include <engine/config.hpp>
32 m_visible_wavelengths_nm.resize(780 - 280);
33 std::iota(m_visible_wavelengths_nm.begin(), m_visible_wavelengths_nm.end(), 280);
48 void blackbody_system::update_blackbody(
entity::id entity_id)
54 auto rgb_spectral_luminance = [&](
double wavelength_nm) ->
math::dvec3
57 const double wavelength_m = wavelength_nm * 1
e-9;
60 const double spectral_radiance = physics::light::blackbody::spectral_radiance<double>(blackbody.temperature, wavelength_m);
63 const double spectral_luminance =
spectral_radiance * 1
e-9 * physics::light::max_luminous_efficacy<double>;
67 const auto color_rgb = config::scene_linear_color_space<double>.from_xyz * color_xyz;
70 return color_rgb * spectral_luminance;
77 blackbody.luminance =
math::max(rgb_luminance);
78 blackbody.color = rgb_luminance / blackbody.luminance;
83 update_blackbody(entity_id);
88 update_blackbody(entity_id);
void update(float t, float dt) override
Perform's a system's update() function.
blackbody_system(entity::registry ®istry)
Abstract base class for updatable systems.
entity::registry & registry
Registry on which the system operate.
math::vec3< T > xyz_match(T lambda)
Fitted piecewise gaussian approximation to the CIE 1931 standard observer color matching function.
entt::registry registry
Component registry type.
entt::entity id
Entity ID type.
std::invoke_result< UnaryOp, typename std::iterator_traits< InputIt >::value_type >::type simpson(UnaryOp f, InputIt first, InputIt last)
Approximates the definite integral of a function using Simpson's 1/3 rule.
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.
T spectral_radiance(T t, T lambda, T c=constants::speed_of_light< T >)
Calculates the spectral radiance of a blackbody for the given wavelength.