gKit2 light
Loading...
Searching...
No Matches
indirect.glsl
Go to the documentation of this file.
1
3
4#version 460
5
6#ifdef VERTEX_SHADER
7
8layout(location= 0) in vec3 position;
9out vec3 vertex_position;
10
11uniform mat4 modelMatrix;
12uniform mat4 vpMatrix;
13uniform mat4 viewMatrix;
14
15// row_major : organisation des matrices par lignes...
16layout(binding= 0, row_major, std430) readonly buffer modelData
17{
18 mat4 objectMatrix[];
19};
20
21void main( )
22{
23 gl_Position= vpMatrix * objectMatrix[gl_DrawID] * modelMatrix * vec4(position, 1);
24
25 // position dans le repere camera
26 vertex_position= vec3(viewMatrix * objectMatrix[gl_DrawID] * modelMatrix * vec4(position, 1));
27}
28#endif
29
30
31#ifdef FRAGMENT_SHADER
32
33in vec3 vertex_position;
34
35out vec4 fragment_color;
36
37void main( )
38{
39 vec4 color= vec4(1, 0.8, 0, 1);
40 // recalcule la normale geometrique du triangle, dans le repere camera
41 vec3 t= normalize(dFdx(vertex_position));
42 vec3 b= normalize(dFdy(vertex_position));
43 vec3 normal= normalize(cross(t, b));
44
45 // matiere diffuse...
46 float cos_theta= max(0.0, normal.z);
47 color= color * cos_theta;
48
49 fragment_color= vec4(color.rgb, 1);
50}
51#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
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition vec.cpp:167
Vector cross(const Vector &u, const Vector &v)
renvoie le produit vectoriel de 2 vecteurs.
Definition vec.cpp:173
vecteur generique, utilitaire.
Definition vec.h:169
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:192