dungeon_crawler

view prototype/sdr/mrt.p.glsl @ 43:3fef65352b0b

- added mipmap generation
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 30 Aug 2012 05:58:09 +0300
parents 80dab4000413
children aa86119e3295
line source
1 /* MRT assignments
2 * 0 - RGB: position, A: shininess
3 * 1 - RGB: normal
4 * 3 - RGB: diffuse color, A: shininess str.
5 * 4 - 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 vec4 texel = texture2D(tex_dif, gl_TexCoord[0].st);
33 vec3 diffuse = fog * (gl_FrontMaterial.diffuse * texel).xyz;
34 vec3 spec = fog * gl_FrontMaterial.specular.xyz;
35 float sstr = (spec.x + spec.y + spec.z) / 3.0;
37 gl_FragData[0] = vec4(pos, gl_FrontMaterial.shininess);
38 gl_FragData[1] = vec4(n, 0.0);
39 gl_FragData[2] = vec4(diffuse, sstr);
40 //gl_FragData[3] = vec4(0.0, 0.0, 0.0, 0.0);
41 }