gKit2 light
Loading...
Searching...
No Matches
vertex_display.glsl
1
2#version 430
3
4#ifdef VERTEX_SHADER
5layout(location= 0) in vec3 position;
6
7layout(binding= 0) buffer invocationData
8{
9 uint invocations[];
10};
11
12uniform mat4 mvpMatrix;
13uniform mat4 mvMatrix;
14
15out vec3 vertex_position;
16out vec3 vertex_color;
17
18void main( )
19{
20 gl_Position= mvpMatrix * vec4(position, 1);
21 vertex_position= vec3(mvMatrix * vec4(position, 1));
22
23 uint n= invocations[gl_VertexID];
24
25 // utilise une palette de couleur pour afficher la valeur du compteur
26 const vec3 colors[10]= vec3[10](
27 vec3(0,0,0),
28 vec3(12,17,115),
29 vec3(28,121,255),
30 vec3(31,255,255),
31 vec3(130,255,17),
32 vec3(255,255,14),
33 vec3(255,112,22),
34 vec3(251,0,20),
35 vec3(113,1,14),
36 vec3(113,1,14)
37 );
38
39 if(n < 10) vertex_color= colors[n] / vec3(255);
40 else vertex_color= colors[9] / vec3(255);
41}
42
43#endif
44
45#ifdef FRAGMENT_SHADER
46out vec4 fragment_color;
47
48in vec3 vertex_position;
49in vec3 vertex_color;
50
51layout(early_fragment_tests) in;
52
53void main( )
54{
55 vec3 l= normalize(-vertex_position); // l, direction vers la lumiere // la camera est la source de lumiere. (0,0,0) dans le repere camera
56 vec3 n= normalize(cross(dFdx(vertex_position), dFdy(vertex_position))); // n, normale au point p
57 float cos_theta= abs(dot(n, l)); // cos theta, angle entre la normale et la direction vers la lumiere
58
59 fragment_color= vec4(vertex_color * cos_theta, 1);
60}
61#endif
Color abs(const Color &color)
renvoie la valeur absolue de chaque canal.
Definition color.cpp:71
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
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