weather change test
This commit is contained in:
@@ -101,16 +101,6 @@ WorldRenderer::WorldRenderer(
|
||||
settings.graphics.skyboxResolution.get(),
|
||||
assets->require<Shader>("skybox_gen")
|
||||
);
|
||||
|
||||
WeatherPreset weather = {};
|
||||
weather.deserialize(io::read_json("res:presets/weather/rain.json"));
|
||||
weather.intensity = 0.5f;
|
||||
weatherInstances.push_back(std::move(weather));
|
||||
|
||||
weather = {};
|
||||
weather.deserialize(io::read_json("res:presets/weather/snow.json"));
|
||||
weather.intensity = 0.5f;
|
||||
weatherInstances.push_back(std::move(weather));
|
||||
}
|
||||
|
||||
WorldRenderer::~WorldRenderer() = default;
|
||||
@@ -129,18 +119,9 @@ void WorldRenderer::setupWorldShader(
|
||||
shader.uniform1f("u_gamma", settings.graphics.gamma.get());
|
||||
shader.uniform1f("u_fogFactor", fogFactor);
|
||||
shader.uniform1f("u_fogCurve", settings.graphics.fogCurve.get());
|
||||
|
||||
float fog_opacity = 0.0f;
|
||||
float fog_dencity = 0.0f;
|
||||
float fog_curve = 0.0f;
|
||||
for (const auto& weather : weatherInstances) {
|
||||
fog_opacity += weather.fogOpacity * weather.intensity;
|
||||
fog_dencity += weather.fogDencity * weather.intensity;
|
||||
fog_curve += weather.fogCurve * weather.intensity;
|
||||
}
|
||||
shader.uniform1f("u_weatherFogOpacity", fog_opacity);
|
||||
shader.uniform1f("u_weatherFogDencity", fog_dencity);
|
||||
shader.uniform1f("u_weatherFogCurve", fog_curve);
|
||||
shader.uniform1f("u_weatherFogOpacity", weather.fogOpacity());
|
||||
shader.uniform1f("u_weatherFogDencity", weather.fogDencity());
|
||||
shader.uniform1f("u_weatherFogCurve", weather.fogCurve());
|
||||
shader.uniform1f("u_dayTime", level.getWorld()->getInfo().daytime);
|
||||
shader.uniform2f("u_lightDir", skybox->getLightDir());
|
||||
shader.uniform3f("u_cameraPos", camera.position);
|
||||
@@ -171,6 +152,24 @@ void WorldRenderer::renderLevel(
|
||||
bool pause,
|
||||
bool hudVisible
|
||||
) {
|
||||
weather.update(delta);
|
||||
|
||||
if (timer > 1.0f && weather.b.fall.texture.empty() && timer < 2.0f) {
|
||||
weather.b.deserialize(io::read_json("res:presets/weather/snow.json"));
|
||||
weather.t = 0.0f;
|
||||
weather.speed = 0.5f;
|
||||
weather.update(delta);
|
||||
}
|
||||
|
||||
if (timer > 15.0f && weather.a.fall.texture.empty()) {
|
||||
std::swap(weather.a, weather.b);
|
||||
weather.b = {};
|
||||
weather.b.deserialize(io::read_json("res:presets/weather/fog.json"));
|
||||
weather.t = 0.0f;
|
||||
weather.speed = 0.1f;
|
||||
weather.update(delta);
|
||||
}
|
||||
|
||||
texts->render(ctx, camera, settings, hudVisible, false);
|
||||
|
||||
bool culling = engine.getSettings().graphics.frustumCulling.get();
|
||||
@@ -217,13 +216,15 @@ void WorldRenderer::renderLevel(
|
||||
|
||||
setupWorldShader(entityShader, camera, settings, fogFactor);
|
||||
|
||||
std::array<WeatherPreset*, 2> weatherInstances {&weather.a, &weather.b};
|
||||
for (const auto& weather : weatherInstances) {
|
||||
float zero = weather.fall.minOpacity;
|
||||
float one = weather.fall.maxOpacity;
|
||||
entityShader.uniform1i("u_alphaClip", weather.fall.opaque);
|
||||
entityShader.uniform1f("u_opacity", (weather.intensity * (one - zero)) + zero);
|
||||
if (weather.intensity > 1.e-3f && !weather.fall.texture.empty()) {
|
||||
precipitation->render(camera, pause ? 0.0f : delta, weather);
|
||||
float zero = weather->fall.minOpacity;
|
||||
float one = weather->fall.maxOpacity;
|
||||
float t = (weather->intensity * (one - zero)) + zero;
|
||||
entityShader.uniform1i("u_alphaClip", weather->fall.opaque);
|
||||
entityShader.uniform1f("u_opacity", weather->fall.opaque ? t * t : t);
|
||||
if (weather->intensity > 1.e-3f && !weather->fall.texture.empty()) {
|
||||
precipitation->render(camera, pause ? 0.0f : delta, *weather);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,10 +356,8 @@ void WorldRenderer::draw(
|
||||
|
||||
const auto& settings = engine.getSettings();
|
||||
const auto& worldInfo = world->getInfo();
|
||||
float clouds = 0.0f;
|
||||
for (const auto& weather : weatherInstances) {
|
||||
clouds += weather.clouds * glm::sqrt(weather.intensity);
|
||||
}
|
||||
float clouds = weather.b.clouds * glm::sqrt(weather.t) +
|
||||
weather.a.clouds * glm::sqrt(1.0f - weather.t);
|
||||
clouds = glm::max(worldInfo.fog, clouds);
|
||||
float mie = 1.0f + glm::max(worldInfo.fog, clouds * 0.5f) * 2.0f;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user