gKit2 light
Loading...
Searching...
No Matches
tuto9_groups.glsl
Go to the documentation of this file.
1
2
3#version 330
4
5#ifdef VERTEX_SHADER
6layout(location= 0) in vec3 position;
7layout(location= 2) in vec3 normal;
8
9uniform mat4 mvpMatrix;
10uniform mat4 mvMatrix;
11
12out vec3 vertex_normal;
13
14void 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
26in vec3 vertex_normal;
27
28uniform vec4 color;
29
30out vec4 fragment_color;
31void 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
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
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
Definition vec.cpp:181
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