gKit2 light
indirect.glsl
1 #version 430
2 #extension GL_ARB_shader_draw_parameters : require
3 
4 #ifdef VERTEX_SHADER
5 
6 layout(location= 0) in vec3 position;
7 out vec3 vertex_position;
8 
9 uniform mat4 vpMatrix;
10 uniform mat4 viewMatrix;
11 
12 #if 1
13 layout(row_major) uniform modelBuffer
14 {
15  mat4 model[25];
16 };
17 #else
18 uniform mat4 model[25];
19 #endif
20 
21 void main( )
22 {
23  gl_Position= vpMatrix * model[gl_DrawIDARB] * vec4(position, 1);
24  vertex_position= vec3(viewMatrix * model[gl_DrawIDARB] * vec4(position, 1));
25 }
26 #endif
27 
28 
29 #ifdef FRAGMENT_SHADER
30 
31 in vec3 vertex_position;
32 
33 out vec4 fragment_color;
34 
35 void main( )
36 {
37  vec4 color= vec4(1, 0.8, 0, 1);
38  vec3 t= normalize(dFdx(vertex_position));
39  vec3 b= normalize(dFdy(vertex_position));
40  vec3 normal= normalize(cross(t, b));
41 
42  float cos_theta= abs(normal.z);
43  color= color * cos_theta;
44 
45  fragment_color= vec4(color.rgb, 1);
46 }
47 #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