Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

HDR colors broken in shaders after updating project from Unity 2017.4.2f2 to Unity 2018.2.17f1

Discussion in 'Shaders' started by OhiraKyou, Nov 30, 2018.

  1. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    I duplicated a project and updated the duplicate from Unity 2017.4.2f2 to Unity 2018.2.17f1, to see what would break and if I could get it fixed up enough to make a permanent switch.

    The project was, and still is, in the linear color space. Yet, I noticed that many effects were significantly duller and darker. And, some rim effects were brighter. But, the most puzzling of all was this change:

    Before (full-size version):


    After (full-size version):


    By removing the [HDR] attribute, this particular example returned to normal. But, many of my effects rely on HDR colors. I noticed that "Brightness" is gone, replaced with "Intensity." So, what exactly has changed? What can I do to fix all of my HDR effects?

    For reference, I have attached the shader used in this example. Perhaps it has something to do with the way HDR colors are interpolated with lerp.
     

    Attached Files:

  2. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Still looking for an answer on this.
     
  3. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    You'll see a bunch of HDR related shader/material changes listed here if you do a search:

    https://unity3d.com/unity/whats-new/unity-2018.1.0

    Editor: Removed the "Intensity" float field next to HDR texture fields in Material editors. Use the exposure controls in the Color Picker instead.


    Editor: ColorPickerHDRConfig is now obsolete and is no longer used.


    If I recall, this is what a color field would use if you had the [HDR] tag, but now it is no longer used. So now your color field values are being treated as LDR. I believe you'll need to make a custom inspector for your shaders that uses EditorGUILayout.ColorField() with the 'hdr' parameter as true for the color fields you want to be treated as HDR.

    It's a shame they didn't simply implement the HDR tag to use this new method instead.

    This post may be useful to you too:
    https://forum.unity.com/threads/how-to-change-hdr-colors-intensity-via-shader.531861/#post-3501895
     
    Last edited: Dec 16, 2018
  4. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    The HDR tag is still used and displays the new intensity value in place of the old "current brightness" value. This intensity value can be modified and does affect bloom. HDR materials with extra brightness created in 2017.4 have intensities greater than 1 in 2018.2. But, they all appear wrong after the update and would need to be tweaked all over again without any guidance as to exactly how these colors were affected by the update.

    What I want to know is precisely how to modify a 2018.x intensity so that it looks the way it did when it was a 2017.x brightness.

    I've looked through the changelogs and found that thread during my own search prior to posting this thread. Neither tell me exactly why these automatically converted values look wildly separated from their 2017 counterparts.
     
  5. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    There used to be two separate color picker classes internally, one for LDR, and one for HDR which they added later. They rolled the HDR functionality into the original one and deprecated it. This only affected people writing custom editors as now instead of calling the HDR specific color picker you call the original with an extra book to enable HDR.

    The [HDR] property drawer was updated to handle the change properly, but it's still need to enable whether a color should be treated as HDR or not.
     
    P_Jong likes this.
  6. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    I've attached a 223 KB archive containing two versions (Unity 2017.4.2f2 and 2018.1.9f2) of a minimal project that illustrates the difference between the same scene in Unity 2017 and 2018.

    The ProjectSettings.asset file seems to be particularly relevant to the issue, as the difference between versions showed itself in this test project after I copied the settings file from my main project. Both versions of the example project include these settings.

    2017 vs 2018 screenshots:
     

    Attached Files:

    Last edited: Apr 2, 2019
    zadda and KarlGG like this.
  7. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    For now if you do this, for example in that shader:

    Code (CSharp):
    1.     col = lerp(_ZeroColor, _OneColor, col.r) * _TintColor;
    2. #ifndef UNITY_NO_LINEAR_COLORSPACE
    3.     col.rgb = GammaToLinearSpace(col.rgb);
    4. #endif
    It seems to nearly perfectly match between 2017 and 2018.

    But that is not an ideal solution. Could be that now in 2018 your HDR colors are actually appearing properly and before the colors you set for them were wrong to adjust for these issues:

    Editor: Fixed bug where HDR color swatches in the Inspector were not converted to gamma color space before being displayed.

    Editor: Fixed bug where sampling color with eyedropper would not convert sampled color back to linear space when the color field was marked as HDR.


    Or maybe it is just a bug with the [HDR] tag doing some extra stuff to the values when set to the shader that it shouldn't be. Since removing that tag and just using the EditorGUI.ColorField works fine.
     
    Last edited: Apr 3, 2019
    OhiraKyou likes this.
  8. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Hmm, interesting. Applying GammaToLinearSpace to color properties does seem to result in generally very close colors. But, similar to what you said, if they really were automatically converting colors to linear, it might make more sense to manually tweak values using the more accurate linear colors than to add more instructions to every shader to maintain the original values.

    Now I feel like I need to find an official statement on this so that I know if I should be making those adjustments or filing a bug report. The changelog reference to swatches is closer to the opposite of what's being observed here.

    In either case, thanks for coming up with a working solution and a solid theory! If that theory gets confirmed, I'll feel pretty confident about updating to Unity 2018 and rebalancing colors manually.

    For reference, here's a gallery of screenshots taken from the same location in a level in Unity 2017, 2018 (before applying the fix), and 2018 (after applying the fix): https://imgur.com/a/C6bCFGU
     
    Invertex likes this.
  9. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,539
    No problem, and to be honest I'm more leaning towards it being an [HDR] bug than improper colors picked, given that removing the HDR tag brings back proper color. So I'd probably file a bug report about that, issue seems to still persist in 2019.1.
     
  10. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Just remembered that I didn't post the bug report response. Here it is:
    Not exactly what I would call a satisfactory response, because "shifted slightly" is a vague understatement. But, if the seemingly uninformed claim that it is by design can be believed, that at least helps with choosing how to handle the change.
     
    Invertex likes this.
  11. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    259
    Edit: deleted the texture-related thoughts from this reply. It's been 22 days since I last tested the GammaToLinearSpace solution, and I have since forgot that only the color properties needed gamma corrected. So, tweaking the colors manually does still seem like the best choice.
     
    Last edited: Apr 27, 2019