add weather intensity (WIP)
This commit is contained in:
parent
830e05733f
commit
fe503d1192
@ -15,6 +15,7 @@ uniform mat4 u_proj;
|
|||||||
uniform mat4 u_view;
|
uniform mat4 u_view;
|
||||||
uniform vec3 u_cameraPos;
|
uniform vec3 u_cameraPos;
|
||||||
uniform float u_gamma;
|
uniform float u_gamma;
|
||||||
|
uniform float u_opacity;
|
||||||
uniform samplerCube u_cubemap;
|
uniform samplerCube u_cubemap;
|
||||||
|
|
||||||
uniform vec3 u_torchlightColor;
|
uniform vec3 u_torchlightColor;
|
||||||
@ -36,6 +37,7 @@ void main() {
|
|||||||
a_dir = modelpos.xyz - u_cameraPos;
|
a_dir = modelpos.xyz - u_cameraPos;
|
||||||
vec3 skyLightColor = pick_sky_color(u_cubemap);
|
vec3 skyLightColor = pick_sky_color(u_cubemap);
|
||||||
a_color.rgb = max(a_color.rgb, skyLightColor.rgb*decomp_light.a) * v_color;
|
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));
|
a_distance = length(u_view * u_model * vec4(pos3d * FOG_POS_SCALE, 0.0));
|
||||||
gl_Position = u_proj * u_view * modelpos;
|
gl_Position = u_proj * u_view * modelpos;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -115,7 +115,7 @@ void Decorator::updateRandom(
|
|||||||
return;
|
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(
|
auto treg = util::get_texture_region(
|
||||||
assets, "particles:rain_splash_0", ""
|
assets, "particles:rain_splash_0", ""
|
||||||
);
|
);
|
||||||
@ -131,13 +131,13 @@ void Decorator::updateRandom(
|
|||||||
2
|
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);
|
auto sound = assets.get<audio::Sound>(weather.fall.noise);
|
||||||
audio::play(
|
audio::play(
|
||||||
sound,
|
sound,
|
||||||
pos,
|
pos,
|
||||||
false,
|
false,
|
||||||
1.0f,
|
weather.intensity * weather.intensity,
|
||||||
1.0f,
|
1.0f,
|
||||||
false,
|
false,
|
||||||
audio::PRIORITY_LOW,
|
audio::PRIORITY_LOW,
|
||||||
|
|||||||
@ -136,8 +136,8 @@ void WorldRenderer::setupWorldShader(
|
|||||||
shader.uniform1f("u_gamma", settings.graphics.gamma.get());
|
shader.uniform1f("u_gamma", settings.graphics.gamma.get());
|
||||||
shader.uniform1f("u_fogFactor", fogFactor);
|
shader.uniform1f("u_fogFactor", fogFactor);
|
||||||
shader.uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
|
shader.uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
|
||||||
shader.uniform1f("u_weatherFogOpacity", 0.8f);
|
shader.uniform1f("u_weatherFogOpacity", weather.fogOpacity * weather.intensity);
|
||||||
shader.uniform1f("u_weatherFogDencity", 2.0f);
|
shader.uniform1f("u_weatherFogDencity", weather.fogDencity);
|
||||||
shader.uniform1f("u_dayTime", level.getWorld()->getInfo().daytime);
|
shader.uniform1f("u_dayTime", level.getWorld()->getInfo().daytime);
|
||||||
shader.uniform2f("u_lightDir", skybox->getLightDir());
|
shader.uniform2f("u_lightDir", skybox->getLightDir());
|
||||||
shader.uniform3f("u_cameraPos", camera.position);
|
shader.uniform3f("u_cameraPos", camera.position);
|
||||||
@ -183,6 +183,7 @@ void WorldRenderer::renderLevel(
|
|||||||
}
|
}
|
||||||
|
|
||||||
entityShader.uniform1i("u_alphaClip", true);
|
entityShader.uniform1i("u_alphaClip", true);
|
||||||
|
entityShader.uniform1f("u_opacity", 1.0f);
|
||||||
level.entities->render(
|
level.entities->render(
|
||||||
assets,
|
assets,
|
||||||
*modelBatch,
|
*modelBatch,
|
||||||
@ -213,7 +214,10 @@ void WorldRenderer::renderLevel(
|
|||||||
|
|
||||||
setupWorldShader(entityShader, camera, settings, fogFactor);
|
setupWorldShader(entityShader, camera, settings, fogFactor);
|
||||||
entityShader.uniform1i("u_alphaClip", false);
|
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);
|
precipitation->render(camera, pause ? 0.0f : delta, weather);
|
||||||
|
weather.intensity = -glm::cos(timer * 0.2f) * 0.5f + 0.5f;
|
||||||
|
|
||||||
skybox->unbind();
|
skybox->unbind();
|
||||||
}
|
}
|
||||||
@ -344,7 +348,13 @@ void WorldRenderer::draw(
|
|||||||
const auto& settings = engine.getSettings();
|
const auto& settings = engine.getSettings();
|
||||||
const auto& worldInfo = world->getInfo();
|
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();
|
const auto& assets = *engine.getAssets();
|
||||||
auto& linesShader = assets.require<Shader>("lines");
|
auto& linesShader = assets.require<Shader>("lines");
|
||||||
|
|||||||
@ -12,6 +12,9 @@ dv::value WeatherPreset::serialize() const {
|
|||||||
froot["scale"] = fall.scale;
|
froot["scale"] = fall.scale;
|
||||||
froot["noise"] = fall.noise;
|
froot["noise"] = fall.noise;
|
||||||
root["fall"] = froot;
|
root["fall"] = froot;
|
||||||
|
root["fog_opacity"] = fogOpacity;
|
||||||
|
root["fog_dencity"] = fogDencity;
|
||||||
|
root["clouds"] = clouds;
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
@ -24,5 +27,8 @@ void WeatherPreset::deserialize(const dv::value& src) {
|
|||||||
froot.at("hspeed").get(fall.hspeed);
|
froot.at("hspeed").get(fall.hspeed);
|
||||||
froot.at("scale").get(fall.scale);
|
froot.at("scale").get(fall.scale);
|
||||||
froot.at("noise").get(fall.noise);
|
froot.at("noise").get(fall.noise);
|
||||||
|
src.at("fog_opacity").get(fogOpacity);
|
||||||
|
src.at("fog_dencity").get(fogDencity);
|
||||||
|
src.at("clouds").get(clouds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,10 +18,24 @@ struct WeatherPreset : Serializable {
|
|||||||
float hspeed = 0.1f;
|
float hspeed = 0.1f;
|
||||||
/// @brief UV scaling
|
/// @brief UV scaling
|
||||||
float scale = 0.1f;
|
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
|
/// @brief Fall splash
|
||||||
std::optional<ParticlesPreset> splash;
|
std::optional<ParticlesPreset> splash;
|
||||||
} fall {};
|
} 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;
|
dv::value serialize() const override;
|
||||||
void deserialize(const dv::value& src) override;
|
void deserialize(const dv::value& src) override;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user