# Iterating to enanche gaussian blur will darken my image :(

3 replies to this topic

### #1SuperPixel

Valued Member

• Members
• 306 posts

Posted 19 July 2012 - 04:30 PM

Hi all,

I'm performing gaussian blur with a 9 taps filter and I use bilinear filtering in turn to reduce the number of taps (i.e. getting two sample at once thanks to hw filtering..., so using just half of the taps [9/2]+1).

If I iterate over the previous blurred result to get more blur on the resulting image, the image itself gets darker and darker as the number of iterations raise ... until it gets completely black ...

Why this behaviour ?

Note: I've calculated my weights from the pascal triangle and normalized them, also the tex coords offset will reflect the border of the pixel to account for the fact that I'm using bilinear filtering to read more sample at once.

I show just the horizontal pass pixel shader source:

static const float weight[3]  = {0.2270270270,0.3162162162,0.0702702703};
static const float offsets[3] = {0.0,1.3846153846,3.2307692308};
//perform horizontal blur
static const float2 invImageSize  = float2(1.f/1000.f,1.f/800.f);
static const float  downsampledLevel = 0.f;
float4 PSBlurH(VS_OUTPUT Input) : SV_Target{
float3 color	= colorTexture.SampleLevel(textureSampler,Input.tc*invImageSize,downsampledLevel).xyz*weight[0];
[unroll]
for(int i=1;i<3;++i){
color += colorTexture.SampleLevel(textureSampler,Input.tc+float2(offsets[i]*invImageSize.x,0.f),downsampledLevel).xyz*weight[i];
color += colorTexture.SampleLevel(textureSampler,Input.tc-float2(offsets[i]*invImageSize.x,0.f),downsampledLevel).xyz*weight[i];
}
return float4(color,1.f);
}


It seems that the background color is influencing the cube ... :/

### #2Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 19 July 2012 - 05:53 PM

Weird. The code snippet you posted looks fine to me. Are you sure you don't have blending enabled or something odd like that? That could also explain the cube picking up the background color.
reedbeta.com - developer blog, OpenGL demos, and other projects

### #3SuperPixel

Valued Member

• Members
• 306 posts

Posted 19 July 2012 - 06:02 PM

Reedbeta, on 19 July 2012 - 05:53 PM, said:

Weird. The code snippet you posted looks fine to me. Are you sure you don't have blending enabled or something odd like that? That could also explain the cube picking up the background color.

I disable blending do default setting OMSetBlendState to null, it will reset to default blend ... mmmm or maybe I should specify explicitly that with a specific blend state ?

I use this code for the fullscreen quad, which actually draws a quad that is bigger than the viewport such that one triangle of the two will be enough to fill the entire viewport.

// ouputs a full screen quad with tex coords
VS_OUTPUT Out;
Out.tc	   = float2( (VertexID << 1) & 2, VertexID & 2 );
Out.hpos	 = float4( Out.tc * float2( 2.f, -2.f ) + float2( -1.f, 1.f), 0.f, 1.f );
return Out;
}


### #4SuperPixel

Valued Member

• Members
• 306 posts

Posted 19 July 2012 - 07:47 PM

SuperPixel, on 19 July 2012 - 06:02 PM, said:

I disable blending do default setting OMSetBlendState to null, it will reset to default blend ... mmmm or maybe I should specify explicitly that with a specific blend state ?

I use this code for the fullscreen quad, which actually draws a quad that is bigger than the viewport such that one triangle of the two will be enough to fill the entire viewport.

// ouputs a full screen quad with tex coords
VS_OUTPUT Out;
Out.tc	   = float2( (VertexID << 1) & 2, VertexID & 2 );
Out.hpos	 = float4( Out.tc * float2( 2.f, -2.f ) + float2( -1.f, 1.f), 0.f, 1.f );
return Out;
}


Fixed !

It came out that I wasn't sampling from the center of the pixel on ...

thanks anyway

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users