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