gKit2 light
texcoords.glsl
1 
2 #version 330
3 
4 #ifdef VERTEX_SHADER
5 layout(location= 0) in vec3 position;
6 layout(location= 1) in vec2 texcoord;
7 layout(location= 2) in vec3 normal;
8 
9 uniform mat4 mvpMatrix;
10 uniform mat4 mvMatrix;
11 uniform mat4 normalMatrix;
12 
13 out vec3 vertex_position;
14 out vec2 vertex_texcoord;
15 out vec3 vertex_normal;
16 
17 void main( )
18 {
19  gl_Position= mvpMatrix * vec4(position, 1);
20  vertex_position= vec3(mvMatrix * vec4(position, 1));
21  vertex_texcoord= texcoord;
22  vertex_normal= mat3(normalMatrix) * normal; // uniquement une rotation, mat3 suffit
23 
24 }
25 #endif
26 
27 #ifdef FRAGMENT_SHADER
28 uniform sampler2D color_texture;
29 
30 in vec3 vertex_position;
31 in vec2 vertex_texcoord;
32 in vec3 vertex_normal;
33 
34 out vec4 fragment_color;
35 
36 void main( )
37 {
38  // place la source de lumiere sur la camera, repere camera, position 0, 0, 0
39  float cos_theta= dot( normalize(vertex_normal), normalize(-vertex_position));
40  //~ vec4 color= textureLod(color_texture, vertex_texcoord, 0);
41  vec4 color= texture(color_texture, vertex_texcoord);
42  fragment_color= cos_theta * color;
43 }
44 #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, utilitaire.
Definition: vec.h:94
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition: vec.h:121
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
Definition: vec.cpp:93