From 5124e81348ecdc915dd7248c8b088353f2037ea2 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 22 Nov 2020 10:17:20 +0400 Subject: [PATCH] Use linear interpolation instead of abrupt transitions for groundcover lighting --- files/shaders/lighting.glsl | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/files/shaders/lighting.glsl b/files/shaders/lighting.glsl index 1b3ff288a..5eae89029 100644 --- a/files/shaders/lighting.glsl +++ b/files/shaders/lighting.glsl @@ -14,11 +14,20 @@ void perLight(out vec3 ambientOut, out vec3 diffuseOut, int lightIndex, vec3 vie lambert = max(lambert, 0.0); #else { - // might need to be < 0 depending on direction of viewPos - if (dot(viewPos, viewNormal.xyz) > 0) - lambert = -lambert; - if (lambert < 0) - lambert *= -0.3; + float cosine = dot(normalize(viewPos), normalize(viewNormal.xyz)); + if (lambert >= 0.0) + cosine = -cosine; + + float mult = 1.0; + float divisor = 8.0; + + if (cosine < 0.0 && cosine >= -1.0/divisor) + mult = mix(1.0, 0.3, -cosine*divisor); + else if (cosine < -1.0/divisor) + mult = 0.3; + + lambert *= mult; + lambert = abs(lambert); } #endif diffuseOut = gl_LightSource[lightIndex].diffuse.xyz * lambert;