Mysterious gaussian blur for bloom shader going wrong...

Started by
2 comments, last by w0dk4 14 years ago
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;
    }

    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;
    }

    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.
Advertisement
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;

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

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!

******************************************************************************************
Youtube Channel

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.
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]

This topic is closed to new replies.

Advertisement