# Average luminance (2x downsample) filter kernel

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

## Recommended Posts

Hello,

a while ago I posted a thread about some problems regarding the calculation of the average lumiance from a texture. Although the mipmaps where generated correctly, only the mid-image area was taking into consideration for the average luminance. I was using automatic mip-generation for this, and appearently this was the problem. Now I've changed to manual 2 x downsampling with block-filter, but I can't figure out the correct filter kernel. With this current implementation:

		out.vColor = Sample(Luminance, in.vTex0);
out.vColor += Sample(Luminance, in.vTex0 + float2(vTexel.y, vTexel.y));
out.vColor += Sample(Luminance, in.vTex0 + float2(vTexel.x, 0.0f));
out.vColor += Sample(Luminance, in.vTex0 + float2(0.0f, vTexel.y));
out.vColor /= 4.0f;


I get "jittering" behaviour in areas with movement, and there are some spots in a scene where if I look at the scene gets eigther too bright or too dark. I also tried:

		out.vColor = Sample(Luminance, in.vTex0);
out.vColor += Sample(Luminance, in.vTex0 + float2(vTexel.x, 0.0f));
out.vColor += Sample(Luminance, in.vTex0 + float2(-vTexel.x, 0.0f));
out.vColor += Sample(Luminance, in.vTex0 + float2(0.0f, vTexel.y));
out.vColor += Sample(Luminance, in.vTex0 + float2(0.0f, -vTexel.y));
out.vColor /= 5.0f;


which didn't improve much, eigther than make the scene much too bright. I searched a while but didn't find any resources how to calculate this correctly. Any ideas?

##### Share on other sites

In your current implementation, you've written:

out.vColor += Sample(Luminance, in.vTex0 + float2(vTexel.y, vTexel.y));

You're using vTexel.y twice. ^^

##### Share on other sites

You're using vTexel.y twice. ^^

Oh wow, thanks a lot, I really didn't notice that at all. Was not the only part of the problem though, I also have been passing in the wrong texels (target texture size, instead of input texture), and that almost fixes it. There is still one catch though, since I downscale the textures by the factor of 2:

2560x1600

1280x800

...

10x6

5x3

2x1

1x1

In that jump from 5x3 to 2x1 both x and y looses one pixel, which still uses only the pixels in the middle area of the screen. Though its a lot better already since the rest of the scene is at least taken into consideration up until this point, but its still not perfect. Any ideas for that?

##### Share on other sites

You could go from 5x3  to 1x1 using simple gather shader. Performance should be even better.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 15
• 21
• 26
• 11