istereo2

view sdr/tunnel.p.glsl @ 9:64e15874f3bd

foo
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 26 Sep 2015 02:56:07 +0300
parents
children
line source
1 #ifdef GL_ES
2 precision mediump float;
3 #endif
5 uniform sampler2D tex, tex_norm;
7 varying vec3 vpos, normal, tangent;
8 varying vec4 color, tc;
9 varying vec3 lpos;
11 void main()
12 {
13 vec4 fog_color = vec4(0.0, 0.0, 0.0, 1.0);
14 vec3 tcol = texture2D(tex, tc.xy * vec2(1.0, -1.0)).xyz;
15 vec3 tnorm = texture2D(tex_norm, tc.xy * vec2(1.0, -1.0)).xyz;
17 float fog = exp(-(0.2 * -vpos.z));
19 vec3 ldir = lpos - vpos;
20 float ldist = length(ldir);
22 /* bring the light direction to tangent space */
23 vec3 norm = normalize(normal);
24 vec3 tang = normalize(tangent);
25 vec3 bitan = cross(norm, tang);
27 mat3 tbn_xform = mat3(tang.x, bitan.x, norm.x,
28 tang.y, bitan.y, norm.y,
29 tang.z, bitan.z, norm.z);
31 vec3 l = normalize(tbn_xform * ldir);
33 /* grab normal from the normalmap */
34 vec3 n = normalize(tnorm * 2.0 - 1.0);
36 float diffuse = max(dot(n, l), 0.0);
38 /* blinn-phong specular */
39 vec3 v = normalize(-vpos);
40 vec3 h = normalize(v + l);
41 float specular = pow(max(dot(n, h), 0.0), 60.0);
43 const vec3 amb = vec3(0.02, 0.02, 0.02);
45 float att = clamp(1.0 / (0.5 * (ldist * ldist)), 0.0, 1.0);
47 vec3 dif = tcol * diffuse * att;
48 vec3 spec = vec3(0.6, 0.6, 0.6) * specular * att;
50 gl_FragColor = vec4(fog * (amb + dif + spec), 1.0);
51 }