Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Roughness is wrong in linear. Here's a fix.

Discussion in 'General Graphics' started by mar0x, Jun 19, 2015.

  1. mar0x

    mar0x

    Joined:
    Sep 22, 2012
    Posts:
    8
    After the artist I'm working with complained about everything shining, I had to take a look. The problem was immediately obvious: roughness in linear color space (HDR, Deferred, SpecularStandard, but I haven't tested with other combinations) is getting compressed via a power function. Of course the first candidate function I'd try is gamma correction. Sure enough, preemptively applying degamma in the standard shader inputs for smoothness compensates for the later gamma that Unity applies (presumably on write to buffer?) and gives the correct results.

    And the easiest way to see something is wrong is to go into deferred, linear. Now turn on the debug view for Specular. Go between gamma and linear. Nothing changes, right? Great. Now turn on the debug view for smoothness, and go between gamma and linear again. Whoops, so much for gamma space being "incorrect", right?

    With a modified shader we can match Marmoset Toolbag perfectly (on linear in both, gamma was fine previously). I've included the shader, it's just for specular standard, since that's what we're currently using.

    This is on Unity 5.0.2.
     

    Attached Files:

  2. G-Mika

    G-Mika

    Joined:
    Jul 17, 2012
    Posts:
    99
    Nice catch, I wondered why the reflection of the sun on glasses were shinier than the sun on my skybox. I figured it was how hdr colors were encoded but I never looked into it.
     
  3. Zuntatos

    Zuntatos

    Joined:
    Nov 18, 2012
    Posts:
    612
    Tried it out, confirmed to be like that in 5.1 as well.
    The rendertexture expects diffuse/specular/roughness/emission written to it to be in gamma space, and only worldnormals in linear space.
     
  4. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    If this is truly a bug you should report it to UT. Nice find.
     
    zyzyx likes this.
  5. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,350
    I knew there was something wrong with the shininess, despite so many people insisting that it was "realistic". I agree you should submit this fix to Unity.
     
  6. tynew

    tynew

    Joined:
    Sep 25, 2013
    Posts:
    122
    Any way to get this working for Metallic shader?
     
  7. Reanimate_L

    Reanimate_L

    Joined:
    Oct 10, 2009
    Posts:
    2,785
    Just curious which line that changed?
    nvm found it :)