gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
brdf_lambert.glsl
1
#version 330
2
3
4
#ifdef VERTEX_SHADER
5
layout(location= 0) in
vec3
position;
6
layout(location= 2) in
vec3
normal;
7
8
uniform mat4 mvpMatrix;
9
uniform mat4 modelMatrix;
10
11
out
vec3
p;
12
out
vec3
n;
13
14
void
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
24
in
vec3
p;
25
in
vec3
n;
26
27
uniform mat4 viewInvMatrix;
28
29
//~ const vec3 source= vec3(0, 0, 0); // source dans le repere du monde
30
const
vec3
emission=
vec3
(1);
31
const
float
k= 0.8;
32
33
const
float
PI= 3.14159265359;
34
35
out
vec4
fragment_color;
36
void
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
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