HLSL:绘制一个居中的圆圈

时间:2013-01-04 17:18:26

标签: hlsl

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

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

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

提前致谢!

1 个答案:

答案 0 :(得分: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