Draw the cubes using flat shading and fewer vertexes.
[mandelwow.git] / shaded.vert
1 #version 300 es
2 precision lowp float;
3
4 in vec3 position;
5 in vec3 normal;
6 flat out vec4 color;  // Shaded color
7
8 uniform mat4 model;
9 uniform mat4 perspview;
10 uniform vec3 col;
11
12 void main() {
13     mat4 m = perspview * model;
14     vec3 dark = col * 0.1;
15     vec3 u_light = vec3( 0.5, -0.7, -0.6);
16     vec3 v_normal = transpose(inverse(mat3(model))) * normal;
17
18     float distance = model[3][2];
19     float attenuation = 1. / (1. + distance * distance * 0.05);
20     float brightness = max(dot(normalize(v_normal), normalize(u_light)) * attenuation, 0.0);
21     color = vec4(mix(dark, col, brightness), 1.0);
22
23     gl_Position = m * vec4(position, 1.0);
24 }