Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted question about gamma and linear work flow in unity

Discussion in 'General Graphics' started by cyberjoys, Jul 26, 2021.

  1. cyberjoys


    Dec 1, 2020
    hi, guys
    after reading the doc, i see gamma and linear work flow as the following.

    gamma work flow:
    1.texture imported with sRGB checked or not is no matter, all texture will be sampled WITHOUT gamma correction removed? need manual gamma correct in shader when sample sRGB tex?
    2.all shader render output will NOT apply AUTO gamma correct in the end?
    3.if so, in gamma work flow, i need to sample texture, do gamma remove in my shader, then do linear calulation, then before return result, do manual gamma correct ?

    linear work flow:
    1. texture imported with sRGB checked doest matter, in linear work flow, unity will use GPU sRGB sampler by default, and texture sampled will have auto gamma correct removed ? no manual gamma correct remove?
    2. all shader render out put will apply AUTO gamma correct in the end? no manual implement required ?
    3. if so, in linear work flow, i dont need to worry about any of the gamma correct stuff ??

    am i right about the gamma and linear work flow?
    coz, i think there are some confusions in the doc that makes me not 100% sure about this, really hope someone can clearify a bit for me
  2. bgolus


    Dec 7, 2012
    When using the gamma color space, all textures are sampled without any sRGB correction regardless of if the sRGB setting is checked or not, because the rendering is all being done in sRGB space already. If you want lighting to look like it does when using linear space, then yes, you would need to convert the color textures (and light color!) from sRGB "gamma" space to linear space, do the lighting operations, and convert them back to sRGB space. But usually if you're using gamma color space you're choosing to do so explicitly because you don't want lighting to be done in linear space.

    When using linear color space the sRGB setting on the texture importer changes how the GPU samples it, and any textures marked as sRGB will be converted from sRGB "gamma" space to linear space by the hardware. And yes, when rendering is finished the linear space render target will be displayed converted back to sRGB "gamma" space.

    So yes. As long as the appropriate textures (anything that's a "color") are marked as sRGB, you don't need to do anything else to "fix" stuff when using linear color space.

    The one caveat to this is the look of alpha blending changes between gamma and linear space rendering as well. This means if you're mocking up UI in Photoshop or some other external art application, it will not match what you see in the game when using linear space rendering. This is because most art tools do their color and transparency blending using gamma space instead of linear space. There are workarounds to this that require rendering UI to a separate render texture and compositing them manually with a custom shader, but most people just live with it. You can make Photoshop look like Unity does when using linear color space by changing the image mode to 32 bits/channel, but this also disables some of Photoshop's filters and tools.
  3. cyberjoys


    Dec 1, 2020
    thanks mate, you always are a big help to the community, cheers :)