improve bad weather clouds, fix clouds fog distance calculation

This commit is contained in:
Bixilon 2022-11-10 19:46:10 +01:00
parent 95b4ba3b4b
commit 8ad05049bb
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
4 changed files with 13 additions and 5 deletions

View File

@ -187,10 +187,13 @@ class CloudsRenderer(
}
}
private fun calculateRainColor(time: WorldTime, rain: Float): Vec3 {
private fun calculateRainColor(time: WorldTime, rain: Float, thunder: Float): Vec3 {
val normal = calculateNormal(time)
val brightness = normal.length()
return interpolateLinear(rain, normal, RAIN_COLOR) * brightness
var color = RAIN_COLOR
color = color * maxOf(1.0f - thunder, 0.4f)
return interpolateLinear(maxOf(rain, thunder), normal, color) * brightness * 0.8f
}
private fun calculateCloudsColor(): Vec3 {
@ -200,7 +203,7 @@ class CloudsRenderer(
}
val time = sky.time
if (weather.rain > 0.0f || weather.thunder > 0.0f) {
return calculateRainColor(time, maxOf(weather.rain, weather.thunder))
return calculateRainColor(time, weather.rain, weather.thunder)
}
return calculateNormal(time)
}

View File

@ -21,6 +21,10 @@ uniform float uFogDistance = 15.0f * 15.0f;
uniform vec4 uFogColor;
uniform bool uUseFogColor = false;
#ifndef DISTANCE_MULTIPLIER
#define DISTANCE_MULTIPLIER 1.0f
#endif
float calulate_fog_alpha(float distance2) {
if (distance2 < uFogStart) {
return 1.0f;
@ -43,7 +47,7 @@ float calculate_fog() {
vec2 distance_vec2 = finFragmentPosition.xz - uCameraPosition.xz;
float distance = dot(distance_vec2, distance_vec2);
#endif
return calulate_fog_alpha(distance);
return calulate_fog_alpha(distance * DISTANCE_MULTIPLIER);
}
void set_fog() {

View File

@ -20,6 +20,7 @@ uniform vec4 uCloudsColor;
flat in float finBrightness;
#define DISTANCE_MULTIPLIER 0.3f
#include "minosoft:fog"
void main() {

View File

@ -33,7 +33,7 @@ void main() {
gl_Position = uViewProjectionMatrix * vec4(position, 1.0);
finFragmentPosition = position / 3;
finFragmentPosition = position;
switch (vinSide) {
case 0u: finBrightness = 0.7f; break; // DOWN