2D Shadows: Extended

Hello Readers!

I just continued working on the 2D shadows system, and implemented a box blur which creates the illusion of soft shadows.

The box blur is performed in this shader:

sampler2D shadowMap;

float4 PSShaderMain( float2 Tex : TEXCOORD0 ) : COLOR0
float texelWidth = 1.0/800;
float texelHeight = 1.0/600;

float4 Color = tex2D( shadowMap, Tex.xy);
/*Color += tex2D(shadowMap, float2(Tex.x-texelWidth, Tex.y-texelHeight));
Color += tex2D(shadowMap, float2(Tex.x, Tex.y-texelHeight));
Color += tex2D(shadowMap, float2(Tex.x+texelWidth, Tex.y-texelHeight));
Color += tex2D(shadowMap, float2(Tex.x+texelWidth, Tex.y));
Color += tex2D(shadowMap, float2(Tex.x+texelWidth, Tex.y+texelHeight));
Color += tex2D(shadowMap, float2(Tex.x, Tex.y+texelHeight));
Color += tex2D(shadowMap, float2(Tex.x-texelWidth, Tex.y+texelHeight));
Color += tex2D(shadowMap, float2(Tex.x-texelWidth, Tex.y));
Color = Color/9;*/

return Color;

And a few screenshots to illustrate (Click the images to view real size):
Before shader effect (zoomed in at shadow border):

After shader effect (zoomed in at shadow border):

Over-all view before:

Over-all view after:

You still see a bit of aliasing, thats because I needed to do a Gaussian blur and I did a box blur. Online they say when running the box blur three-times it produces a blur that looks strongly like Gaussian Blur. But I’m happy with the results now.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: