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
layout(location= 1) in
vec2
texcoord;
7
layout(location= 2) in
vec3
normal;
8
9
out
vec2
vertex_texcoord;
10
out
vec3
vertex_normal;
11
12
uniform mat4 mvpMatrix;
13
uniform mat4 normalMatrix;
14
15
void
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
31
in
vec2
vertex_texcoord;
32
in
vec3
vertex_normal;
33
34
uniform sampler2D diffuse;
35
36
out
vec4
fragment_color;
37
38
void
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
abs
Color abs(const Color &color)
renvoie la valeur absolue de chaque canal.
Definition
color.cpp:71
normalize
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition
vec.cpp:167
vec2
vecteur generique, utilitaire.
Definition
vec.h:152
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