Sign in to follow this  

Mysterious gaussian blur for bloom shader going wrong...

This topic is 2790 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

Hello there, I have a very weird problem where I really doubt wether Im seeing things clearly, so please have a look if Im doing something obviously wrong here. So, I got a scene rendered to the backbuffer, I stretchrect it to a 4 times smaller texture. Now I apply a brightpass, rendering to a new texture of the same size: So, now I'll apply the following gaussian blur, as found on many sources on the internet, to blur the texture, in order for the highlighted parts to shine over the X-Wings front. Only that it does the exact opposite, it actually blurs inwards:
float g_blurRadiusX;
float g_blurRadiusY;

static const int kernelSize = 9;

//Blur Weights
static const float BlurWeights[kernelSize] = 
{
	0.05f,
	0.09f,
	0.12f,
	0.15f,
	0.16f,
	0.15f,
	0.12f,
	0.09f,
	0.05f
}; 

float4 BlurH_PS( VS_OUTPUT In ) : COLOR0
{ 
	
	float4 color = 0;
    float2 texCoord = In.TextureUV;

    for (int i = 0; i < kernelSize; i++)
    {    
		texCoord.x = In.TextureUV.x + ((i-4)*g_blurRadiusX);
		color += tex2D(Tex0Sampler, texCoord) * BlurWeights[i];
    }

    return color;
}

float4 BlurV_PS( VS_OUTPUT In ) : COLOR0
{ 
	
	float4 color = 0;
    float2 texCoord = In.TextureUV;

	for (int i = 0; i < kernelSize; i++)
    {    
		texCoord.y = In.TextureUV.y + ((i-4)*g_blurRadiusY);
		color += tex2D(Tex0Sampler, texCoord) * BlurWeights[i];
    }

    return color;
}

(blurRadiusX is 1/TexWidth and so on) Anybody might have any idea on whats going on here? A note: After I rendered the brightpass, I use the downsample texture as a rendertarget, and so on. So I dont always create a new texture, but reuse the old ones, after Clearing them with 0 0 0 0.

Share this post


Link to post
Share on other sites
I would suspect this line but don't quote me on it ;), in the pixel shader. Im a bit rusty with shaders so I may be talking out of my behind...

color += tex2D(Tex0Sampler, texCoord) * BlurWeights[i];

Try
color += tex2D(Tex0Sampler, texCoord) + BlurWeights[i];

You can contact me on MSN, it's a little easier if I have working code to test with, btw, nice to see you on Game Dev!

Share this post


Link to post
Share on other sites
I'm not actually sure I understand what the problem is yet.

At first glance, the code looks alright.

Do the images go (from left to right, and up to do) original, brightpass, blur one direction, blur other direction? They might be a little small to see much.

Share this post


Link to post
Share on other sites
Yeah, they go from the left to the right.

Anyways, I found what the issue was. For some reason, I was using 64bit floating point textures. Switching to D3DFMT_A8R8G8B8 completely solved the issue. Im not sure why though.

/oh hi LS :)

[Edited by - w0dk4 on April 25, 2010 8:52:26 AM]

Share this post


Link to post
Share on other sites

This topic is 2790 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.

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