summaryrefslogtreecommitdiff
path: root/game/environment.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2024-09-22 15:13:13 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2024-09-22 15:13:20 +0100
commitc5cf04a2c6c2e1c1315f1c6125c06ab1bbbdb045 (patch)
tree6f9c122e0abdb4949a3c102b2245d007969d6091 /game/environment.cpp
parentCalculate sunlight direction from worldTime (diff)
downloadilt-c5cf04a2c6c2e1c1315f1c6125c06ab1bbbdb045.tar.bz2
ilt-c5cf04a2c6c2e1c1315f1c6125c06ab1bbbdb045.tar.xz
ilt-c5cf04a2c6c2e1c1315f1c6125c06ab1bbbdb045.zip
Adjust light colour as sun rises/sets
This is a bit made-up-maths/numbers, but it looks reasonable.
Diffstat (limited to 'game/environment.cpp')
-rw-r--r--game/environment.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/game/environment.cpp b/game/environment.cpp
index 1ef9bcb..19aad84 100644
--- a/game/environment.cpp
+++ b/game/environment.cpp
@@ -13,10 +13,17 @@ Environment::tick(TickDuration)
void
Environment::render(const SceneRenderer & renderer, const SceneProvider & scene) const
{
+ constexpr RGB baseAmbient {0.1F}, baseDirectional {0.0F};
+ constexpr RGB relativeAmbient {0.3F, 0.3F, 0.4F}, relativeDirectional {0.6F, 0.6F, 0.5F};
+
const auto sunPos = getSunPos({}, worldTime);
const auto sunDir = (glm::mat3 {rotate_yp({sunPos.y + pi, sunPos.x})} * north);
- renderer.setAmbientLight({0.5F, 0.5F, 0.5F});
- renderer.setDirectionalLight({0.6F, 0.6F, 0.6F}, sunDir, scene);
+ const auto vertical = -std::min(0.F, sunDir.z - 0.1F);
+ const auto ambient = baseAmbient + relativeAmbient * vertical;
+ const auto directional = baseDirectional + relativeDirectional * vertical;
+
+ renderer.setAmbientLight(ambient);
+ renderer.setDirectionalLight(directional, sunDir, scene);
}
// Based on the C++ code published at https://www.psa.es/sdg/sunpos.htm