gKit2 light
tuto3GL_normals.glsl
1 
3 #version 330
4 
5 #ifdef VERTEX_SHADER
6 
7 uniform vec3 positions[36];
8 
9 uniform mat4 mvpMatrix;
10 uniform mat4 normalMatrix;
11 uniform float time;
12 
13 out vec3 vertex_normal;
14 void main( )
15 {
16  vec3 a= positions[gl_VertexID - gl_VertexID % 3];
17  vec3 b= positions[gl_VertexID - gl_VertexID % 3 +1];
18  vec3 c= positions[gl_VertexID - gl_VertexID % 3 +2];
19  vec3 ab= normalize(b - a);
20  vec3 ac= normalize(c - a);
21  vec3 n= cross(ab, ac);
22  vertex_normal= vec3(normalMatrix * vec4(n, 0));
23  gl_Position= mvpMatrix * vec4(positions[gl_VertexID], 1);
24 }
25 #endif
26 
27 
28 #ifdef FRAGMENT_SHADER
29 
30 in vec3 vertex_normal;
31 
32 out vec4 fragment_color;
33 
34 void main( )
35 {
36  float face_id= float(gl_PrimitiveID /2) / 5.0;
37  //~ vec3 color= vec3(face_id, 1 - face_id , 0);
38  vec3 color= abs(normalize(vertex_normal)).zzz;
39  // remplir le triangle avec une couleur uniforme
40  fragment_color= vec4(color, 1);
41  //~ fragment_color= vec4(abs(normalize(vertex_normal)), 1);
42 }
43 #endif
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition: vec.cpp:79
vecteur generique, utilitaire.
Definition: vec.h:104
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition: vec.h:121
Vector cross(const Vector &u, const Vector &v)
renvoie le produit vectoriel de 2 vecteurs.
Definition: vec.cpp:85