gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
tuto9_groups.glsl
Go to the documentation of this file.
1
2
3
#version 330
4
5
#ifdef VERTEX_SHADER
6
layout(location= 0) in
vec3
position;
7
layout(location= 2) in
vec3
normal;
8
9
uniform mat4 mvpMatrix;
10
uniform mat4 mvMatrix;
11
12
out
vec3
vertex_normal;
13
14
void
main( )
15
{
16
gl_Position= mvpMatrix *
vec4
(position, 1);
17
18
// normale dans le repere camera
19
vertex_normal= mat3(mvMatrix) * normal;
20
}
21
22
#endif
23
24
25
#ifdef FRAGMENT_SHADER
26
in
vec3
vertex_normal;
27
28
uniform
vec4
color;
29
30
out
vec4
fragment_color;
31
void
main( )
32
{
33
vec3
l=
normalize
(
vec3
(0.5, 0.25, 0) );
// todo : passer en parametre...
34
vec3
n=
normalize
(vertex_normal);
35
float
cos_theta=
max
(0,
dot
(n, l));
36
37
// terme ambiant
38
float
ambient=
max
(0,
dot
( n,
vec3
(0, 1, 0) ));
39
vec4
ambient_color= color * (1 + ambient) / 2;
40
41
fragment_color= 0.2 * ambient_color + color * cos_theta;
42
}
43
44
#endif
max
Point max(const Point &a, const Point &b)
renvoie la plus grande composante de chaque point { max(a.x, b.x), max(a.y, b.y), max(a....
Definition
vec.cpp:35
dot
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
Definition
vec.cpp:181
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