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