scg3  0.6
cube_map_gouraud_vert.glsl
Go to the documentation of this file.
1 /**
2  * \file cube_map_gouraud_vert.glsl
3  * \brief Cube map vertex shader with Gouraud shading,
4  * uses external function applyLighting().
5  */
6 
7 #version 150
8 
9 in vec4 vVertex;
10 in vec3 vNormal;
11 
12 uniform mat4 modelViewMatrix;
13 uniform mat4 mvpMatrix;
14 uniform mat3 normalMatrix;
15 uniform mat4 invViewMatrix;
16 
17 smooth out vec4 emissionAmbientDiffuse;
18 smooth out vec4 specular;
19 smooth out vec3 texCoord0;
20 
21 
22 // --- declarations ---
23 
24 
25 void applyLighting(const in vec3 ecVertex, const in vec3 ecNormal,
26  out vec4 emissionAmbientDiffuse, out vec4 specular);
27 
28 
29 // --- implementations ---
30 
31 
32 void main() {
33 
34  // transform vertex position and normal into eye coordinates
35  vec3 ecVertex = (modelViewMatrix * vVertex).xyz;
36  vec3 ecNormal = normalMatrix * vNormal;
37 
38  // apply lighting model (to be defined in separate shader)
39  applyLighting(ecVertex, ecNormal, emissionAmbientDiffuse, specular);
40 
41  // compute reflection for cube mapping
42  vec4 ecReflection = vec4(reflect(normalize(ecVertex), normalize(ecNormal)), 0.);
43 
44  // set output values
45  gl_Position = mvpMatrix * vVertex;
46  texCoord0 = (invViewMatrix * ecReflection).stp;
47 }