Help DownSampling with HLSL

Started by
9 comments, last by josiah7 15 years, 10 months ago
I must be missing something. I want the image to move towards the average color.

If I add the colors of all surrounding texels using a 3x3 kernel, then write the average, shouldnt the entire image move torwards an average color over many iterations of such a filter?

Heres my 3x3 averaging filter:

float4 Average( float2 UV : TEXCOORD0 ) : COLOR0{  float TexelSize = 1.0f / imageWidth;   float3 color = 0.0f;   color += tex2D( sourceRT, UV + float2(  0.0f,       0.0f      )); // get the color of the texel  color += tex2D( sourceRT, UV + float2( -TexelSize,  0.0f      )); // add the color of the texel to left  color += tex2D( sourceRT, UV + float2(  TexelSize,  0.0f      )); // add the color of the texel to right  color += tex2D( sourceRT, UV + float2(  0.0f,      -TexelSize )); // add the color of the texel below  color += tex2D( sourceRT, UV + float2(  0.0f,       TexelSize )); // add the color of the texel above  color += tex2D( sourceRT, UV + float2( -TexelSize, -TexelSize )); // add the color of the texel lower left  color += tex2D( sourceRT, UV + float2(  TexelSize, -TexelSize )); // add the color of the texel lower right  color += tex2D( sourceRT, UV + float2( -TexelSize,  TexelSize )); // add the color of the texel upper left  color += tex2D( sourceRT, UV + float2(  TexelSize,  TexelSize )); // add the color of the texel upper right   float3 average = color / 9.0f;  // divide by 9 to get the average of the 9 samples   return float4(average, 1.0f); }



On the left is unprocessed. On the right with 10 iterations of the filter.

I would think this would produce an image containing colors moving toward the average of all the colors in the original after a few iterations. But after 10, I only get a very slight blur.

What gives?

[Edited by - josiah7 on June 25, 2008 7:46:58 PM]

This topic is closed to new replies.

Advertisement