0
votes

I'm trying to write a post process shader that blurs the center of the screen and then gradually dies off.

Thanks to some code posted on here I have an anti-aliased circle being blurred, but it is in the top left of the screen. The problem seems to be in my algorithm for calculating the circle:

float4 PS_GaussianBlur(float2 texCoord : TEXCOORD) : COLOR0
{
float4 insideColor = float4(0.0f, 0.0f, 0.0f, 0.0f);
float4 outsideColor = tex2D(colorMap, texCoord);

//Perform the blur:
for (int i = 0; i < KERNEL_SIZE; ++i)
    insideColor += tex2D(colorMap, texCoord + offsets[i]) * weights[i];

float dist = (texCoord.x * texCoord.x) + (texCoord.y * texCoord.y);
float distFromCenter = .5 - dist;  // positive when inside the circle
float thresholdWidth = 0.1;  // a constant you'd tune to get the right level of softness
float antialiasedCircle = saturate((distFromCenter / thresholdWidth) + 0.5);
return lerp(outsideColor, insideColor, antialiasedCircle);
}

Thanks in advance!

1

1 Answers

1
votes

Try this:

float dx = 0.5 - texCoord.x, dy = 0.5 - texCoord.y;
float dist = dx * dx + dy * dy;
float distFromCenter = 0.25 - dist;  // positive when inside the circle