Sign in to follow this  
h3ro

Blur shader problem

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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this