add weather intensity (WIP)

This commit is contained in:
MihailRis 2025-02-11 15:51:19 +03:00
parent 830e05733f
commit fe503d1192
5 changed files with 38 additions and 6 deletions

View File

@ -15,6 +15,7 @@ uniform mat4 u_proj;
uniform mat4 u_view;
uniform vec3 u_cameraPos;
uniform float u_gamma;
uniform float u_opacity;
uniform samplerCube u_cubemap;
uniform vec3 u_torchlightColor;
@ -36,6 +37,7 @@ void main() {
a_dir = modelpos.xyz - u_cameraPos;
vec3 skyLightColor = pick_sky_color(u_cubemap);
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_light.a) * v_color;
a_color.a = u_opacity;
a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
gl_Position = u_proj * u_view * modelpos;
}

View File

@ -115,7 +115,7 @@ void Decorator::updateRandom(
return;
}
}
if (dst2 < 128 && rainSplash.has_value()) {
if (dst2 < 128 && random.randFloat() < glm::pow(weather.intensity, 2.0f) && rainSplash.has_value()) {
auto treg = util::get_texture_region(
assets, "particles:rain_splash_0", ""
);
@ -131,13 +131,13 @@ void Decorator::updateRandom(
2
));
}
if (random.rand() % 200 < 2 && pos.y < areaCenter.y + 1) {
if (random.rand() % 200 < 3 && pos.y < areaCenter.y + 1) {
auto sound = assets.get<audio::Sound>(weather.fall.noise);
audio::play(
sound,
pos,
false,
1.0f,
weather.intensity * weather.intensity,
1.0f,
false,
audio::PRIORITY_LOW,

View File

@ -136,8 +136,8 @@ void WorldRenderer::setupWorldShader(
shader.uniform1f("u_gamma", settings.graphics.gamma.get());
shader.uniform1f("u_fogFactor", fogFactor);
shader.uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
shader.uniform1f("u_weatherFogOpacity", 0.8f);
shader.uniform1f("u_weatherFogDencity", 2.0f);
shader.uniform1f("u_weatherFogOpacity", weather.fogOpacity * weather.intensity);
shader.uniform1f("u_weatherFogDencity", weather.fogDencity);
shader.uniform1f("u_dayTime", level.getWorld()->getInfo().daytime);
shader.uniform2f("u_lightDir", skybox->getLightDir());
shader.uniform3f("u_cameraPos", camera.position);
@ -183,6 +183,7 @@ void WorldRenderer::renderLevel(
}
entityShader.uniform1i("u_alphaClip", true);
entityShader.uniform1f("u_opacity", 1.0f);
level.entities->render(
assets,
*modelBatch,
@ -213,7 +214,10 @@ void WorldRenderer::renderLevel(
setupWorldShader(entityShader, camera, settings, fogFactor);
entityShader.uniform1i("u_alphaClip", false);
float zero = weather.fall.minOpacity;
entityShader.uniform1f("u_opacity", (weather.intensity * (1.0f - zero)) + zero);
precipitation->render(camera, pause ? 0.0f : delta, weather);
weather.intensity = -glm::cos(timer * 0.2f) * 0.5f + 0.5f;
skybox->unbind();
}
@ -344,7 +348,13 @@ void WorldRenderer::draw(
const auto& settings = engine.getSettings();
const auto& worldInfo = world->getInfo();
skybox->refresh(pctx, worldInfo.daytime, 1.0f + worldInfo.fog * 2.0f, 4);
skybox->refresh(
pctx,
worldInfo.daytime,
1.0f +
glm::max(worldInfo.fog, weather.clouds * glm::sqrt(weather.intensity) * 0.5f) * 2.0f,
4
);
const auto& assets = *engine.getAssets();
auto& linesShader = assets.require<Shader>("lines");

View File

@ -12,6 +12,9 @@ dv::value WeatherPreset::serialize() const {
froot["scale"] = fall.scale;
froot["noise"] = fall.noise;
root["fall"] = froot;
root["fog_opacity"] = fogOpacity;
root["fog_dencity"] = fogDencity;
root["clouds"] = clouds;
return root;
}
@ -24,5 +27,8 @@ void WeatherPreset::deserialize(const dv::value& src) {
froot.at("hspeed").get(fall.hspeed);
froot.at("scale").get(fall.scale);
froot.at("noise").get(fall.noise);
src.at("fog_opacity").get(fogOpacity);
src.at("fog_dencity").get(fogDencity);
src.at("clouds").get(clouds);
}
}

View File

@ -18,10 +18,24 @@ struct WeatherPreset : Serializable {
float hspeed = 0.1f;
/// @brief UV scaling
float scale = 0.1f;
/// @brief Fall opacity interpreted as zero.
/// @example if 0.8 then opacity range is 0.8-1.0 for 0.0-1.0 intensity
float minOpacity = 0.8f;
/// @brief Fall splash
std::optional<ParticlesPreset> splash;
} fall {};
/// @brief Max weather fog opacity
float fogOpacity = 0.8f;
/// @brief Weather fog depth multiplier
float fogDencity = 2.0f;
float clouds = 0.5f;
/// @brief Weather effects intensity
float intensity = 0.9f;
dv::value serialize() const override;
void deserialize(const dv::value& src) override;
};