Jump to content
  • Advertisement
Sign in to follow this  
h3ro

Blur shader problem

This topic is 3027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
I feel very stupid now. The float thing was the problem. Cant believe I did not catch that myself. Thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!