2013-01-04 51 views
0

我正在嘗試編寫一個後期處理着色器,它可以模糊屏幕的中心,然後逐漸消失。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

試試這個:

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 
+0

這做到了!萬分感謝! – Michael