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-08-06 21:10:47 +02:00
|
|
|
uniform sampler2D aoTex;
|
|
|
|
uniform sampler2D normTex;
|
|
|
|
uniform sampler2D specTex;
|
2012-03-19 22:10:14 +01:00
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_SHADOW
|
2012-08-06 21:10:47 +02:00
|
|
|
varying vec4 v_shadow;
|
2012-04-08 17:55:06 +02:00
|
|
|
#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-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;
|
2012-08-06 21:10:47 +02:00
|
|
|
uniform vec3 sunColor;
|
|
|
|
uniform vec3 sunDir;
|
2012-01-29 02:22:22 +01:00
|
|
|
|
2012-08-06 21:10:47 +02:00
|
|
|
varying vec4 v_lighting;
|
2012-01-29 02:22:22 +01:00
|
|
|
varying vec2 v_tex;
|
|
|
|
varying vec2 v_los;
|
|
|
|
|
2012-08-06 21:10:47 +02:00
|
|
|
#if USE_INSTANCING && USE_AO
|
|
|
|
varying vec2 v_tex2;
|
|
|
|
#endif
|
|
|
|
|
2012-04-08 17:55:06 +02:00
|
|
|
#if USE_SPECULAR
|
|
|
|
uniform float specularPower;
|
|
|
|
uniform vec3 specularColor;
|
|
|
|
#endif
|
|
|
|
|
2012-08-06 21:10:47 +02:00
|
|
|
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP || USE_AO
|
|
|
|
uniform vec4 effectSettings;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_SPECULAR || USE_NORMAL_MAP || USE_SPECULAR_MAP || USE_PARALLAX_MAP
|
|
|
|
varying vec4 v_normal;
|
|
|
|
#if USE_INSTANCING && (USE_NORMAL_MAP || USE_PARALLAX_MAP)
|
|
|
|
varying vec4 v_tangent;
|
|
|
|
//varying vec3 v_bitangent;
|
|
|
|
#endif
|
|
|
|
#if USE_SPECULAR || USE_SPECULAR_MAP
|
|
|
|
varying vec3 v_half;
|
|
|
|
#endif
|
|
|
|
#if USE_INSTANCING && USE_PARALLAX_MAP
|
|
|
|
varying vec3 v_eyeVec;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2012-03-19 22:10:14 +01:00
|
|
|
float get_shadow()
|
|
|
|
{
|
2012-04-14 19:32:22 +02:00
|
|
|
#if USE_SHADOW && !DISABLE_RECEIVE_SHADOWS
|
2012-04-08 17:55:06 +02:00
|
|
|
#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
|
|
|
void main()
|
|
|
|
{
|
2012-08-06 21:10:47 +02:00
|
|
|
vec2 coord = v_tex;
|
|
|
|
|
|
|
|
#if USE_PARALLAX_MAP || USE_NORMAL_MAP
|
|
|
|
vec3 bitangent = vec3(v_normal.w, v_tangent.w, v_lighting.w);
|
|
|
|
mat3 tbn = mat3(v_tangent.xyz, bitangent, v_normal.xyz);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if USE_PARALLAX_MAP
|
|
|
|
{
|
|
|
|
float h = texture2D(normTex, coord).a;
|
|
|
|
|
|
|
|
vec3 eyeDir = normalize(v_eyeVec * tbn);
|
|
|
|
float dist = length(v_eyeVec);
|
|
|
|
|
|
|
|
float s;
|
|
|
|
vec2 move;
|
|
|
|
float height = 1.0;
|
|
|
|
float scale = effectSettings.z;
|
|
|
|
|
|
|
|
scale = (scale * (PARALLAX_DIST_MAX - dist)) / PARALLAX_DIST_MAX;
|
|
|
|
|
|
|
|
float iter = 8.0;
|
|
|
|
#if USE_HQ_PARALLAX
|
|
|
|
iter = 16.0;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
s = 1.0 / iter;
|
|
|
|
move = vec2(-eyeDir.x, eyeDir.y) * scale / (eyeDir.z * iter);
|
|
|
|
vec2 nil = vec2(0.0);
|
|
|
|
|
|
|
|
#define PARALLAX_ITER {\
|
|
|
|
height -= s;\
|
|
|
|
vec2 temp = (h < height) ? move : nil;\
|
|
|
|
coord += temp;\
|
|
|
|
h = texture2D(normTex, coord).a;\
|
|
|
|
}
|
|
|
|
|
|
|
|
// 8 iterations of parallax
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
|
|
|
|
// an additional 8 iterations for the HQ parallax
|
|
|
|
#if USE_HQ_PARALLAX
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
PARALLAX_ITER
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vec4 tex = texture2D(baseTex, coord);
|
2012-01-29 02:22:22 +01:00
|
|
|
|
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-08-06 21:10:47 +02:00
|
|
|
#if USE_SPECULAR || USE_SPECULAR_MAP || USE_NORMAL_MAP
|
|
|
|
vec3 normal = v_normal.xyz;
|
|
|
|
#endif
|
2012-04-08 17:55:06 +02:00
|
|
|
|
2012-08-06 21:10:47 +02:00
|
|
|
#if USE_INSTANCING && USE_NORMAL_MAP
|
|
|
|
vec3 ntex = texture2D(normTex, coord).rgb * 2.0 - 1.0;
|
|
|
|
ntex.y = -ntex.y;
|
|
|
|
normal = normalize(tbn * ntex);
|
|
|
|
vec3 bumplight = max(dot(-sunDir, normal), 0.0) * sunColor;
|
|
|
|
vec3 sundiffuse = (bumplight - v_lighting.rgb) * effectSettings.x + v_lighting.rgb;
|
2012-04-08 17:55:06 +02:00
|
|
|
#else
|
2012-08-06 21:10:47 +02:00
|
|
|
vec3 sundiffuse = v_lighting.rgb;
|
2012-04-08 17:55:06 +02:00
|
|
|
#endif
|
|
|
|
|
2012-08-06 21:10:47 +02:00
|
|
|
vec4 specular = vec4(0.0);
|
|
|
|
#if USE_SPECULAR || USE_SPECULAR_MAP
|
|
|
|
vec3 specCol;
|
|
|
|
float specPow;
|
|
|
|
#if USE_INSTANCING && USE_SPECULAR_MAP
|
|
|
|
vec4 s = texture2D(specTex, coord);
|
|
|
|
specCol = s.rgb;
|
|
|
|
specular.a = s.a;
|
|
|
|
specPow = effectSettings.y;
|
|
|
|
#else
|
|
|
|
specCol = specularColor;
|
|
|
|
specPow = specularPower;
|
|
|
|
#endif
|
|
|
|
specular.rgb = sunColor * specCol * pow(max(0.0, dot(normalize(normal), v_half)), specPow);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
vec3 color = (texdiffuse * sundiffuse + specular.rgb) * get_shadow();
|
|
|
|
vec3 ambColor = texdiffuse * ambient;
|
|
|
|
|
|
|
|
#if USE_INSTANCING && USE_AO
|
|
|
|
vec3 ao = texture2D(aoTex, v_tex2).rrr;
|
|
|
|
ao = mix(vec3(1.0), ao * 2.0, effectSettings.w);
|
|
|
|
ambColor *= ao;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
color += ambColor;
|
|
|
|
|
|
|
|
#if USE_INSTANCING && USE_SPECULAR_MAP && USE_SELF_LIGHT
|
|
|
|
color = mix(texdiffuse, color, specular.a);
|
|
|
|
#endif
|
2012-04-08 17:55:06 +02:00
|
|
|
|
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;
|
|
|
|
}
|