2 * \file simple_flat_vert.glsl
3 * \brief Minimal lighting vertex shader, using a single point light and Gouraud shading.
11 uniform mat4 modelViewMatrix;
12 uniform mat4 projectionMatrix;
13 uniform mat4 mvpMatrix;
14 uniform mat3 normalMatrix;
16 const int MAX_NUMBER_OF_LIGHTS = 10;
23 vec4 halfVector; // used as vec3, expected as normalized
24 vec4 spotDirection; // used as vec3, expected as normalized
29 layout(std140) uniform LightBlock {
30 Light lights[MAX_NUMBER_OF_LIGHTS];
41 layout(std140) uniform MaterialBlock {
46 uniform vec4 globalAmbientLight;
51 // --- declarations ---
54 void applyLighting(const in vec3 ecVertex, const in vec3 ecNormal, out vec4 color);
57 // --- implementations ---
62 // transform vertex position and normal into eye coordinates
63 vec3 ecVertex = (modelViewMatrix * vVertex).xyz;
64 vec3 ecNormal = normalMatrix * vNormal;
66 // apply lighting model
67 applyLighting(ecVertex, ecNormal, color);
70 gl_Position = mvpMatrix * vVertex;
74 void applyLighting(const in vec3 ecVertex, const in vec3 ecNormal, out vec4 color) {
76 // normalized view direction and surface normal
77 vec3 v = normalize(-ecVertex);
78 vec3 n = normalize(ecNormal);
80 // normalized light source direction and half vector
81 vec3 s = normalize(lights[0].position.xyz - ecVertex);
82 vec3 h = normalize(v + s);
84 // emission and global ambient
85 color = material.emission + material.ambient * globalAmbientLight;
89 color += material.ambient * lights[0].ambient;
92 float sDotN = max(0., dot(s, n));
93 color += material.diffuse * lights[0].diffuse * sDotN;
96 float hDotN = dot(h, n);
98 color += material.specular * lights[0].specular * pow(hDotN, material.shininess);