Browse Source

Add function for converting visual magnitude to relative brightness. Pass relative brightness to star geometry

master
C. J. Howard 1 year ago
parent
commit
972d75b72c
4 changed files with 55 additions and 13 deletions
  1. +7
    -0
      src/astro/illuminance.cpp
  2. +11
    -0
      src/astro/illuminance.hpp
  3. +31
    -5
      src/game/state/nuptial-flight.cpp
  4. +6
    -8
      src/game/world.cpp

+ 7
- 0
src/astro/illuminance.cpp View File

@ -23,6 +23,13 @@
namespace astro
{
double vmag_to_brightness(double mv)
{
// 100^(1/5)
static constexpr double fifth_root_100 = 2.5118864315095801110850320677993;
return std::pow(fifth_root_100, -mv);
}
double vmag_to_lux(double mv)
{
return std::pow(10.0, (-14.18 - mv) * 0.4);

+ 11
- 0
src/astro/illuminance.hpp View File

@ -22,6 +22,17 @@
namespace astro
{
/**
* Converts apparent (visual) magnitude to a brightness factor relative to a 0th magnitude star.
*
* @param mv Illuminance in apparent magnitude.
* @return Relative brightness factor.
*
* @see https://en.wikipedia.org/wiki/Illuminance
*/
double vmag_to_brightness(double mv);
/**
* Converts apparent (visual) magnitude to lux.

+ 31
- 5
src/game/state/nuptial-flight.cpp View File

@ -114,11 +114,6 @@ nuptial_flight::nuptial_flight(game::context& ctx):
// Setup camera
setup_camera();
/*
ctx.surface_camera->look_at({0, 0, 1}, {0, 0, 0}, {0, 1, 0});
ctx.surface_camera->set_exposure(-14.5f);
ctx.surface_scene->update_tweens();
*/
// Queue fade in
ctx.fade_transition_color->set_value({1, 1, 1});
@ -252,6 +247,7 @@ void nuptial_flight::enable_controls()
bool gamepad_invert_pan = false;
bool mouse_look_toggle = false;
ctx.mouse_look = false;
const double time_scale = 5000.0;
if (ctx.config->contains("mouse_tilt_sensitivity"))
mouse_tilt_sensitivity = math::radians((*ctx.config)["mouse_tilt_sensitivity"].get<float>());
@ -542,6 +538,36 @@ void nuptial_flight::enable_controls()
);
*/
// Fast-forward
ctx.controls["fast_forward"]->set_activated_callback
(
[&ctx = this->ctx, time_scale]()
{
game::world::set_time_scale(ctx, time_scale);
}
);
ctx.controls["fast_forward"]->set_deactivated_callback
(
[&ctx = this->ctx, time_scale]()
{
game::world::set_time_scale(ctx, 0.0);
}
);
ctx.controls["rewind"]->set_activated_callback
(
[&ctx = this->ctx, time_scale]()
{
game::world::set_time_scale(ctx, -time_scale);
}
);
ctx.controls["rewind"]->set_deactivated_callback
(
[&ctx = this->ctx, time_scale]()
{
game::world::set_time_scale(ctx, 0.0);
}
);
// Setup pause control
ctx.controls["pause"]->set_activated_callback
(

+ 6
- 8
src/game/world.cpp View File

@ -38,6 +38,7 @@
#include "gl/vertex-buffer.hpp"
#include "physics/light/photometry.hpp"
#include "physics/orbit/orbit.hpp"
#include "astro/illuminance.hpp"
#include "render/material.hpp"
#include "render/model.hpp"
#include "render/passes/shadow-map-pass.hpp"
@ -110,14 +111,11 @@ void create_stars(game::context& ctx)
// Transform XYZ color to ACEScg colorspace
double3 color_acescg = color::xyz::to_acescg(color_xyz);
// Convert apparent magnitude to irradiance (W/m^2)
double vmag_irradiance = std::pow(10.0, 0.4 * (-vmag - 19.0 + 0.4));
// Convert irradiance to illuminance
double vmag_illuminance = vmag_irradiance * (683.0 * 0.14);
// Convert apparent magnitude to brightness factor relative to a 0th magnitude star
double brightness = astro::vmag_to_brightness(vmag);
// Scale color by illuminance
double3 scaled_color = color_acescg * vmag_illuminance;
// Scale color by relative brightness
double3 scaled_color = color_acescg * brightness;
// Build vertex
*(star_vertex++) = static_cast<float>(position_inertial.x);
@ -126,7 +124,7 @@ void create_stars(game::context& ctx)
*(star_vertex++) = static_cast<float>(scaled_color.x);
*(star_vertex++) = static_cast<float>(scaled_color.y);
*(star_vertex++) = static_cast<float>(scaled_color.z);
*(star_vertex++) = static_cast<float>(vmag);
*(star_vertex++) = static_cast<float>(brightness);
}
// Unload star catalog

Loading…
Cancel
Save