dungeon_crawler

view prototype/sdr/fallback.p.glsl @ 76:f379c00eb07f

added samurai's texel center fix for the color grading palette lookup
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 23 Oct 2012 14:57:08 +0300
parents acfe0c0110fc
children
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 const vec3 lpos = vec3(0.0, 0.0, -0.5);
9 const vec3 vdir = vec3(0.0, 0.0, 1.0);
11 const vec3 lcol = vec3(1.0, 0.732, 0.437);
13 void main()
14 {
15 vec3 texel = texture2D(tex_dif, gl_TexCoord[0].st).xyz;
17 vec3 n = normalize(norm);
18 vec3 t = normalize(tang);
19 vec3 b = cross(n, t);
21 mat3 tbn_mat = mat3(
22 t.x, b.x, n.x,
23 t.y, b.y, n.y,
24 t.z, b.z, n.z);
26 vec3 ldir = tbn_mat * normalize(lpos - pos);
27 vec3 hvec = normalize(vdir + ldir);
29 n = normalize(texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
30 float ndotl = max(dot(n, ldir), 0.0);
31 float ndoth = max(dot(n, hvec), 0.0);
33 vec3 diffuse = gl_FrontMaterial.diffuse.xyz * texel * ndotl;
34 vec3 specular = gl_FrontMaterial.specular.xyz * pow(ndoth, gl_FrontMaterial.shininess);
36 float fog = clamp((fog_end + pos.z) / (fog_end - fog_start), 0.0, 1.0);
38 gl_FragColor = vec4((diffuse + specular) * lcol * fog, 1.0);
39 }