Search Unity

Trouble with adaptive tonemapping - Possible to limit it?

Discussion in 'Editor & General Support' started by Volantk, Feb 23, 2012.

  1. Volantk

    Volantk

    Joined:
    Feb 23, 2012
    Posts:
    2
    I'm having some trouble getting the adaptive tonemapping to do what I want, or rather to limit it to my needs.

    We're making a game that requires quite a bit of contrast between the light and dark areas. When standing in light, the dark areas should be pitch black. When in dark areas, the camera should adjust and make things just bright enough to see what's in front of you, but not bright as day.

    The Adaptive Reinhard tonemapping gets me almost where I want to be, but there are some issues.

    My values are:
    Middle grey: 0.07
    White: 10

    In order for the dark areas to be dark enough when you're inside them, the light areas are toned down too much. This makes the lighting really dull when you're in the brightest areas.

    To make the light areas look good, I have to tweak the "middle grey" value a bit, which works, but then the dark areas become way too bright.

    Is there's a way to limit the tonemapper so that it stops before ruining the dark areas.

    I can try to formulate it better:
    Say the tonemapper is at the imaginary value 50 when you look at an averagely lit spot in your scene.
    When looking at very light areas, it will go up to 100 to compensate for it, toning the brightness down. This is ok. However...
    When looking at very dark areas, it will go to 0, making it just as bright as the areas that are lit. I want to cap that imaginary value at something like 60, so that it stops while the dark is still...darkness.

    Image visualizing this:
    http://i.imgur.com/nQnNy.jpg


    All replies appreciated. Fixes, workarounds, anything. :)

    Thanks.
     
    newmonuments likes this.
  2. Ganymede

    Ganymede

    Joined:
    Mar 26, 2012
    Posts:
    2
    This is the first thing I noticed (other than the improvements in 3.5 being rather fantastic!). I'm sure the Unity devs will place the addition in at some point, hopefully soon. I'm sure there's a way to scale the tonemapping influence depending on the base luminance... but the work required is beyond me at this point!

    Either way, I '+1' the proposal.

    Nice diagram, by the way
     
  3. Ganymede

    Ganymede

    Joined:
    Mar 26, 2012
    Posts:
    2
    I think i've made some progress on this! I'd doubt it's the best way to go about it as I haven't gone into the full technical workings of a tonemapper, but within the tonemapper shader (within 'image effects/sources/shaders') inside the 'fragAdaptive' function is a line (should be line 149):

    'color.rgb = color.rgb * (lumScaled / cieLum);'

    i changed this to:

    'color.rgb = color.rgb * ((lumScaled) / (cieLum+0.03f));'

    seemed to do what we're trying to do... to an extent! it leaves shadows in shadow better, at least

    if you come up with any better, cleaner alterations, do let me know!
     
  4. R0man

    R0man

    Joined:
    Jul 10, 2011
    Posts:
    90
    I would love to know if someone has figured out an elegant solution to this problem.
     
  5. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    I googled this because I needed this exact functionality and this was the only thread I found.

    I have no knowledge of shader programming or image effects, but I think I managed to make something that works. I've attached it to this post.

    Basically I guessed there had to be one spot in the code where I could clamp the values returned and by following the middleGrey value from the inspector to the shader I think I found a suitable spot. Then I just added a lower limit and a higher limit to the inspector. Setting the higher limit to something like 10 worked wonders in my case. Setting it to a high number like 100 basically disables the clamping and makes it behave like the default tonemapper.

    I had no idea what to clamp the values to so that's why the default for the higher limit is set to 1. It's obviously way too low. :p

    I also have no idea what I actually did so that's why I just called the values lower and higher limit and didn't write a description for them in the inspector because I wouldn't know what to write.

    I've added a comment with // TwiiK Hack in all the places I changed the original scripts and shader if you want to compare them with the originals. I think it's 6 places and about 12 or so new lines of code.

    Edit: I realized now that I should have created a new image effect instead of overwriting the old one. Ohh well, anyone who uses it can do that for themselves if they want to. :)
     

    Attached Files:

    Last edited: Aug 19, 2012
  6. Volantk

    Volantk

    Joined:
    Feb 23, 2012
    Posts:
    2
    Randomly checking a thread made six months ago, only to find a post containing a solution, posted yesterday: Score!

    I'll give it a go and see if it's a bit more manageable now.

    Takk skal du ha ;)
     
  7. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Bare hyggelig. :)

    Let me know if it doesn't work out as I'm still doing some work on the tonemapping. One thing that is still bothering me is how bright windows and doorway are when I enter a house. Would be nice if that could be limited in some way as well without affecting the rest of the image.
     
  8. Alexander-Perrin

    Alexander-Perrin

    Joined:
    Sep 6, 2012
    Posts:
    4
    I don't know if any of you are still working on this, but I made some progress also! I found out that we were attempting to solve this problem in entirely the wrong way. The tonemapper provided actually seems to work just fine. It's the way that the scene is set up that makes things difficult

    Firstly, change to using a linear colourspace. This is pretty vital. It's a much more accurate representation of light interaction in the real world.
    Secondly, ensure HDR is enabled (obviously).
    Thirdly, and most importantly! Really boost the light values for everything. For my sunlight I'm using an intensity of 3.

    By using these settings and configuring the adaptive reinhard mapper with the proper values, i've got darks remaining dark and brights remaining bright, with a small amount of adaption in the middle, it's perfect!
     
  9. kjetilh

    kjetilh

    Joined:
    Oct 1, 2010
    Posts:
    82
    Alexander: So, what values are you using for this then? Just default? My scenes whiteout, unless I set middle grey to 0.001. It doesn't seem right.
    Btw, I'm also getting an error with the adaptive reinhard, "false wrong color rt format".

    Any ideas?

    Thanks!