gKit2 light
Toggle main menu visibility
Loading...
Searching...
No Matches
gkit2_tutos
M2
fragment_record.glsl
Go to the documentation of this file.
1
2
3
#version 430
4
5
#ifdef VERTEX_SHADER
6
uniform mat4 mvpMatrix;
7
uniform mat4 mvMatrix;
8
9
in
vec3
position;
10
out
vec3
vertex_position;
11
12
void
main( )
13
{
14
gl_Position= mvpMatrix *
vec4
(position, 1);
15
vertex_position= position;
16
}
17
#endif
18
19
20
#ifdef FRAGMENT_SHADER
21
22
struct
fragment
23
{
24
float
x, y, z;
25
float
r, g, b;
26
};
27
28
layout(std430, binding= 0) buffer fragments
29
{
30
uint count;
31
32
fragment array[];
33
};
34
35
layout(binding= 0, r32ui) coherent uniform uimage2D counters;
36
37
in
vec3
vertex_position;
38
out
vec4
fragment_color;
39
40
layout(early_fragment_tests) in;
41
42
void
main( )
43
{
44
vec3
t=
normalize
( dFdx(vertex_position) );
45
vec3
b=
normalize
( dFdy(vertex_position) );
46
vec3
normal=
normalize
(
cross
(t, b) );
47
vec3
color= (normal + 1) / 2;
48
float
g= 0.3*color.r + 0.7*color.g + 0.1*color.b;
49
50
uint n= imageAtomicAdd(counters, ivec2(gl_FragCoord.xy), 1) +1;
51
52
// utilise une palette de couleur pour afficher la valeur du compteur
53
const
vec3
colors[10]=
vec3
[10](
54
vec3
(0,0,0),
55
vec3
(12,17,115),
56
vec3
(28,121,255),
57
vec3
(31,255,255),
58
vec3
(130,255,17),
59
vec3
(255,255,14),
60
vec3
(255,112,22),
61
vec3
(251,0,20),
62
vec3
(113,1,14),
63
vec3
(113,1,14)
64
);
65
if
(n < 10) color= g * colors[n] /
vec3
(255);
66
else
color= g * colors[9] /
vec3
(255);
67
68
fragment_color=
vec4
(
vec3
(g), 1);
69
70
//
71
uint offset= atomicAdd(count, 1);
72
73
array[offset].x= vertex_position.x;
74
array[offset].y= vertex_position.y;
75
array[offset].z= vertex_position.z;
76
array[offset].r= color.r;
77
array[offset].g= color.g;
78
array[offset].b= color.b;
79
}
80
#endif
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