dungeon_crawler
view prototype/sdr/mrt.p.glsl @ 79:110b2af4b9d8
fixed the shader non-conformity by explicitly converting 2.2 to vec3 before passing it to pow for the texel inverse-gamma thing
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 27 Oct 2012 01:54:39 +0300 |
parents | 12a1dcfe91fa |
children | a373b36ffc17 |
line source
1 /* MRT assignments
2 * 0 - RGB: position, A: shininess
3 * 1 - RGB: normal
4 * 2 - RGB: diffuse color, A: shininess str.
5 * 3 - unused
6 */
8 uniform sampler2D tex_dif, tex_norm;
10 varying vec3 pos, norm, tang;
12 const float fog_start = 3.0;
13 const float fog_end = 6.0;
15 void main()
16 {
17 vec3 n = normalize(norm);
18 vec3 t = normalize(tang);
19 vec3 b = cross(n, t);
21 mat3 tbn_mat = mat3(
22 t.x, t.y, t.z,
23 b.x, b.y, b.z,
24 n.x, n.y, n.z);
26 // grab normal from the normal map, remap it and transform it to view space
27 n = texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0;
28 n = normalize(tbn_mat * n);
30 float fog = clamp((fog_end + pos.z) / (fog_end - fog_start), 0.0, 1.0);
32 vec3 texel_srgb = texture2D(tex_dif, gl_TexCoord[0].st).xyz;
33 vec3 texel = pow(texel_srgb.xyz, vec3(2.2, 2.2, 2.2));
35 vec3 diffuse = fog * (gl_FrontMaterial.diffuse.xyz * texel);
36 vec3 spec = fog * gl_FrontMaterial.specular.xyz;
37 float sstr = (spec.x + spec.y + spec.z) / 3.0;
39 gl_FragData[0] = vec4(pos, gl_FrontMaterial.shininess);
40 gl_FragData[1] = vec4(n, 0.0);
41 gl_FragData[2] = vec4(diffuse, sstr);
42 //gl_FragData[3] = vec4(0.0, 0.0, 0.0, 0.0);
43 }