annotate prototype/sdr/mrt.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 |
84a56fb24850 |
children |
12a1dcfe91fa |
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@16
|
32 vec4 texel = texture2D(tex_dif, gl_TexCoord[0].st);
|
nuclear@35
|
33 vec3 diffuse = fog * (gl_FrontMaterial.diffuse * texel).xyz;
|
nuclear@35
|
34 vec3 spec = fog * gl_FrontMaterial.specular.xyz;
|
nuclear@20
|
35 float sstr = (spec.x + spec.y + spec.z) / 3.0;
|
nuclear@20
|
36
|
nuclear@34
|
37 gl_FragData[0] = vec4(pos, gl_FrontMaterial.shininess);
|
nuclear@35
|
38 gl_FragData[1] = vec4(n, 0.0);
|
nuclear@20
|
39 gl_FragData[2] = vec4(diffuse, sstr);
|
nuclear@33
|
40 //gl_FragData[3] = vec4(0.0, 0.0, 0.0, 0.0);
|
nuclear@16
|
41 }
|