gKit2 light
Loading...
Searching...
No Matches
indirect_remap.glsl
Go to the documentation of this file.
1
3
4#version 430
5
6#ifdef VERTEX_SHADER
7
8#extension GL_ARB_shader_draw_parameters : require
9
10layout(location= 0) in vec3 position;
11out vec3 vertex_position;
12
13uniform mat4 modelMatrix;
14uniform mat4 vpMatrix;
15uniform mat4 viewMatrix;
16
17// row_major : organisation des matrices par lignes...
18layout(binding= 0, row_major, std430) readonly buffer modelData
19{
20 mat4 objectMatrix[];
21};
22
23layout(binding= 1, std430) readonly buffer remapData
24{
25 uint remap[];
26};
27
28void main( )
29{
30 uint id= remap[gl_DrawIDARB];
31 gl_Position= vpMatrix * objectMatrix[id] * modelMatrix * vec4(position, 1);
32
33 // position dans le repere camera
34 vertex_position= vec3(viewMatrix * objectMatrix[id] * modelMatrix * vec4(position, 1));
35}
36#endif
37
38
39#ifdef FRAGMENT_SHADER
40
41in vec3 vertex_position;
42
43out vec4 fragment_color;
44
45void main( )
46{
47 vec4 color= vec4(1, 0.8, 0, 1);
48 // recalcule la normale geometrique du triangle, dans le repere camera
49 vec3 t= normalize(dFdx(vertex_position));
50 vec3 b= normalize(dFdy(vertex_position));
51 vec3 normal= normalize(cross(t, b));
52
53 // matiere diffuse...
54 float cos_theta= max(0.0, normal.z);
55 color= color * cos_theta;
56
57 fragment_color= vec4(color.rgb, 1);
58}
59#endif
Point max(const Point &a, const Point &b)
renvoie la plus grande composante de chaque point { max(a.x, b.x), max(a.y, b.y), max(a....
Definition vec.cpp:35
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