istereo

annotate sdr/tunnel.p.glsl @ 29:fb4c9641059f

added more forgotten files
author John Tsiombikas <nuclear@mutantstargoat.com>
date Thu, 08 Sep 2011 08:31:15 +0300
parents
children 8dd271942543
rev   line source
nuclear@29 1 #ifdef GL_ES
nuclear@29 2 precision highp float;
nuclear@29 3 #endif
nuclear@29 4
nuclear@29 5 uniform sampler2D tex, tex_norm;
nuclear@29 6
nuclear@29 7 varying vec3 vpos, normal, tangent;
nuclear@29 8 varying vec4 color, tc;
nuclear@29 9 varying vec3 lpos;
nuclear@29 10
nuclear@29 11 void main()
nuclear@29 12 {
nuclear@29 13 vec4 fog_color = vec4(0.0, 0.0, 0.0, 1.0);
nuclear@29 14 vec3 tcol = texture2D(tex, tc.xy * vec2(1.0, -1.0)).xyz;
nuclear@29 15 vec3 tnorm = texture2D(tex_norm, tc.xy * vec2(1.0, -1.0)).xyz;
nuclear@29 16
nuclear@29 17 float fog = exp(-(0.2 * -vpos.z));
nuclear@29 18
nuclear@29 19 vec3 ldir = lpos - vpos;
nuclear@29 20 float ldist = length(ldir);
nuclear@29 21
nuclear@29 22 /* bring the light direction to tangent space */
nuclear@29 23 vec3 norm = normalize(normal);
nuclear@29 24 vec3 tang = normalize(tangent);
nuclear@29 25 vec3 bitan = cross(norm, tang);
nuclear@29 26
nuclear@29 27 mat3 tbn_xform = mat3(tang.x, bitan.x, norm.x,
nuclear@29 28 tang.y, bitan.y, norm.y,
nuclear@29 29 tang.z, bitan.z, norm.z);
nuclear@29 30
nuclear@29 31 vec3 l = normalize(tbn_xform * ldir);
nuclear@29 32
nuclear@29 33 /* grab normal from the normalmap */
nuclear@29 34 vec3 n = normalize(tnorm * 2.0 - 1.0);
nuclear@29 35
nuclear@29 36 float diffuse = max(dot(n, l), 0.0);
nuclear@29 37
nuclear@29 38 /* blinn-phong specular */
nuclear@29 39 vec3 v = normalize(-vpos);
nuclear@29 40 vec3 h = normalize(v + l);
nuclear@29 41 float specular = pow(max(dot(n, h), 0.0), 60.0);
nuclear@29 42
nuclear@29 43 vec3 amb = vec3(0.02, 0.02, 0.02);
nuclear@29 44
nuclear@29 45 float att = clamp(1.0 / (0.5 * (ldist * ldist)), 0.0, 1.0);
nuclear@29 46
nuclear@29 47 vec3 dif = tcol * diffuse * att;
nuclear@29 48 vec3 spec = vec3(0.6, 0.6, 0.6) * specular * att;
nuclear@29 49
nuclear@29 50 //gl_FragColor = 0.5 * tcol + 0.5 * tnorm;//mix(fog_color, tcol, fog);
nuclear@29 51 gl_FragColor = vec4(fog * (amb + dif + spec), 1.0);
nuclear@29 52 }