]> git.lizzy.rs Git - dragonfireclient.git/blob - client/shaders/object_shader/opengl_vertex.glsl
Fix broken coloring of wielditems (#9969)
[dragonfireclient.git] / client / shaders / object_shader / opengl_vertex.glsl
1 uniform mat4 mWorldViewProj;
2 uniform mat4 mWorld;
3
4 uniform vec3 eyePosition;
5 uniform float animationTimer;
6
7 varying vec3 vNormal;
8 varying vec3 vPosition;
9 varying vec3 worldPosition;
10
11 varying vec3 eyeVec;
12 varying vec3 lightVec;
13 varying float vIDiff;
14
15 const float e = 2.718281828459;
16 const float BS = 10.0;
17
18 float directional_ambient(vec3 normal)
19 {
20         vec3 v = normal * normal;
21
22         if (normal.y < 0)
23                 return dot(v, vec3(0.670820f, 0.447213f, 0.836660f));
24
25         return dot(v, vec3(0.670820f, 1.000000f, 0.836660f));
26 }
27
28 void main(void)
29 {
30         gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
31         gl_Position = mWorldViewProj * gl_Vertex;
32
33         vPosition = gl_Position.xyz;
34         vNormal = gl_Normal;
35         worldPosition = (mWorld * gl_Vertex).xyz;
36
37         vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0);
38
39         lightVec = sunPosition - worldPosition;
40         eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz;
41
42         // This is intentional comparison with zero without any margin.
43         // If normal is not equal to zero exactly, then we assume it's a valid, just not normalized vector
44         vIDiff = length(gl_Normal) == 0.0
45                 ? 1.0
46                 : directional_ambient(normalize(gl_Normal));
47
48         gl_FrontColor = gl_BackColor = gl_Color;
49 }