Recommended Posts

Hallo, I am having some problems with my very basic blur shader, and was wondering if anyone could lend me a hand? pixelSizeX is 1 / width of the sprite, pixelSizeY is 1 / height of the sprite. When I try to use it, the sprite renders correctly, but there is no blur at all, turning it up to something like 10 samples still produces no blur.
float4 BlurPixel(int nSamples, float x, float y, sampler textureSampler)
{
float startX = x - ((nSamples * 0.5) * pixelSizeX);
float startY = y - ((nSamples * 0.5) * pixelSizeY);

float4 color = float4(0,0,0,0);
for(int i = 0; i < nSamples; i++)
{
for(int j = 0; j < nSamples; j++)
{
float coordX = startX + (pixelSizeX * j);
float coordY = startY + (pixelSizeY * i);

color += tex2D(textureSampler, float2(coordX, coordY));
}
}

return color / (nSamples * nSamples);
}



Share on other sites
Things look fine at first glance. Like Decibit requested, you may need to post a little more for us to be helpful. The only questions that come to mind are:

1) Are pixelSizeX/Y floats?
2) If yes, when setting them are you doing 1 / width with width being an integer? If so, you probably want to be doing 1.0f / width instead. This would perhaps explain why you see no blur, since pixelSizeX/Y will be 0 and every sample will be from the same pixel.

Share on other sites
I feel very stupid now. The float thing was the problem. Cant believe I did not catch that myself. Thanks!

Create an account

Register a new account

• Forum Statistics

• Total Topics
628400
• Total Posts
2982449

• 9
• 10
• 9
• 19
• 24