2012-04-08 17:55:06 +02:00
|
|
|
#version 120
|
2012-02-09 18:55:25 +01:00
|
|
|
|
2012-01-29 02:22:22 +01:00
|
|
|
uniform sampler2D baseTex;
|
2012-03-19 22:10:14 +01:00
|
|
|
uniform sampler2D losTex;
|
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_SHADOW
|
|
|
|
#if USE_SHADOW_SAMPLER
|
2012-03-19 22:10:14 +01:00
|
|
|
uniform sampler2DShadow shadowTex;
|
|
|
|
#else
|
|
|
|
uniform sampler2D shadowTex;
|
|
|
|
#endif
|
2012-02-25 18:29:27 +01:00
|
|
|
#endif
|
2012-03-19 22:10:14 +01:00
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_OBJECTCOLOR
|
2012-04-03 20:44:46 +02:00
|
|
|
uniform vec3 objectColor;
|
|
|
|
#else
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_PLAYERCOLOR
|
2012-04-03 20:44:46 +02:00
|
|
|
uniform vec3 playerColor;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-01-29 02:22:22 +01:00
|
|
|
uniform vec3 shadingColor;
|
|
|
|
uniform vec3 ambient;
|
|
|
|
uniform vec4 shadowOffsets1;
|
|
|
|
uniform vec4 shadowOffsets2;
|
|
|
|
|
|
|
|
varying vec3 v_lighting;
|
|
|
|
varying vec2 v_tex;
|
|
|
|
varying vec4 v_shadow;
|
|
|
|
varying vec2 v_los;
|
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_SPECULAR
|
|
|
|
uniform float specularPower;
|
|
|
|
uniform vec3 specularColor;
|
2012-04-09 01:03:22 +02:00
|
|
|
uniform vec3 sunColor;
|
2012-04-08 17:55:06 +02:00
|
|
|
varying vec3 v_normal;
|
|
|
|
varying vec3 v_half;
|
|
|
|
#endif
|
|
|
|
|
2012-03-19 22:10:14 +01:00
|
|
|
float get_shadow()
|
|
|
|
{
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_SHADOW
|
|
|
|
#if USE_SHADOW_SAMPLER
|
|
|
|
#if USE_SHADOW_PCF
|
2012-03-19 22:10:14 +01:00
|
|
|
return 0.25 * (
|
|
|
|
shadow2D(shadowTex, vec3(v_shadow.xy + shadowOffsets1.xy, v_shadow.z)).a +
|
|
|
|
shadow2D(shadowTex, vec3(v_shadow.xy + shadowOffsets1.zw, v_shadow.z)).a +
|
|
|
|
shadow2D(shadowTex, vec3(v_shadow.xy + shadowOffsets2.xy, v_shadow.z)).a +
|
|
|
|
shadow2D(shadowTex, vec3(v_shadow.xy + shadowOffsets2.zw, v_shadow.z)).a
|
|
|
|
);
|
|
|
|
#else
|
|
|
|
return shadow2D(shadowTex, v_shadow.xyz).a;
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
if (v_shadow.z >= 1.0)
|
|
|
|
return 1.0;
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_SHADOW_PCF
|
2012-03-19 22:10:14 +01:00
|
|
|
return (
|
|
|
|
(v_shadow.z <= texture2D(shadowTex, v_shadow.xy + shadowOffsets1.xy).x ? 0.25 : 0.0) +
|
|
|
|
(v_shadow.z <= texture2D(shadowTex, v_shadow.xy + shadowOffsets1.zw).x ? 0.25 : 0.0) +
|
|
|
|
(v_shadow.z <= texture2D(shadowTex, v_shadow.xy + shadowOffsets2.xy).x ? 0.25 : 0.0) +
|
|
|
|
(v_shadow.z <= texture2D(shadowTex, v_shadow.xy + shadowOffsets2.zw).x ? 0.25 : 0.0)
|
|
|
|
);
|
|
|
|
#else
|
|
|
|
return (v_shadow.z <= texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
return 1.0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-29 02:22:22 +01:00
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 tex = texture2D(baseTex, v_tex);
|
|
|
|
|
2012-04-10 23:08:54 +02:00
|
|
|
// Alpha-test as early as possible
|
|
|
|
#ifdef REQUIRE_ALPHA_GEQUAL
|
|
|
|
if (tex.a < REQUIRE_ALPHA_GEQUAL)
|
|
|
|
discard;
|
|
|
|
#endif
|
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_TRANSPARENT
|
2012-01-29 02:22:22 +01:00
|
|
|
gl_FragColor.a = tex.a;
|
|
|
|
#else
|
|
|
|
gl_FragColor.a = 1.0;
|
|
|
|
#endif
|
2012-02-25 18:29:27 +01:00
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
vec3 texdiffuse = tex.rgb;
|
2012-01-29 02:22:22 +01:00
|
|
|
|
2012-04-03 20:44:46 +02:00
|
|
|
// Apply-coloring based on texture alpha
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_OBJECTCOLOR
|
|
|
|
texdiffuse *= mix(objectColor, vec3(1.0, 1.0, 1.0), tex.a);
|
2012-04-03 20:44:46 +02:00
|
|
|
#else
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_PLAYERCOLOR
|
|
|
|
texdiffuse *= mix(playerColor, vec3(1.0, 1.0, 1.0), tex.a);
|
2012-04-03 20:44:46 +02:00
|
|
|
#endif
|
2012-01-29 02:22:22 +01:00
|
|
|
#endif
|
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
vec3 sundiffuse = v_lighting;
|
|
|
|
|
|
|
|
#if USE_SPECULAR
|
|
|
|
// Interpolated v_normal needs to be re-normalized since it varies
|
|
|
|
// significantly between adjacent vertexes;
|
|
|
|
// v_half changes very gradually so don't bother normalizing that
|
2012-04-09 01:03:22 +02:00
|
|
|
vec3 specular = sunColor * specularColor * pow(max(0.0, dot(normalize(v_normal), v_half)), specularPower);
|
2012-04-08 17:55:06 +02:00
|
|
|
#else
|
|
|
|
vec3 specular = vec3(0.0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vec3 color = (texdiffuse * sundiffuse + specular) * get_shadow() + texdiffuse * ambient;
|
|
|
|
|
2012-04-08 18:36:23 +02:00
|
|
|
#if !IGNORE_LOS
|
|
|
|
float los = texture2D(losTex, v_los).a;
|
|
|
|
color *= los;
|
|
|
|
#endif
|
2012-01-29 02:22:22 +01:00
|
|
|
|
|
|
|
color *= shadingColor;
|
2012-04-08 17:55:06 +02:00
|
|
|
|
2012-01-29 02:22:22 +01:00
|
|
|
gl_FragColor.rgb = color;
|
|
|
|
}
|