Just throwing this out there for anyone working on making this better.
Some observations about the current BSR.
- The texture size is hardcoded into Shadow.glsl at 1024… and the BSR allows you to set the texture size. This would not produce good results.
- It uses stepping instead of smooth stepping for the shadow creation. It makes sense in the border check… but not so much in DoShadowCompareOffset.
Here be a video of the results with the new frag shader… it implements smoothstep, passing in the shadow texture size and some blending trickery to help minimize artifacting without the use of multisampling. Personally, I think this has a LONG way to go, and I won’t end up using this as it doesn’t work well with small scale models. Below is the frag shader updates… feel free to build off of it as this is as far as I am going with it.
http://youtu.be/XkVwz6Sryhc
PostShadow.frag
[java]#ifdef NO_SHADOW2DPROJ
#define SHADOWMAP sampler2D
#define SHADOWTEX texture2D
#define SHADCOORD(coord) coord.xy
#else
#define SHADOWMAP sampler2DShadow
#define SHADOWTEX shadow2D
#define SHADCOORD(coord) vec3(coord.xy,0.0)
#endif
uniform float m_TexSize;
float pixSize = 0.0;
vec2 pixSize2 = vec2(0.0);
float Shadow_DoShadowCompareOffset(in SHADOWMAP tex, vec4 projCoord, vec2 offset){
float sStep = SHADOWTEX(tex, SHADCOORD(projCoord.xy + offset * pixSize2)).r;
return smoothstep(projCoord.z-0.00025,projCoord.z+0.000025,sStep);
}
float Shadow_BorderCheck(in vec2 coord){
vec4 t = vec4(coord.xy, 0.0, 1.0);
t = step(t.wwxy, t.xyzz);
return dot(t,t*0.999);
}
float Shadow_DoPCF_2x2(in SHADOWMAP tex, in vec4 projCoord){
float shadow = 0.0;
float x,y;
for (y = -3.0 ; y <= 3.0 ; y+=1.5)
for (x = -3.0 ; x <:3.0 ; x+=1.5)
shadow += clamp(Shadow_DoShadowCompareOffset(tex,projCoord,vec2(x,y)) +
Shadow_BorderCheck(projCoord.xy),
0.0, 1.0);
shadow /= 25.0;
return shadow;
}
uniform SHADOWMAP m_ShadowMap;
varying vec4 projCoord;
void main() {
pixSize = 1.0 / m_TexSize;
pixSize2 = vec2(pixSize);
vec4 coord = projCoord;
float shadow = Shadow_DoPCF_2x2(m_ShadowMap,coord);
float shadow2 = shadow;
if (shadow < 1.0) shadow *= 1.5;
if (shadow > 0.15) shadow = 1.0;
if (shadow2 < 1.0) shadow2 *= 1.25;
if (shadow2 > 0.75) shadow2 = 1.0;
float finalShadow = mix(shadow,shadow2,0.5);
finalShadow *= 1.35;
finalShadow = mix(finalShadow,1.0,0.5);
gl_FragColor = vec4(vec3(finalShadow),1.0);
}[/java]