gKit2 light
fragment_record.glsl
1 
2 #version 430
3 
4 #ifdef VERTEX_SHADER
5 uniform mat4 mvpMatrix;
6 uniform mat4 mvMatrix;
7 
8 in vec3 position;
9 out vec3 vertex_position;
10 
11 void main( )
12 {
13  gl_Position= mvpMatrix * vec4(position, 1);
14  vertex_position= position;
15 }
16 #endif
17 
18 
19 #ifdef FRAGMENT_SHADER
20 
21 struct fragment
22 {
23  float x, y, z;
24  float r, g, b;
25 };
26 
27 layout(std430, binding= 0) buffer fragments
28 {
29  uint count;
30  uint instance_count;
31  uint vertex_base;
32  uint instance_base;
33 
34  fragment array[];
35 };
36 
37 layout(binding= 0, r32ui) coherent uniform uimage2D counters;
38 
39 in vec3 vertex_position;
40 out vec4 fragment_color;
41 
42 layout(early_fragment_tests) in;
43 
44 void 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(color, 1);
71  fragment_color= vec4(vec3(g), 1);
72 
73  //
74  uint offset= atomicAdd(count, 1);
75 
76  array[offset].x= vertex_position.x;
77  array[offset].y= vertex_position.y;
78  array[offset].z= vertex_position.z;
79  array[offset].r= color.r;
80  array[offset].g= color.g;
81  array[offset].b= color.b;
82 }
83 #endif
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition: vec.cpp:123
Vector cross(const Vector &u, const Vector &v)
renvoie le produit vectoriel de 2 vecteurs.
Definition: vec.cpp:129
vecteur generique, utilitaire.
Definition: vec.h:146
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition: vec.h:168