Blur shader problem

Started by
2 comments, last by h3ro 14 years, 1 month ago
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);
}

Advertisement
Could you please post the entire shader (effect)?
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.
I feel very stupid now. The float thing was the problem. Cant believe I did not catch that myself. Thanks!

This topic is closed to new replies.

Advertisement