From 39cd8e00495e1b63bf60d13818dc725a6c737dca Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Thu, 24 Sep 2020 22:14:30 -0700 Subject: [PATCH] Make sky gradients interpolate as time passes --- src/game/systems/weather-system.cpp | 21 +++++++++++++++++++-- src/game/systems/weather-system.hpp | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/game/systems/weather-system.cpp b/src/game/systems/weather-system.cpp index 1833d6d..69814d6 100644 --- a/src/game/systems/weather-system.cpp +++ b/src/game/systems/weather-system.cpp @@ -133,7 +133,20 @@ void weather_system::set_time_of_day(float t) if (sky_pass) { - sky_pass->set_sky_gradient(sky_gradient); + float hour = time_of_day / (60.0f * 60.0f); + std::size_t gradient_index = static_cast(hour); + + const std::array& gradient0 = sky_gradients[gradient_index]; + const std::array& gradient1 = sky_gradients[(gradient_index + 1) % sky_gradients.size()]; + float t = hour - std::floor(hour); + + std::array gradient; + for (int i = 0; i < 4; ++i) + { + gradient[i] = math::lerp(gradient0[i], gradient1[i], t); + } + + sky_pass->set_sky_gradient(gradient); } shadow_light = sun_light; @@ -160,6 +173,8 @@ void weather_system::set_sky_palette(const ::image* image) for (unsigned int x = 0; x < w; ++x) { + std::array gradient; + for (unsigned int y = 0; y < std::min(4, h); ++y) { unsigned int i = y * w * c + x * c; @@ -167,8 +182,10 @@ void weather_system::set_sky_palette(const ::image* image) float g = srgb_to_linear(static_cast(pixels[i + 1]) / 255.0f); float b = srgb_to_linear(static_cast(pixels[i + 2]) / 255.0f); - sky_gradient[y] = {r, g, b, static_cast(y) * (1.0f / 3.0f)}; + gradient[y] = {r, g, b, static_cast(y) * (1.0f / 3.0f)}; } + + sky_gradients.push_back(gradient); } } } diff --git a/src/game/systems/weather-system.hpp b/src/game/systems/weather-system.hpp index d49d4fc..718dcb3 100644 --- a/src/game/systems/weather-system.hpp +++ b/src/game/systems/weather-system.hpp @@ -65,7 +65,7 @@ private: material_pass* material_pass; const image* sky_palette; const image* shadow_palette; - std::array sky_gradient; + std::vector> sky_gradients; }; #endif // ANTKEEPER_WEATHER_SYSTEM_HPP