How do I get average luminosity of the scene?

solving problems with low performance
Post Reply
  • Author
  • Message
Offline
*sensei*
Posts: 372
Joined: 28 Jul 2013, 23:26

How do I get average luminosity of the scene?

Does anyone know if there is a technique to downsample scene to a 1x1 texture to use for proper average luminosity calculation for use in tonemapping and adaptation? -- yes, from within pixel shader.

Running it in pixel shader just gets me average luminosity of the pixel or texture, which returns weird results.. example; only certain parts of the trees will become darker when looking at the sun, instead of the entire tree, or ground will stay too bright.

I'm looking for ways to improve tonemapping and adaptation, but limitation in getting accurate scene averages is holding a bit back.... unless I misunderstand something. As far as I understand it requires some changes to deliver a downsampled texture, which cannot be done through pixel shader alone.

Thank you kindly.

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17450
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: How do I get average luminosity of the scene?

Average is not the best while working with hdr data, small bright spot will make average level too high. I tweaked math of adaptation blending to game vanilla weathers (without post processing) to make adaptation natural to human eye, so when fire in the darkness, it not affect everything negatively, but sky do. The less you bother with this, the less pain with tweaking other things. I always start tweaking from setting sun intensity and adaptation limits, then lights. Or take as base values standart ldr look of the game lighting, make it the same, but modify everything else, but again adaptation is one of the first (perfect adaptation is when sun looks properly as human see it, but darkness in games is different, so upper limit of adaptation matter the most).
Well, enough that blah-blah-blah mr freeman, to make adaptation computation draw pixel in corner of screen or line, it's very simple actually and was done many times, ask f.e. gta4 users or search already made shaders which reading data of entire screen and write to edge/corner.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
*sensei*
Posts: 372
Joined: 28 Jul 2013, 23:26

Re: How do I get average luminosity of the scene?

Hey Boris,
So if I understand well using tex2D(_s4, IN.txcoord0.xy) alone will already give me proper results in calculating different methods of tonemapping or adaptation? I currently add _s2 and _s4 together.

Example;

float3 Adaptation = tex2D(_s4, IN.txcoord0.xy);
float3 LumCoeff = {0.299, 0.587, 0.114};
float AvgLumin = dot(Adaptation, LumCoeff);

This should already compute to accurate average luminosity of scene and not of pixel? I don't know which math behind in your adaptation.

Currently picking between Reinhard method 4 (http://www.cs.utah.edu/~reinhard/cdrom/tonemap.pdf -- page 3) and Filmic from John Hable ( http://www.slideshare.net/ozlael/hable- ... r-lighting -- slide 142)

Offline
User avatar
*blah-blah-blah maniac*
Posts: 17450
Joined: 27 Dec 2011, 08:53
Location: Rather not to say

Re: How do I get average luminosity of the scene?

_s4 sampler in enbeffect.fx is screen brightness, but not average as i wrote in previous post, you may use it. Limitations of my adaptation are in enbeffect.fx file. You can visualize values of adaptation in side of the screen or in meter of any type, line, circle, digits.
_________________
i9-9900k, 64Gb RAM, RTX 3060 12Gb, Win7

Offline
*sensei*
Posts: 372
Joined: 28 Jul 2013, 23:26

Re: How do I get average luminosity of the scene?

Sounds perfect to me. I'll have a play with it and drop Skyrim adaptation out of the mix since its just bad.

Havent opened the original enbeffect.fx file in a while, I see now you take _s4 and use max of it to obtain max white point. Or at least that's how I see it. I'll toy a bit with code and see how that works out for me.

Tanks!
Post Reply