istereo

diff 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
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/sdr/tunnel.p.glsl	Thu Sep 08 08:31:15 2011 +0300
     1.3 @@ -0,0 +1,52 @@
     1.4 +#ifdef GL_ES
     1.5 +precision highp float;
     1.6 +#endif
     1.7 +
     1.8 +uniform sampler2D tex, tex_norm;
     1.9 +
    1.10 +varying vec3 vpos, normal, tangent;
    1.11 +varying vec4 color, tc;
    1.12 +varying vec3 lpos;
    1.13 +
    1.14 +void main()
    1.15 +{
    1.16 +	vec4 fog_color = vec4(0.0, 0.0, 0.0, 1.0);
    1.17 +	vec3 tcol = texture2D(tex, tc.xy * vec2(1.0, -1.0)).xyz;
    1.18 +	vec3 tnorm = texture2D(tex_norm, tc.xy * vec2(1.0, -1.0)).xyz;
    1.19 +
    1.20 +	float fog = exp(-(0.2 * -vpos.z));
    1.21 +	
    1.22 +	vec3 ldir = lpos - vpos;
    1.23 +	float ldist = length(ldir);
    1.24 +
    1.25 +	/* bring the light direction to tangent space */
    1.26 +	vec3 norm = normalize(normal);
    1.27 +	vec3 tang = normalize(tangent);
    1.28 +	vec3 bitan = cross(norm, tang);
    1.29 +
    1.30 +	mat3 tbn_xform = mat3(tang.x, bitan.x, norm.x,
    1.31 +			tang.y, bitan.y, norm.y,
    1.32 +			tang.z, bitan.z, norm.z);
    1.33 +
    1.34 +	vec3 l = normalize(tbn_xform * ldir);
    1.35 +
    1.36 +	/* grab normal from the normalmap */
    1.37 +	vec3 n = normalize(tnorm * 2.0 - 1.0);
    1.38 +
    1.39 +	float diffuse = max(dot(n, l), 0.0);
    1.40 +
    1.41 +	/* blinn-phong specular */
    1.42 +	vec3 v = normalize(-vpos);
    1.43 +	vec3 h = normalize(v + l);
    1.44 +	float specular = pow(max(dot(n, h), 0.0), 60.0);
    1.45 +
    1.46 +	vec3 amb = vec3(0.02, 0.02, 0.02);
    1.47 +
    1.48 +	float att = clamp(1.0 / (0.5 * (ldist * ldist)), 0.0, 1.0);
    1.49 +
    1.50 +	vec3 dif = tcol * diffuse * att;
    1.51 +	vec3 spec = vec3(0.6, 0.6, 0.6) * specular * att;
    1.52 +
    1.53 +	//gl_FragColor = 0.5 * tcol + 0.5 * tnorm;//mix(fog_color, tcol, fog);
    1.54 +	gl_FragColor = vec4(fog * (amb + dif + spec), 1.0);
    1.55 +}