gKit2 light
Loading...
Searching...
No Matches
instance.glsl
1#version 330
2
3#ifdef VERTEX_SHADER
4
5layout(location= 0) in vec3 position;
6
7layout(location= 2) in vec3 normal;
8out vec3 vertex_normal;
9
10uniform mat4 mvpMatrix;
11uniform mat4 normalMatrix;
12
13void main( )
14{
15 // retrouve la position dans la grille 5x5 en fonction de l'identifiant de la copie / instance
16 float x= float(gl_InstanceID % 5) - 2;
17 float y= float(gl_InstanceID / 5) - 2;
18
19 // deplace le sommet pour le placer dans la grille
20 gl_Position= mvpMatrix * vec4(position + vec3(x * 20, y * 20, 0), 1);
21 vertex_normal= mat3(normalMatrix) * normal;
22}
23#endif
24
25
26#ifdef FRAGMENT_SHADER
27
28in vec3 vertex_normal;
29
30out vec4 fragment_color;
31
32void main( )
33{
34 vec3 normal= normalize(vertex_normal);
35 float cos_theta= abs(normal.z);
36 //~ vec3 color= vec3(1, 1, 1);
37 vec3 color= abs(normal);
38 color= color * cos_theta;
39
40 fragment_color= vec4(color, 1);
41}
42#endif
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition vec.cpp:167
vecteur generique, utilitaire.
Definition vec.h:169
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:192