Browse Source

Parameterize RGB wavelengths

master
C. J. Howard 2 years ago
parent
commit
b0b3cd3235
6 changed files with 39 additions and 13 deletions
  1. +9
    -5
      src/ecs/systems/atmosphere-system.cpp
  2. +7
    -0
      src/ecs/systems/atmosphere-system.hpp
  3. +9
    -5
      src/ecs/systems/blackbody-system.cpp
  4. +7
    -0
      src/ecs/systems/blackbody-system.hpp
  5. +5
    -0
      src/game/bootloader.cpp
  6. +2
    -3
      src/game/game-context.hpp

+ 9
- 5
src/ecs/systems/atmosphere-system.cpp View File

@ -23,12 +23,10 @@
namespace ecs {
atmosphere_system::atmosphere_system(ecs::registry& registry):
entity_system(registry)
entity_system(registry),
rgb_wavelengths_nm{0, 0, 0},
rgb_wavelengths_m{0, 0, 0}
{
// RGB wavelengths determined by matching wavelengths to XYZ, transforming XYZ to ACEScg, then selecting the max wavelengths for R, G, and B.
rgb_wavelengths_nm = {602.224, 541.069, 448.143};
rgb_wavelengths_m = rgb_wavelengths_nm * 1e-9;
registry.on_construct<ecs::atmosphere_component>().connect<&atmosphere_system::on_atmosphere_construct>(this);
registry.on_replace<ecs::atmosphere_component>().connect<&atmosphere_system::on_atmosphere_replace>(this);
}
@ -36,6 +34,12 @@ atmosphere_system::atmosphere_system(ecs::registry& registry):
void atmosphere_system::update(double t, double dt)
{}
void atmosphere_system::set_rgb_wavelengths(const double3& wavelengths)
{
rgb_wavelengths_nm = wavelengths;
rgb_wavelengths_m = wavelengths * 1e-9;
}
void atmosphere_system::update_coefficients(ecs::entity entity)
{
// Abort if entity has no atmosphere component

+ 7
- 0
src/ecs/systems/atmosphere-system.hpp View File

@ -38,6 +38,13 @@ public:
virtual void update(double t, double dt);
/**
* Sets the wavelengths of red, green, and blue light.
*
* @param wavelengths Vector containing the wavelengths of red (x), green (y), and blue (z) light, in nanometers.
*/
void set_rgb_wavelengths(const double3& wavelengths);
private:
void update_coefficients(ecs::entity entity);

+ 9
- 5
src/ecs/systems/blackbody-system.cpp View File

@ -26,12 +26,10 @@
namespace ecs {
blackbody_system::blackbody_system(ecs::registry& registry):
entity_system(registry)
entity_system(registry),
rgb_wavelengths_nm{0, 0, 0},
rgb_wavelengths_m{0, 0, 0}
{
// RGB wavelengths determined by matching wavelengths to XYZ, transforming XYZ to ACEScg, then selecting the max wavelengths for R, G, and B.
rgb_wavelengths_nm = {602.224, 541.069, 448.143};
rgb_wavelengths_m = rgb_wavelengths_nm * 1e-9;
// Construct a range of sample wavelengths in the visible spectrum
visible_wavelengths_nm.resize(780 - 280);
std::iota(visible_wavelengths_nm.begin(), visible_wavelengths_nm.end(), 280);
@ -46,6 +44,12 @@ blackbody_system::blackbody_system(ecs::registry& registry):
void blackbody_system::update(double t, double dt)
{}
void blackbody_system::set_rgb_wavelengths(const double3& wavelengths)
{
rgb_wavelengths_nm = wavelengths;
rgb_wavelengths_m = wavelengths * 1e-9;
}
void blackbody_system::update_luminous_intensity(ecs::entity entity)
{
// Abort if entity has no blackbody component

+ 7
- 0
src/ecs/systems/blackbody-system.hpp View File

@ -40,6 +40,13 @@ public:
virtual void update(double t, double dt);
/**
* Sets the wavelengths of red, green, and blue light.
*
* @param wavelengths Vector containing the wavelengths of red (x), green (y), and blue (z) light, in nanometers.
*/
void set_rgb_wavelengths(const double3& wavelengths);
private:
void update_luminous_intensity(ecs::entity entity);

+ 5
- 0
src/game/bootloader.cpp View File

@ -789,6 +789,9 @@ void setup_systems(game_context* ctx)
const auto& viewport_dimensions = ctx->app->get_viewport_dimensions();
float4 viewport = {0.0f, 0.0f, static_cast<float>(viewport_dimensions[0]), static_cast<float>(viewport_dimensions[1])};
// RGB wavelengths determined by matching wavelengths to XYZ, transforming XYZ to ACEScg, then selecting the max wavelengths for R, G, and B.
const double3 rgb_wavelengths_nm = {602.224, 541.069, 448.143};
// Setup terrain system
ctx->terrain_system = new ecs::terrain_system(*ctx->ecs_registry, ctx->resource_manager);
ctx->terrain_system->set_patch_size(TERRAIN_PATCH_SIZE);
@ -864,9 +867,11 @@ void setup_systems(game_context* ctx)
// Setup blackbody system
ctx->blackbody_system = new ecs::blackbody_system(*ctx->ecs_registry);
ctx->blackbody_system->set_rgb_wavelengths(rgb_wavelengths_nm);
// Setup atmosphere system
ctx->atmosphere_system = new ecs::atmosphere_system(*ctx->ecs_registry);
ctx->atmosphere_system->set_rgb_wavelengths(rgb_wavelengths_nm);
// Setup astronomy system
ctx->astronomy_system = new ecs::astronomy_system(*ctx->ecs_registry);

+ 2
- 3
src/game/game-context.hpp View File

@ -36,6 +36,7 @@
#include "input/mapper.hpp"
#include "input/event-router.hpp"
#include "animation/tween.hpp"
#include "scene/scene.hpp"
#include <optional>
#include <entt/entt.hpp>
#include <fstream>
@ -98,8 +99,6 @@ namespace ecs
class samara_system;
}
#include "scene/scene.hpp"
/**
*
*/
@ -206,7 +205,7 @@ struct game_context
screen_transition* radial_transition_outer;
animation<float>* equip_tool_animation;
animation<float>* unequip_tool_animation;
// Controls
input::event_router* input_event_router;
input::mapper* input_mapper;

Loading…
Cancel
Save