1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Minor changes

This commit is contained in:
Gefüllte Taubenbrust 2024-08-18 16:11:30 +02:00
parent e6752008e0
commit e5afca89f7
8 changed files with 50 additions and 2 deletions

View file

@ -1,5 +1,6 @@
uniform sampler2D baseTexture;
varying vec3 sunTint;
uniform vec3 dayLight;
uniform lowp vec4 fogColor;
uniform float fogDistance;
@ -431,7 +432,7 @@ void main(void)
// calculate fragment color from components:
col.rgb =
adjusted_night_ratio * col.rgb + // artificial light
(1.0 - adjusted_night_ratio) * ( // natural light
sunTint * (1.0 - adjusted_night_ratio) * ( // natural light
col.rgb * (1.0 - shadow_int * (1.0 - shadow_color)) + // filtered texture color
dayLight * shadow_color * shadow_int); // reflected filtered sunlight/moonlight
}

View file

@ -32,6 +32,7 @@ centroid varying vec2 varTexCoord;
varying highp vec3 eyeVec;
varying float nightRatio;
varying vec3 sunTint;
// Color of the light emitted by the light sources.
uniform vec3 artificialLight;
varying float vIDiff;
@ -89,6 +90,20 @@ float directional_ambient(vec3 normal)
return dot(v, vec3(0.670820, 1.000000, 0.836660));
}
vec3 getDirectLightScatteringAtGround(vec3 v_LightDirection)
{
// Based on talk at 2002 Game Developers Conference by Naty Hoffman and Arcot J. Preetham
const float beta_r0 = 1e-5; // Rayleigh scattering beta
// These factors are calculated based on expected value of scattering factor of 1e-5
// for Nitrogen at 532nm (green), 2e25 molecules/m3 in atmosphere
const vec3 beta_r0_l = vec3(3.3362176e-01, 8.75378289198826e-01, 1.95342379700656) * beta_r0; // wavelength-dependent scattering
const float atmosphere_height = 15000.; // height of the atmosphere in meters
// sun/moon light at the ground level, after going through the atmosphere
return exp(-beta_r0_l * atmosphere_height / (1e-5 - dot(v_LightDirection, vec3(0., 1., 0.))));
}
void main(void)
{
varTexCoord = (mTexture * inTexCoord0).st;
@ -162,6 +177,7 @@ void main(void)
shadow_position.z -= z_bias;
perspective_factor = pFactor;
sunTint = vec3(1.0);
if (f_timeofday < 0.21) {
adj_shadow_strength = f_shadow_strength * 0.5 *
(1.0 - mtsmoothstep(0.18, 0.21, f_timeofday));
@ -172,6 +188,7 @@ void main(void)
adj_shadow_strength = f_shadow_strength *
mtsmoothstep(0.21, 0.26, f_timeofday) *
(1.0 - mtsmoothstep(0.743, 0.793, f_timeofday));
sunTint = mix(vec3(1.0), getDirectLightScatteringAtGround(v_LightDirection), min(1.0, 4.0 * adj_shadow_strength));
}
}
#endif