Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your help!

We need 1 more developer from Canada and 12 more from Australia to help us complete a research survey.

Support our site by taking a quick sponsored survey and win a chance at a $50 Amazon gift card. Click here to get started!


Average luminance (2x downsample) filter kernel


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Juliean   GDNet+   -  Reputation: 4238

Like
0Likes
Like

Posted 06 March 2014 - 11:00 AM

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?



Sponsor:

#2 theagentd   Members   -  Reputation: 740

Like
2Likes
Like

Posted 06 March 2014 - 06:48 PM

In your current implementation, you've written:

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

 

You're using vTexel.y twice. ^^



#3 Juliean   GDNet+   -  Reputation: 4238

Like
0Likes
Like

Posted 07 March 2014 - 04:37 AM


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?



#4 kalle_h   Members   -  Reputation: 2128

Like
3Likes
Like

Posted 07 March 2014 - 09:20 AM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS