gKit2 light
decal.glsl
Go to the documentation of this file.
1 
3 
4 #version 330
5 
6 #ifdef VERTEX_SHADER
7 layout(location= 0) in vec3 position;
8 layout(location= 2) in vec3 normal;
9 
10 uniform mat4 mvpMatrix;
11 uniform mat4 mvMatrix;
12 uniform mat4 decalMatrix;
13 
14 out vec4 decal_position;
15 
16 out vec3 vertex_position;
17 out vec3 vertex_normal;
18 
19 void main( )
20 {
21  gl_Position= mvpMatrix * vec4(position, 1);
22  decal_position= decalMatrix * vec4(position, 1);
23 
24  vertex_position= vec3(mvMatrix * vec4(position, 1));
25  vertex_normal= mat3(mvMatrix) * normal;
26 }
27 #endif
28 
29 #ifdef FRAGMENT_SHADER
30 out vec4 fragment_color;
31 
32 uniform sampler2D decal;
33 in vec4 decal_position;
34 
35 in vec3 vertex_position;
36 in vec3 vertex_normal;
37 
38 void main( )
39 {
40  vec3 l= normalize(-vertex_position); // la camera est la source de lumiere.
41  vec3 n= normalize(vertex_normal);
42  float cos_theta= max(0, dot(n, l));
43  vec3 color= vec3(0.8) * cos_theta;
44 
45  //~ vec3 texcoord= decal_position.xyz / decal_position.w;
46  //~ vec3 decal_color= texture(decal, texcoord.xy).rgb;
47  //~ if(texcoord.x < 0 || texcoord.x > 1)
48  //~ color.g= 1;
49  //~ if(texcoord.y < 0 || texcoord.y > 1)
50  //~ color.r= 1;
51  //~ if(texcoord.z < 0 || texcoord.z > 1)
52  //~ color.b= 1;
53 
54  //~ if((texcoord.x < 0 || texcoord.x > 1)
55  //~ || (texcoord.y < 0 || texcoord.y > 1)
56  //~ || (texcoord.z < 0 || texcoord.z > 1))
57  //~ decal_color= vec3(1);
58 
59  //~ float decal_z= decal_position.z / decal_position.w;
60  //~ if(decal_z < 0 || decal_z > 1)
61  //~ color.r= 1;
62  //~ else
63  //~ color= color * textureProj(decal, decal_position).rgb;
64 
65  vec3 decal_color= textureProj(decal, decal_position).rgb;
66 
67  fragment_color= vec4(color * decal_color, 1);
68 }
69 #endif
Point max(const Point &a, const Point &b)
renvoie la plus grande composante de chaque point. x, y, z= max(a.x, b.x), max(a.y,...
Definition: vec.cpp:35
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
Definition: vec.cpp:137
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition: vec.cpp:123
vecteur generique, utilitaire.
Definition: vec.h:146
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition: vec.h:168