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