8uniform mat4 modelMatrix;
10uniform samplerCube texture0;
12layout(location= 0) in
vec3 position;
13layout(location= 2) in
vec3 normal;
14out
vec3 vertex_position;
15out
vec3 vertex_normal;
16out
vec3 vertex_diffuse;
18float sqr( in const
float x ) {
return x*x; }
22 gl_Position= mvpMatrix *
vec4(position, 1);
23 vertex_position=
vec3(modelMatrix *
vec4(position, 1));
24 vertex_normal= mat3(modelMatrix) *
normalize(normal);
26 float size= textureSize(texture0, 0).x;
27 float dlevel= floor(log2(size));
36 vec3 diffuse= textureLod(texture0,
vec3( 1, 0, 0), dlevel).rgb * sqr(
max(0, .75 + vertex_normal.x)) / 1.75;
37 diffuse+= textureLod(texture0,
vec3(-1, 0, 0), dlevel).rgb * sqr(
max(0, .75 - vertex_normal.x)) / 1.75;
38 diffuse+= textureLod(texture0,
vec3( 0, 1, 0), dlevel).rgb * sqr(
max(0, .75 + vertex_normal.y)) / 1.75;
39 diffuse+= textureLod(texture0,
vec3( 0,-1, 0), dlevel).rgb * sqr(
max(0, .75 - vertex_normal.y)) / 1.75;
40 diffuse+= textureLod(texture0,
vec3( 0, 0, 1), dlevel).rgb * sqr(
max(0, .75 + vertex_normal.z)) / 1.75;
41 diffuse+= textureLod(texture0,
vec3( 0, 0, -1), dlevel).rgb * sqr(
max(0, .75 - vertex_normal.z)) / 1.75;
42 vertex_diffuse= diffuse / 3;
48uniform
vec3 camera_position;
49uniform samplerCube texture0;
54in
vec3 vertex_position;
56in
vec3 vertex_diffuse;
57out
vec4 fragment_color;
61 vec3 v= vertex_position - camera_position;
65 vec3 m= reflect(v, n);
69 float size= textureSize(texture0, 0).x;
70 float glevel=
max(0, log2(size * sqrt(3)) - 0.5 * log2(alpha +1));
71 vec3 glossy= textureLod(texture0, m, glevel).rgb;
73 vec3 color= k * vertex_diffuse + (1 - k) * glossy;
75 fragment_color=
vec4(color, 1);
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....
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
vecteur generique, utilitaire.
vecteur generique 4d, ou 3d homogene, utilitaire.