dungeon_crawler

view prototype/sdr/fallback.p.glsl @ 41:acfe0c0110fc

- cleaned up the renderer - implemented fallback (non-deferred renderer)
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 30 Aug 2012 05:35:00 +0300
parents
children 3fef65352b0b
line source
1 uniform sampler2D tex_dif, tex_norm;
3 varying vec3 pos, norm, tang;
5 const float fog_start = 3.0;
6 const float fog_end = 6.0;
8 void main()
9 {
10 vec3 texel = texture2D(tex_dif, gl_TexCoord[0].st).xyz;
12 vec3 n = normalize(norm);
13 vec3 t = normalize(tang);
14 vec3 b = cross(n, t);
16 mat3 tbn_mat = mat3(
17 t.x, b.x, n.x,
18 t.y, b.y, n.y,
19 t.z, b.z, n.z);
22 const vec3 lpos = vec3(0.0, 0.0, -0.5);
23 vec3 ldir = tbn_mat * normalize(lpos - pos);
25 const vec3 vdir = vec3(0.0, 0.0, 1.0);
26 vec3 hvec = normalize(vdir + ldir);
28 n = normalize(texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
29 float ndotl = max(dot(n, ldir), 0.0);
30 float ndoth = max(dot(n, hvec), 0.0);
32 vec3 diffuse = gl_FrontMaterial.diffuse.xyz * texel * ndotl;
33 vec3 specular = gl_FrontMaterial.specular.xyz * pow(ndoth, gl_FrontMaterial.shininess);
35 float fog = clamp((fog_end + pos.z) / (fog_end - fog_start), 0.0, 1.0);
37 gl_FragColor = vec4((diffuse + specular) * fog, 1.0);
38 }