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-02-25 18:29:27 +01:00
|
|
|
uniform sampler2D blendTex;
|
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;
|
2012-05-21 21:23:14 +02:00
|
|
|
#if USE_SHADOW_PCF
|
|
|
|
uniform vec4 shadowScale;
|
|
|
|
#endif
|
2012-03-19 22:10:14 +01:00
|
|
|
#else
|
|
|
|
uniform sampler2D shadowTex;
|
|
|
|
#endif
|
2012-02-25 18:29:27 +01:00
|
|
|
#endif
|
2012-03-19 22:10:14 +01:00
|
|
|
|
2012-01-29 02:22:22 +01:00
|
|
|
uniform vec3 shadingColor;
|
|
|
|
uniform vec3 ambient;
|
|
|
|
|
|
|
|
varying vec3 v_lighting;
|
|
|
|
varying vec2 v_tex;
|
|
|
|
varying vec4 v_shadow;
|
|
|
|
varying vec2 v_los;
|
2012-02-25 18:29:27 +01:00
|
|
|
varying vec2 v_blend;
|
2012-01-29 02:22:22 +01:00
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_SPECULAR
|
|
|
|
uniform float specularPower;
|
|
|
|
uniform vec3 specularColor;
|
|
|
|
varying vec3 v_normal;
|
|
|
|
varying vec3 v_half;
|
|
|
|
#endif
|
|
|
|
|
2012-03-19 22:10:14 +01:00
|
|
|
float get_shadow()
|
2012-01-29 02:22:22 +01:00
|
|
|
{
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_SHADOW
|
|
|
|
#if USE_SHADOW_SAMPLER
|
|
|
|
#if USE_SHADOW_PCF
|
2012-05-21 21:23:14 +02:00
|
|
|
vec2 offset = fract(v_shadow.xy - 0.5);
|
|
|
|
vec4 size = vec4(offset + 1.0, 2.0 - offset);
|
|
|
|
vec4 weight = (vec4(2.0 - 1.0 / size.xy, 1.0 / size.zw - 1.0) + (v_shadow.xy - offset).xyxy) * shadowScale.zwzw;
|
|
|
|
return (1.0/9.0)*dot(size.zxzx*size.wwyy,
|
2012-08-06 21:10:47 +02:00
|
|
|
vec4(shadow2D(shadowTex, vec3(weight.zw, v_shadow.z)).r,
|
|
|
|
shadow2D(shadowTex, vec3(weight.xw, v_shadow.z)).r,
|
|
|
|
shadow2D(shadowTex, vec3(weight.zy, v_shadow.z)).r,
|
|
|
|
shadow2D(shadowTex, vec3(weight.xy, v_shadow.z)).r));
|
2012-03-19 22:10:14 +01:00
|
|
|
#else
|
2012-08-06 21:10:47 +02:00
|
|
|
return shadow2D(shadowTex, v_shadow.xyz).r;
|
2012-03-19 22:10:14 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
if (v_shadow.z >= 1.0)
|
|
|
|
return 1.0;
|
2012-05-21 21:23:14 +02:00
|
|
|
return (v_shadow.z <= texture2D(shadowTex, v_shadow.xy).x ? 1.0 : 0.0);
|
2012-03-19 22:10:14 +01:00
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
return 1.0;
|
|
|
|
#endif
|
|
|
|
}
|
2012-01-29 02:22:22 +01:00
|
|
|
|
2012-03-19 22:10:14 +01:00
|
|
|
void main()
|
|
|
|
{
|
2012-04-08 17:55:06 +02:00
|
|
|
#if BLEND
|
2012-02-25 18:29:27 +01:00
|
|
|
// Use alpha from blend texture
|
|
|
|
gl_FragColor.a = 1.0 - texture2D(blendTex, v_blend).a;
|
2012-01-29 02:22:22 +01:00
|
|
|
#endif
|
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
vec4 tex = texture2D(baseTex, v_tex);
|
2012-01-29 02:22:22 +01:00
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if DECAL
|
2012-02-25 18:29:27 +01:00
|
|
|
// Use alpha from main texture
|
2012-04-08 17:55:06 +02:00
|
|
|
gl_FragColor.a = tex.a;
|
2012-01-29 02:22:22 +01:00
|
|
|
#endif
|
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
vec3 texdiffuse = tex.rgb;
|
|
|
|
vec3 sundiffuse = v_lighting;
|
|
|
|
|
|
|
|
#if USE_SPECULAR
|
|
|
|
// Interpolated v_normal needs to be re-normalized since it varies
|
|
|
|
// significantly between adjacenent vertexes;
|
|
|
|
// v_half changes very gradually so don't bother normalizing that
|
|
|
|
vec3 specular = specularColor * pow(max(0.0, dot(normalize(v_normal), v_half)), specularPower);
|
|
|
|
#else
|
|
|
|
vec3 specular = vec3(0.0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vec3 color = (texdiffuse * sundiffuse + specular) * get_shadow() + texdiffuse * ambient;
|
|
|
|
|
|
|
|
float los = texture2D(losTex, v_los).a;
|
|
|
|
color *= los;
|
2012-01-29 02:22:22 +01:00
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if DECAL
|
|
|
|
color *= shadingColor;
|
2012-02-25 18:29:27 +01:00
|
|
|
#endif
|
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
gl_FragColor.rgb = color;
|
2012-01-29 02:22:22 +01:00
|
|
|
}
|