This topic is 4345 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I'm new to shaders (just started looking at them Monday) so excuse me if I sound like I don't know what I'm talking about. I'm trying to implement soft shadows using a post-processing shader on my shadow map. I found a Poisson shadow blur algorithm in the book ShaderX3 and it looked like the perfect solution. It does make my shadows look much better (realistic) but there is still an edge to the shadow which is what I'm trying to get rid of (is there no way to post screen shots?). Basically, the idea is, the shadow "texture" is sampled at each vertex using a Poisson distribution around that vertex. An output color value is then calculated based on the color of the samples. Here is the shader I've written:
texture sgv_blurTexture;

float4	sgv_screenToTexture;

#define NUM_BLUR_TAPS 12

float2 filterTaps[NUM_BLUR_TAPS] = {{-0.326212f, -0.405805f},
{-0.840144f, -0.07358f},
{-0.695914f,  0.457137f},
{-0.203345f,  0.620716f},
{ 0.96234f,  -0.194983f},
{ 0.473434f, -0.480026f},
{ 0.519456f,  0.767022f},
{ 0.185461f, -0.893124f},
{ 0.507431f,  0.064425f},
{ 0.89642f,   0.412458f},
{-0.32194f,  -0.932615f},
{-0.791559f, -0.597705f}};

sampler SourceSampler =
sampler_state
{
Texture = <sgv_blurTexture>;
//MipFilter = LINEAR;
//MinFilter = LINEAR;
//MagFilter = LINEAR;
};

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
struct VS_OUTPUT
{
float4 position					: POSITION;
float2 tc0   					: TEXCOORD0;
};

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
struct PS_OUTPUT
{
float4 RGBColor : COLOR0;  // Pixel color
};

PS_OUTPUT ps_blur(VS_OUTPUT vOut)
{
PS_OUTPUT output;

float colorSum = 0.0f;
float fScale = 0.02f;

for(int i = 0; i < NUM_BLUR_TAPS; i++)
{
float2 tapCoord = vOut.tc0 + filterTaps * fScale * (1.0f - vOut.tc0.y);

float tapColor = tex2D(SourceSampler, tapCoord);

colorSum += tapColor;
}

float finalColor = colorSum/NUM_BLUR_TAPS;

output.RGBColor = float4 (finalColor, finalColor, finalColor, finalColor);

return output;
}

VS_OUTPUT vs_Blur(  float4 vPos : POSITION )
{
VS_OUTPUT output;

float2 uvBase = vPos.xy * sgv_screenToTexture.xy + sgv_screenToTexture.zw;

output.position = vPos;
output.tc0 = uvBase;

return output;
}

technique BLUR_GPU
<int priority=5; >
{
pass P0
{
FogEnable=false;
FogTableMode=None;
FogVertexMode=None;

CullMode = None; // ??

ColorWriteEnable=Red|Green|Blue;

AlphaBlendEnable=false;
SrcBlend=One;
DestBlend=Zero;
AlphaTestEnable=false;
AlphaFunc=Greater;
AlphaRef=0;

ZEnable=false;
ZFunc=LessEqual;
ZWriteEnable=false;

}
}

technique BLUR_CPU
<int priority=0; int NoOp=1; >// CPU Version
{
pass P0
{
}
}


Any ideas on how to tweak this to get rid of the hard edge on my shadow? Any ideas to improve this shader in general? [Edited by - doja93 on March 30, 2006 12:20:55 PM]

##### Share on other sites
Well, it turns out I answered my own question. The shader is actually working correctly on the shadow map. There is just another part of my engine that is culling the shadow map so that it is rendered incorrectly i.e. if I view the shadow map rendered to a bitmap it looks correct (soft shadowing) but rendered in game it looks incorrect.

Just wanted to post and let people know that the shader itself works great. Credit to Jason L. Mitchell for the basic Poisson blur algorithm.