gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
M2
instance.glsl
1
#version 330
2
3
#ifdef VERTEX_SHADER
4
5
layout(location= 0) in
vec3
position;
6
7
layout(location= 2) in
vec3
normal;
8
out
vec3
vertex_normal;
9
10
uniform mat4 mvpMatrix;
11
uniform mat4 normalMatrix;
12
13
void
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
28
in
vec3
vertex_normal;
29
30
out
vec4
fragment_color;
31
32
void
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
normalize
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition
vec.cpp:167
vec3
vecteur generique, utilitaire.
Definition
vec.h:169
vec4
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition
vec.h:192
Generated on
for gKit2 light by
1.17.0