gKit2 light
tuto4GL_normals.glsl
1 
2 #version 330
3 
4 #ifdef VERTEX_SHADER
5 in vec3 position;
6 in vec3 normal;
7 
8 uniform mat4 mvpMatrix;
9 uniform mat4 mvMatrix;
10 
11 // normal est un attribut du vertex shader, il n'est pas disponible dans le fragment shader, donc :
12 out vec3 view_normal;
13 // il faut declarer un varying, un resultat du vertex shader
14 
15 void main( )
16 {
17  gl_Position= mvpMatrix * vec4(position, 1);
18  view_normal= mat3(mvMatrix) * normal; // uniquement une rotation, mat3 suffit
19 
20 }
21 #endif
22 
23 #ifdef FRAGMENT_SHADER
24 uniform vec3 color;
25 
26 // recupere la normale calculee par le vertex shader, meme type, meme nom, mais in au lieu de out
27 in vec3 view_normal;
28 // rappel: interpolation en fonction de la position du fragment dans le triangle
29 
30 out vec4 fragment_color;
31 
32 void main( )
33 {
34  fragment_color= vec4(color * abs(view_normal.z), 1);
35 }
36 #endif
vecteur generique, utilitaire.
Definition: vec.h:104
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition: vec.h:121