Files
Vibe-HD-2D/engine/include/hd2d/Weather.h
Gabrieal Jimmy 2c99305fb0 init
2026-10-02 12:42:00 -05:00

55 lines
1.9 KiB
C++

#pragma once
#include "hd2d/Scene.h"
#include <glm/glm.hpp>
#include <random>
namespace hd2d {
struct RenderSettings;
// Everything the weather changes about the look, so it can be blended.
struct WeatherLook {
float sunIntensity = 0.0f;
glm::vec3 sunColor{1.0f};
glm::vec3 zenith{0.5f}, horizon{0.5f}, ground{0.2f};
float ambient = 0.5f;
glm::vec3 fogColor{0.5f};
float fogDensity = 0.0f, fogHeightFalloff = 0.1f, godRays = 0.0f, shaftStrength = 0.0f, cookieStrength = 0.0f;
float windStrength = 0.0f, windGustSpeed = 0.0f;
float bloomStrength = 0.0f, saturation = 1.0f;
};
// Blends the scene from its clear-weather look (captured from the current
// scene + settings while it is not raining, so manual tuning is kept) toward
// a storm preset, and drives rain intensity, wetness, ground splashes and the
// fading of ambient particles.
class Weather {
public:
Weather();
void setRain(float target) { targetRain_ = glm::clamp(target, 0.0f, 1.0f); }
float targetRain() const { return targetRain_; }
float rain() const { return rain_; }
// Jumps straight to the target (no transition), e.g. for screenshots.
void snap() { rain_ = targetRain_; wetness_ = targetRain_; }
void update(float dt, Scene& scene, RenderSettings& settings);
WeatherLook storm; // look at full rain intensity
float transitionSeconds = 5.0f; // clear <-> storm fade time
float splashesPerSecond = 500.0f;
float splashRadius = 12.0f; // around Scene::focusPoint
private:
static WeatherLook capture(const Scene& scene, const RenderSettings& settings);
static void apply(const WeatherLook& look, Scene& scene, RenderSettings& settings);
WeatherLook clear_;
bool haveClear_ = false;
float rain_ = 0.0f, targetRain_ = 0.0f, wetness_ = 0.0f, splashAccum_ = 0.0f;
std::mt19937 rng_{99};
};
} // namespace hd2d