istereo2

annotate sdr/tunnel.p.glsl @ 24:9d53a4938ce8

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