gKit2 light
Loading...
Searching...
No Matches
brdf_lambert.glsl
1#version 330
2
3
4#ifdef VERTEX_SHADER
5layout(location= 0) in vec3 position;
6layout(location= 2) in vec3 normal;
7
8uniform mat4 mvpMatrix;
9uniform mat4 modelMatrix;
10
11out vec3 p;
12out vec3 n;
13
14void main( )
15{
16 gl_Position= mvpMatrix * vec4(position, 1);
17
18 p= vec3(modelMatrix * vec4(position, 1));
19 n= mat3(modelMatrix) * normal;
20}
21#endif
22
23#ifdef FRAGMENT_SHADER
24in vec3 p;
25in vec3 n;
26
27uniform mat4 viewInvMatrix;
28
29//~ const vec3 source= vec3(0, 0, 0); // source dans le repere du monde
30const vec3 emission= vec3(1);
31const float k= 0.8;
32
33const float PI= 3.14159265359;
34
35out vec4 fragment_color;
36void main( )
37{
38 vec3 camera= vec3(viewInvMatrix * vec4(0, 0, 0, 1)); // position de la camera dans le repere du monde
39 vec3 source= vec3(viewInvMatrix * vec4(10, 10, 0, 1)); // source "frontale" positionnee par rapport a la camera
40
41 // directions
42 vec3 o= normalize(camera - p);
43 vec3 l= normalize(source - p);
44 // cos
45 float cos_theta= max(0, dot(normalize(n), l));
46
47 // brdf
48 float fr= k / PI;
49 vec3 color= emission * fr * cos_theta;
50
51 fragment_color= vec4(color, 1);
52}
53#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