aboutsummaryrefslogtreecommitdiff
path: root/client/shaders/object_shader/opengl_vertex.glsl
diff options
context:
space:
mode:
authorDmitry Kostenko <codeforsmile@gmail.com>2021-11-04 03:03:10 +0100
committerx2048 <codeforsmile@gmail.com>2022-03-07 23:45:26 +0100
commit54dccc480eb03adcf219a7add58f547284f40f76 (patch)
tree53ca69960e1d4bd2facc35368094106b49b56053 /client/shaders/object_shader/opengl_vertex.glsl
parentf2cccf8da72c39299c8e7ba6ad8f782a7d61b883 (diff)
downloadminetest-54dccc480eb03adcf219a7add58f547284f40f76.tar.gz
minetest-54dccc480eb03adcf219a7add58f547284f40f76.tar.bz2
minetest-54dccc480eb03adcf219a7add58f547284f40f76.zip
Improve lighting of entities.
Pass correct natural & artificial light to the shaders Use natural/artificial light ratio for correct rendering of shadows
Diffstat (limited to 'client/shaders/object_shader/opengl_vertex.glsl')
-rw-r--r--client/shaders/object_shader/opengl_vertex.glsl30
1 files changed, 24 insertions, 6 deletions
diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl
index 922fba62b..9ca5ef0f3 100644
--- a/client/shaders/object_shader/opengl_vertex.glsl
+++ b/client/shaders/object_shader/opengl_vertex.glsl
@@ -1,7 +1,9 @@
uniform mat4 mWorld;
-
+uniform vec3 dayLight;
uniform vec3 eyePosition;
uniform float animationTimer;
+uniform vec4 emissiveColor;
+
varying vec3 vNormal;
varying vec3 vPosition;
@@ -29,9 +31,9 @@ centroid varying vec2 varTexCoord;
varying vec3 eyeVec;
varying float nightRatio;
-
+// Color of the light emitted by the light sources.
+const vec3 artificialLight = vec3(1.04, 1.04, 1.04);
varying float vIDiff;
-
const float e = 2.718281828459;
const float BS = 10.0;
@@ -75,14 +77,30 @@ void main(void)
? 1.0
: directional_ambient(normalize(inVertexNormal));
#endif
- nightRatio = 0.0;
#ifdef GL_ES
- varColor = inVertexColor.bgra;
+ vec4 color = inVertexColor.bgra;
#else
- varColor = inVertexColor;
+ vec4 color = inVertexColor;
#endif
+ color *= emissiveColor;
+
+ // The alpha gives the ratio of sunlight in the incoming light.
+ nightRatio = 1.0 - color.a;
+ color.rgb = color.rgb * (color.a * dayLight.rgb +
+ nightRatio * artificialLight.rgb) * 2.0;
+ color.a = 1.0;
+
+ // Emphase blue a bit in darker places
+ // See C++ implementation in mapblock_mesh.cpp final_color_blend()
+ float brightness = (color.r + color.g + color.b) / 3.0;
+ color.b += max(0.0, 0.021 - abs(0.2 * brightness - 0.021) +
+ 0.07 * brightness);
+
+ varColor = clamp(color, 0.0, 1.0);
+
+
#ifdef ENABLE_DYNAMIC_SHADOWS
vec3 nNormal = normalize(vNormal);
cosLight = dot(nNormal, -v_LightDirection);