gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
M2
vertex_display.glsl
1
2
#version 430
3
4
#ifdef VERTEX_SHADER
5
layout(location= 0) in
vec3
position;
6
7
layout(binding= 0) buffer invocationData
8
{
9
uint invocations[];
10
};
11
12
uniform mat4 mvpMatrix;
13
uniform mat4 mvMatrix;
14
15
out
vec3
vertex_position;
16
out
vec3
vertex_color;
17
18
void
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
46
out
vec4
fragment_color;
47
48
in
vec3
vertex_position;
49
in
vec3
vertex_color;
50
51
layout(early_fragment_tests) in;
52
53
void
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
abs
Color abs(const Color &color)
renvoie la valeur absolue de chaque canal.
Definition
color.cpp:71
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
cross
Vector cross(const Vector &u, const Vector &v)
renvoie le produit vectoriel de 2 vecteurs.
Definition
vec.cpp:173
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