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