annotate prototype/sdr/fallback.p.glsl @ 42:6d71dd4760f9
added flag to force the use of the fallback renderer
author |
John Tsiombikas <nuclear@member.fsf.org> |
date |
Thu, 30 Aug 2012 05:38:03 +0300 |
parents |
|
children |
3fef65352b0b |
rev |
line source |
nuclear@41
|
1 uniform sampler2D tex_dif, tex_norm;
|
nuclear@41
|
2
|
nuclear@41
|
3 varying vec3 pos, norm, tang;
|
nuclear@41
|
4
|
nuclear@41
|
5 const float fog_start = 3.0;
|
nuclear@41
|
6 const float fog_end = 6.0;
|
nuclear@41
|
7
|
nuclear@41
|
8 void main()
|
nuclear@41
|
9 {
|
nuclear@41
|
10 vec3 texel = texture2D(tex_dif, gl_TexCoord[0].st).xyz;
|
nuclear@41
|
11
|
nuclear@41
|
12 vec3 n = normalize(norm);
|
nuclear@41
|
13 vec3 t = normalize(tang);
|
nuclear@41
|
14 vec3 b = cross(n, t);
|
nuclear@41
|
15
|
nuclear@41
|
16 mat3 tbn_mat = mat3(
|
nuclear@41
|
17 t.x, b.x, n.x,
|
nuclear@41
|
18 t.y, b.y, n.y,
|
nuclear@41
|
19 t.z, b.z, n.z);
|
nuclear@41
|
20
|
nuclear@41
|
21
|
nuclear@41
|
22 const vec3 lpos = vec3(0.0, 0.0, -0.5);
|
nuclear@41
|
23 vec3 ldir = tbn_mat * normalize(lpos - pos);
|
nuclear@41
|
24
|
nuclear@41
|
25 const vec3 vdir = vec3(0.0, 0.0, 1.0);
|
nuclear@41
|
26 vec3 hvec = normalize(vdir + ldir);
|
nuclear@41
|
27
|
nuclear@41
|
28 n = normalize(texture2D(tex_norm, gl_TexCoord[0].st).xyz * 2.0 - 1.0);
|
nuclear@41
|
29 float ndotl = max(dot(n, ldir), 0.0);
|
nuclear@41
|
30 float ndoth = max(dot(n, hvec), 0.0);
|
nuclear@41
|
31
|
nuclear@41
|
32 vec3 diffuse = gl_FrontMaterial.diffuse.xyz * texel * ndotl;
|
nuclear@41
|
33 vec3 specular = gl_FrontMaterial.specular.xyz * pow(ndoth, gl_FrontMaterial.shininess);
|
nuclear@41
|
34
|
nuclear@41
|
35 float fog = clamp((fog_end + pos.z) / (fog_end - fog_start), 0.0, 1.0);
|
nuclear@41
|
36
|
nuclear@41
|
37 gl_FragColor = vec4((diffuse + specular) * fog, 1.0);
|
nuclear@41
|
38 }
|