dungeon_crawler

annotate prototype/sdr/fallback.p.glsl @ 63:7f52d6310317

fixed design issue with datafile_path
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 02 Oct 2012 04:52:59 +0300
parents acfe0c0110fc
children
rev   line source
nuclear@41 1 uniform sampler2D tex_dif, tex_norm;
nuclear@41 2
nuclear@41 3 varying vec3 pos, norm, tang;
nuclear@41 4
nuclear@41 5 const float fog_start = 3.0;
nuclear@41 6 const float fog_end = 6.0;
nuclear@41 7
nuclear@43 8 const vec3 lpos = vec3(0.0, 0.0, -0.5);
nuclear@43 9 const vec3 vdir = vec3(0.0, 0.0, 1.0);
nuclear@43 10
nuclear@43 11 const vec3 lcol = vec3(1.0, 0.732, 0.437);
nuclear@43 12
nuclear@41 13 void main()
nuclear@41 14 {
nuclear@41 15 vec3 texel = texture2D(tex_dif, gl_TexCoord[0].st).xyz;
nuclear@41 16
nuclear@41 17 vec3 n = normalize(norm);
nuclear@41 18 vec3 t = normalize(tang);
nuclear@41 19 vec3 b = cross(n, t);
nuclear@41 20
nuclear@41 21 mat3 tbn_mat = mat3(
nuclear@41 22 t.x, b.x, n.x,
nuclear@41 23 t.y, b.y, n.y,
nuclear@41 24 t.z, b.z, n.z);
nuclear@41 25
nuclear@41 26 vec3 ldir = tbn_mat * normalize(lpos - pos);
nuclear@41 27 vec3 hvec = normalize(vdir + ldir);
nuclear@41 28
nuclear@41 29 n = normalize(texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
nuclear@41 30 float ndotl = max(dot(n, ldir), 0.0);
nuclear@41 31 float ndoth = max(dot(n, hvec), 0.0);
nuclear@41 32
nuclear@41 33 vec3 diffuse = gl_FrontMaterial.diffuse.xyz * texel * ndotl;
nuclear@41 34 vec3 specular = gl_FrontMaterial.specular.xyz * pow(ndoth, gl_FrontMaterial.shininess);
nuclear@41 35
nuclear@41 36 float fog = clamp((fog_end + pos.z) / (fog_end - fog_start), 0.0, 1.0);
nuclear@41 37
nuclear@43 38 gl_FragColor = vec4((diffuse + specular) * lcol * fog, 1.0);
nuclear@41 39 }