Jump to content
  • Advertisement
Sign in to follow this  
Juliean

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement

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 this post


Link to post
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 this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!