fix weather interpolation & add 'fall.max_intensity' property

This commit is contained in:
MihailRis 2025-03-02 10:38:30 +03:00
parent 7fc226f70f
commit 8640730520
6 changed files with 40 additions and 10 deletions

View File

@ -13,11 +13,11 @@
"particles:rain_splash_2" "particles:rain_splash_2"
] ]
}, },
"min_opacity": 0.8 "min_opacity": 0.8,
"max_intensity": 0.5
}, },
"fog_opacity": 0.8, "fog_opacity": 0.5,
"fog_dencity": 2.0, "fog_dencity": 1.7,
"fog_curve": 0.5, "fog_curve": 0.5,
"clouds": 0.5, "clouds": 0.9
"thunder_rate": 0.1
} }

View File

@ -0,0 +1,23 @@
{
"fall": {
"vspeed": 2.0,
"texture": "misc/rain",
"noise": "ambient/rain",
"splash": {
"lifetime": 0.2,
"spawn_interval": 0.0,
"size": [0.2, 0.2, 0.2],
"frames": [
"particles:rain_splash_0",
"particles:rain_splash_1",
"particles:rain_splash_2"
]
},
"min_opacity": 0.8
},
"fog_opacity": 0.8,
"fog_dencity": 2.0,
"fog_curve": 0.5,
"clouds": 0.7,
"thunder_rate": 0.1
}

View File

@ -115,7 +115,8 @@ void Decorator::updateRandom(
return; return;
} }
} }
if (dst2 < 128 && random.randFloat() < glm::pow(weather.intensity, 2.0f) && rainSplash.has_value()) { float intensity = weather.intensity * weather.fall.maxIntensity;
if (dst2 < 128 && random.randFloat() < glm::pow(intensity, 2.0f) && rainSplash.has_value()) {
auto treg = util::get_texture_region( auto treg = util::get_texture_region(
assets, "particles:rain_splash_0", "" assets, "particles:rain_splash_0", ""
); );
@ -137,7 +138,7 @@ void Decorator::updateRandom(
sound, sound,
pos, pos,
false, false,
weather.intensity * weather.intensity, intensity * intensity,
1.0f, 1.0f,
false, false,
audio::PRIORITY_LOW, audio::PRIORITY_LOW,

View File

@ -203,9 +203,10 @@ void WorldRenderer::renderLevel(
std::array<const WeatherPreset*, 2> weatherInstances {&weather.a, &weather.b}; std::array<const WeatherPreset*, 2> weatherInstances {&weather.a, &weather.b};
for (const auto& weather : weatherInstances) { for (const auto& weather : weatherInstances) {
float maxIntensity = weather->fall.maxIntensity;
float zero = weather->fall.minOpacity; float zero = weather->fall.minOpacity;
float one = weather->fall.maxOpacity; float one = weather->fall.maxOpacity;
float t = (weather->intensity * (one - zero)) + zero; float t = (weather->intensity * (one - zero)) * maxIntensity + zero;
entityShader.uniform1i("u_alphaClip", weather->fall.opaque); entityShader.uniform1i("u_alphaClip", weather->fall.opaque);
entityShader.uniform1f("u_opacity", weather->fall.opaque ? t * t : t); entityShader.uniform1f("u_opacity", weather->fall.opaque ? t * t : t);
if (weather->intensity > 1.e-3f && !weather->fall.texture.empty()) { if (weather->intensity > 1.e-3f && !weather->fall.texture.empty()) {
@ -342,8 +343,10 @@ void WorldRenderer::draw(
const auto& settings = engine.getSettings(); const auto& settings = engine.getSettings();
const auto& worldInfo = world->getInfo(); const auto& worldInfo = world->getInfo();
float clouds = weather.b.clouds * glm::sqrt(weather.t) +
weather.a.clouds * glm::sqrt(1.0f - weather.t); float sqrtT = glm::sqrt(weather.t);
float clouds = weather.b.clouds * sqrtT +
weather.a.clouds * (1.0f - sqrtT);
clouds = glm::max(worldInfo.fog, clouds); clouds = glm::max(worldInfo.fog, clouds);
float mie = 1.0f + glm::max(worldInfo.fog, clouds * 0.5f) * 2.0f; float mie = 1.0f + glm::max(worldInfo.fog, clouds * 0.5f) * 2.0f;

View File

@ -13,6 +13,7 @@ dv::value WeatherPreset::serialize() const {
froot["noise"] = fall.noise; froot["noise"] = fall.noise;
froot["min_opacity"] = fall.minOpacity; froot["min_opacity"] = fall.minOpacity;
froot["max_opacity"] = fall.maxOpacity; froot["max_opacity"] = fall.maxOpacity;
froot["max_intensity"] = fall.maxIntensity;
froot["opaque"] = fall.opaque; froot["opaque"] = fall.opaque;
if (fall.splash) { if (fall.splash) {
froot["splash"] = fall.splash->serialize(); froot["splash"] = fall.splash->serialize();
@ -38,6 +39,7 @@ void WeatherPreset::deserialize(const dv::value& src) {
froot.at("noise").get(fall.noise); froot.at("noise").get(fall.noise);
froot.at("min_opacity").get(fall.minOpacity); froot.at("min_opacity").get(fall.minOpacity);
froot.at("max_opacity").get(fall.maxOpacity); froot.at("max_opacity").get(fall.maxOpacity);
froot.at("max_intensity").get(fall.maxIntensity);
froot.at("opaque").get(fall.opaque); froot.at("opaque").get(fall.opaque);
if (froot.has("splash")) { if (froot.has("splash")) {

View File

@ -22,6 +22,7 @@ struct WeatherPreset : Serializable {
/// @example if 0.8 then opacity range is 0.8-1.0 for 0.0-1.0 intensity /// @example if 0.8 then opacity range is 0.8-1.0 for 0.0-1.0 intensity
float minOpacity = 0.0f; float minOpacity = 0.0f;
float maxOpacity = 1.0f; float maxOpacity = 1.0f;
float maxIntensity = 1.0f;
/// @brief Clip texture by alpha channel /// @brief Clip texture by alpha channel
bool opaque = false; bool opaque = false;
/// @brief Fall splash /// @brief Fall splash