2 :copyright: 2011 by Florian Boesch <pyalot@gmail.com>.
3 :license: GNU AGPL3, see LICENSE for more details.
6 attribute vec3 position, normal;
7 attribute vec2 texcoord;
8 varying vec2 v_texcoord;
10 uniform mat4 proj, view;
11 uniform mat3 view_rot;
14 gl_Position = proj * view * vec4(position, 1.0);
15 v_texcoord = texcoord;
20 uniform vec2 viewport;
21 uniform mat4 inv_proj;
22 uniform mat3 inv_view_rot;
23 uniform float shading_mix, reflectivity;
25 varying vec2 v_texcoord;
26 varying vec3 v_normal;
27 uniform samplerCube diffuse, specular;
29 vec3 get_world_normal(){
30 vec2 frag_coord = gl_FragCoord.xy/viewport;
31 frag_coord = (frag_coord-0.5)*2.0;
32 vec4 device_normal = vec4(frag_coord, 0.0, 1.0);
33 vec3 eye_normal = normalize((inv_proj * device_normal).xyz);
34 vec3 world_normal = normalize(inv_view_rot*eye_normal);
39 vec3 eye_normal = get_world_normal();
40 vec3 normal = normalize(v_normal);
41 vec3 specular_normal = reflect(eye_normal, normal);
42 float reflection = smoothstep(0.0, 1.0, pow(dot(-eye_normal, normal), reflectivity));
43 vec4 specular_color = textureCube(specular, specular_normal) * reflection;
44 vec4 diffuse_color = textureCube(diffuse, normal);
45 vec4 result = mix(specular_color, diffuse_color, shading_mix);
46 gl_FragColor = vec4(pow(result.rgb, vec3(1.0/2.2)), 1.0);