gKit2 light
Loading...
Searching...
No Matches
tuto_storage_buffer.glsl
Go to the documentation of this file.
1
3
4#version 430
5
6#ifdef VERTEX_SHADER
7
8struct vertex
9{
10 vec3 position;
11 vec3 normal;
12 vec2 texcoord;
13};
14
15layout(std430, binding= 0) readonly buffer vertexData
16{
17 vertex data[];
18};
19
20uniform mat4 mvpMatrix;
21uniform mat4 mvMatrix;
22uniform mat4 normalMatrix;
23
24out vec3 vertex_position;
25out vec3 vertex_normal;
26out vec2 vertex_texcoord;
27
28void main( )
29{
30 vec3 p= data[gl_VertexID].position;
31 vec3 n= data[gl_VertexID].normal;
32 vec2 t= data[gl_VertexID].texcoord;
33
34 gl_Position= mvpMatrix * vec4(p, 1);
35
36 vertex_position= vec3(mvMatrix * vec4(p, 1));
37 vertex_normal= mat3(normalMatrix) * n;
38 vertex_texcoord= t;
39}
40#endif
41
42#ifdef FRAGMENT_SHADER
43
44uniform sampler2D diffuse_color;
45
46in vec3 vertex_position;
47in vec3 vertex_normal;
48in vec2 vertex_texcoord;
49
50out vec4 fragment_color;
51
52void main( )
53{
54 float cos_theta= dot(normalize(vertex_normal), normalize(-vertex_position));
55 vec3 color= texture(diffuse_color, vertex_texcoord).rgb * cos_theta;
56 fragment_color= vec4(color, 1);
57}
58#endif
59
float dot(const Vector &u, const Vector &v)
renvoie le produit scalaire de 2 vecteurs.
Definition vec.cpp:181
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition vec.cpp:167
vecteur generique, utilitaire.
Definition vec.h:152
vecteur generique, utilitaire.
Definition vec.h:169
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:192
representation de l'indexation complete d'un sommet