gKit2 light
tuto5GL_cubemap.glsl
Go to the documentation of this file.
1 
3 
4 #version 430
5 
6 #ifdef VERTEX_SHADER
7 uniform mat4 mvpMatrix;
8 uniform mat4 modelMatrix;
9 
10 layout(location= 0) in vec3 position;
11 layout(location= 2) in vec3 normal;
12 out vec3 vertex_position;
13 out vec3 vertex_normal;
14 
15 void main( )
16 {
17  gl_Position= mvpMatrix * vec4(position, 1);
18  vertex_position= vec3(modelMatrix * vec4(position, 1));
19  vertex_normal= mat3(modelMatrix) * normal;
20 }
21 #endif
22 
23 
24 #ifdef FRAGMENT_SHADER
25 uniform vec3 camera_position;
26 uniform samplerCube texture0;
27 
28 const float alpha= 22;
29 const float k= 0.8;
30 
31 in vec3 vertex_position;
32 in vec3 vertex_normal;
33 out vec4 fragment_color;
34 
35 void main( )
36 {
37  vec3 v= vertex_position - camera_position;
38  vec3 n= normalize(vertex_normal);
39  vec3 m= reflect(v, n);
40  //~ vec3 color= texture(texture0, m).rgb;
41  vec3 color= texture(texture0, n).rgb;
42 
43  //~ // approximation
44  //~ float w= textureSize(texture0, 0).x;
45  //~ float dlevel= log2(w) +1;
46  //~ float glevel= max(0, log2(w * sqrt(3)) - 0.5 * log2(alpha+1));
47  //~ vec3 diffuse= textureLod(texture0, n, dlevel).rgb;
48  //~ vec3 glossy= textureLod(texture0, m, glevel).rgb;
49  //~ vec3 color= k * diffuse + (1 - k) * glossy;
50 
51  fragment_color= vec4(color, 1);
52 }
53 #endif
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition: vec.cpp:123
vecteur generique, utilitaire.
Definition: vec.h:146
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition: vec.h:168