summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
Diffstat (limited to 'gfx')
-rw-r--r--gfx/lightDirection.cpp19
-rw-r--r--gfx/lightDirection.h7
2 files changed, 23 insertions, 3 deletions
diff --git a/gfx/lightDirection.cpp b/gfx/lightDirection.cpp
index 3932872..5198bdf 100644
--- a/gfx/lightDirection.cpp
+++ b/gfx/lightDirection.cpp
@@ -1,12 +1,25 @@
#include "lightDirection.h"
#include "maths.h"
-constexpr auto ASTRONOMICAL_TWILIGHT = 18.0_degrees;
+constexpr auto TWILIGHT_START = .0_degrees;
+constexpr auto TWILIGHT_END = -18.0_degrees;
+constexpr auto TWILIGHT_RANGE = TWILIGHT_START - TWILIGHT_END;
+
constexpr auto SUN_ANGLUAR_SIZE = 0.5_degrees;
+constexpr auto SUN_ANGLUAR_RADIUS = SUN_ANGLUAR_SIZE / 2;
+constexpr auto SUN_ELEVATION_REFRACTION_OFFSET = 0.5_degrees;
+constexpr auto SUN_ANGLUAR_OFFSET = SUN_ANGLUAR_RADIUS + SUN_ELEVATION_REFRACTION_OFFSET;
+
+constexpr auto ATMOSPHERE_SCATTER_MIN = .4F;
+constexpr auto ATMOSPHERE_SCATTER_MAX = .7F;
+constexpr auto ATMOSPHERE_SCATTER_RANGE = ATMOSPHERE_SCATTER_MAX - ATMOSPHERE_SCATTER_MIN;
+
+constexpr auto NORM = 0.5F;
LightDirection::LightDirection(const Direction2D sunPos) :
pos {sunPos}, vec {glm::mat3 {rotate_yp(pi + sunPos.x, -sunPos.y)} * north},
- amb {glm::clamp(sunPos.y + ASTRONOMICAL_TWILIGHT, 0.F, 1.F)},
- dir {glm::clamp(sunPos.y + SUN_ANGLUAR_SIZE, 0.F, 1.F)}
+ amb {glm::clamp((sunPos.y - TWILIGHT_END) / TWILIGHT_RANGE, 0.F, 1.F)},
+ dir {(-std::cos(std::clamp((sunPos.y + SUN_ANGLUAR_OFFSET) / SUN_ANGLUAR_SIZE, 0.F, 1.F) * pi) * NORM) + NORM},
+ atmosScatter {((half_pi - sunPos.y) / half_pi * ATMOSPHERE_SCATTER_RANGE) + ATMOSPHERE_SCATTER_MIN}
{
}
diff --git a/gfx/lightDirection.h b/gfx/lightDirection.h
index 789830b..296f497 100644
--- a/gfx/lightDirection.h
+++ b/gfx/lightDirection.h
@@ -31,9 +31,16 @@ public:
return dir;
}
+ [[nodiscard]] float
+ atmosphericScattering() const noexcept
+ {
+ return atmosScatter;
+ }
+
private:
Direction2D pos;
Direction3D vec;
float amb;
float dir;
+ float atmosScatter;
};