Jump to content
  • Advertisement
Sign in to follow this  
adriansnetlis

Approximate Average Brightness Of Rendered Image

This topic is 711 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

So in GLSL shader I have an FBO RGB image. What I need to find out is how bright it is. I need to do it real-time inside shader. How to do it?

Share this post


Link to post
Share on other sites
Advertisement

Generate mips. The bottom mip level is the average value.

 

That'd be the average RGB, wouldn't it? If the mipmap doesn't do anything fancy, and just averages each channel independently, you could take that value and then apply some multipliers to get the "brightness".

 

@OP: the three different color-channels contribute different values to what humans consider "brightness", since our eyes deal with the color channels differently.

 

In my code I use something like:

float brightness = (red * 0.21f) + (green * 0.71f) + (blue * 0.07f);

...which only adds up to 0.99.  :ph34r:

 

But here's some more accurate numbers.

Share this post


Link to post
Share on other sites

Yeah, you can do the dot product after mipping, or you can do it beforehand (into a single-channel texture) and then mip that.

 

If this is for HDR, the geometric mean is often more useful / representative. You can compute it by doing the dot first, then a log (into a single channel texture), then mipping down to 1x1, then an exp to undo the log.

Share this post


Link to post
Share on other sites

Yeah, you can do the dot product after mipping, or you can do it beforehand (into a single-channel texture) and then mip that.

 

If this is for HDR, the geometric mean is often more useful / representative. You can compute it by doing the dot first, then a log (into a single channel texture), then mipping down to 1x1, then an exp to undo the log.

But don't forget to add a black offset (you don't want to add any -infinity values into your average)

Share this post


Link to post
Share on other sites

Phuh... That's a complex thing. I don't know how to access mipmaps, I'm not such experienced. I just do some simple experiments.

Within a shader you can simply use textureLod (with a sufficiently high value for the lod) to access specific mipmap levels.

Share this post


Link to post
Share on other sites

Thanks for info. What versions of GLSL does it work in? It also seems to be a good thing for blur, right?

 

Another question:

In # version 120 and older there was a gl_TexCoord[0] param. That's all nice. In next version it got removed. For meshes this is fine as I can just use texture coordinate attribute. However, how do I find out the current texture coordinates in a 2D filter?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!