0

我正在尝试编写一个模糊屏幕中心然后逐渐消失的后期处理着色器。

感谢此处发布的一些代码,我有一个模糊的抗锯齿圆圈,但它位于屏幕的左上角。问题似乎出在我计算圆的算法中:

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);
}

提前致谢!

4

1 回答 1

1

试试这个:

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
于 2013-01-05T02:38:41.010 回答