2012-05-11 06:26:34 +00:00
|
|
|
struct light {
|
|
|
|
vec4 position; // xyz = pos, w = strength
|
|
|
|
vec4 color; // rgb. a = ?
|
|
|
|
};
|
2012-05-11 03:49:14 +00:00
|
|
|
uniform sampler2D texture;
|
|
|
|
uniform sampler2D normalmap;
|
2012-05-15 10:15:51 +00:00
|
|
|
uniform vec3 ambient;
|
2012-05-11 06:26:34 +00:00
|
|
|
uniform light lights[8];
|
2012-05-11 03:49:14 +00:00
|
|
|
uniform vec4 fog;
|
|
|
|
|
2012-05-11 12:56:34 +00:00
|
|
|
varying vec3 position;
|
2012-05-11 03:49:14 +00:00
|
|
|
varying vec3 bitangent;
|
|
|
|
varying vec3 tangent;
|
|
|
|
varying vec3 normal;
|
|
|
|
varying vec2 st;
|
|
|
|
varying vec4 color;
|
|
|
|
|
|
|
|
float
|
|
|
|
sqr (float x)
|
|
|
|
{
|
|
|
|
return x * x;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4
|
|
|
|
fogBlend (vec4 color)
|
|
|
|
{
|
|
|
|
float f;
|
|
|
|
vec4 fog_color = vec4 (fog.rgb, 1.0);
|
|
|
|
|
2012-07-17 10:10:10 +00:00
|
|
|
f = exp (-sqr (fog.a * gl_FragCoord.z / gl_FragCoord.w));
|
2012-07-17 10:08:36 +00:00
|
|
|
return vec4 (mix (fog_color.rgb, color.rgb, f), color.a);
|
2012-05-11 03:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vec3
|
|
|
|
calc_light (vec3 n, int ind)
|
|
|
|
{
|
|
|
|
vec3 d;
|
2012-05-11 06:26:34 +00:00
|
|
|
light l = lights[ind];
|
2012-05-14 11:29:36 +00:00
|
|
|
float mag;
|
2012-05-11 03:49:14 +00:00
|
|
|
|
2012-05-14 14:54:01 +00:00
|
|
|
d = l.position.xyz - position;
|
2012-05-14 11:29:36 +00:00
|
|
|
mag = dot (d, n);
|
|
|
|
mag = max (0.0, mag);
|
|
|
|
return l.color.rgb * (l.position.w * mag / dot (d, d));
|
2012-05-11 03:49:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
mat3 tbn = mat3 (tangent, bitangent, normal);
|
2012-05-11 06:26:34 +00:00
|
|
|
vec3 norm, l;
|
2012-05-11 03:49:14 +00:00
|
|
|
vec4 col;
|
|
|
|
|
2012-05-14 14:54:01 +00:00
|
|
|
norm = (texture2D (normalmap, st).xyz - vec3(0.5)) * 2.0;
|
2012-05-11 03:49:14 +00:00
|
|
|
norm = tbn * norm;
|
2012-05-15 10:15:51 +00:00
|
|
|
l = ambient;
|
|
|
|
l += calc_light (norm, 0);
|
2012-05-11 06:26:34 +00:00
|
|
|
l += calc_light (norm, 1);
|
|
|
|
l += calc_light (norm, 2);
|
|
|
|
l += calc_light (norm, 3);
|
|
|
|
l += calc_light (norm, 4);
|
|
|
|
l += calc_light (norm, 5);
|
|
|
|
l += calc_light (norm, 6);
|
|
|
|
l += calc_light (norm, 7);
|
|
|
|
col = texture2D (texture, st) * color * vec4 (l, 1.0);
|
2012-05-11 03:49:14 +00:00
|
|
|
gl_FragColor = fogBlend (col);
|
|
|
|
}
|