# 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.

## 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 on other sites

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

##### Share on other sites

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:

##### 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 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 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.

##### 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 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 on other sites
You can use gl_FragCoord to get the window coordinates in the fragment shader. Edited by kloffy

##### Share on other sites

Not in # version 130 and above. Instead I found that # version 150 compatibility works fine.

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 35
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001808
×