From 6958071f497c8f059429343339ad3818ed3cfed1 Mon Sep 17 00:00:00 2001 From: Danila Shutov Date: Sun, 16 Feb 2020 22:37:28 +0300 Subject: Basic model shading (#9374) --- client/shaders/object_shader/opengl_vertex.glsl | 44 +++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 client/shaders/object_shader/opengl_vertex.glsl (limited to 'client/shaders/object_shader/opengl_vertex.glsl') diff --git a/client/shaders/object_shader/opengl_vertex.glsl b/client/shaders/object_shader/opengl_vertex.glsl new file mode 100644 index 000000000..99b9b2709 --- /dev/null +++ b/client/shaders/object_shader/opengl_vertex.glsl @@ -0,0 +1,44 @@ +uniform mat4 mWorldViewProj; +uniform mat4 mWorld; + +uniform vec3 eyePosition; +uniform float animationTimer; + +varying vec3 vNormal; +varying vec3 vPosition; +varying vec3 worldPosition; + +varying vec3 eyeVec; +varying vec3 lightVec; +varying float vIDiff; + +const float e = 2.718281828459; +const float BS = 10.0; + +float directional_ambient(vec3 normal) +{ + vec3 v = normal * normal; + + if (normal.y < 0) + return dot(v, vec3(0.670820f, 0.447213f, 0.836660f)); + + return dot(v, vec3(0.670820f, 1.000000f, 0.836660f)); +} + +void main(void) +{ + gl_TexCoord[0] = gl_MultiTexCoord0; + gl_Position = mWorldViewProj * gl_Vertex; + + vPosition = gl_Position.xyz; + vNormal = gl_Normal; + worldPosition = (mWorld * gl_Vertex).xyz; + + vec3 sunPosition = vec3 (0.0, eyePosition.y * BS + 900.0, 0.0); + + lightVec = sunPosition - worldPosition; + eyeVec = -(gl_ModelViewMatrix * gl_Vertex).xyz; + vIDiff = directional_ambient(normalize(gl_Normal)); + + gl_FrontColor = gl_BackColor = gl_Color; +} -- cgit v1.2.3