Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question Problem with Gamma Texture Linear Color Space

Discussion in 'General Graphics' started by Chengqi-Li, Apr 19, 2022.

  1. Chengqi-Li

    Chengqi-Li

    Joined:
    Mar 11, 2016
    Posts:
    6
    Hello, everyone

    I'm currently working on a game. The UI artist send me the game title image, exported from photoshop. However, after I imported it. A problem occurred, the color looks different between unity and photoshop. My project is using linear color space. However, the image from photoshop is in gamma space. I think that caused this inconsistency.

    My question is, how to use gamma texture is linear color space? (or, how to export linear texture from photoshop)

    Followings are some effects from a brand new unity project, 2019.4.25f1c1.

    Gamma space: image looked the same, however I used HDR in my project. So too bad, that's not an solution.
    gamma.png

    Linear space: image looked different, the outer glow part.
    linear.png
    Linear space with srgb color uncheck from import settings: the image faded. linear_srgb_unchecked.png

    original image:
    logo.png

    I believe the same issue must be asked over and over again. And I have done some research, including https://docs.unity3d.com/Manual/LinearRendering-LinearOrGammaWorkflow.html. And still didn't find solution.

    Thanks for time reading, any comment is appreciated.
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,704
    What if you turn off all post-processing. Does the color still look different?
     
  3. Chengqi-Li

    Chengqi-Li

    Joined:
    Mar 11, 2016
    Posts:
    6
    I think the color is still different. I created an empty unity project to test gamma and linear settings. The camera was untouched. Render pipeline was default. I have tried URP, and the behavior was the same.
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,704
  5. Deleted User

    Deleted User

    Guest

    That's because alpha blend is different between gamma work flow and linear work flow. Usually two ways to solve this problem ,while neither are not perfect:
    1. Change PS color profile to linear color space or blend color with gamma 1.0 but the artist may not like it.
    2. Split Scene-Rendering and UI-Rendering, do gamma encode after scene-rendering, then render UI in gamma color space, while this method can bring some extra performance cost and other issuses such as the color picker's value is not so "precise".
    If your game is not a realistic-style, perhaps gamma work-flow is more suitable for you.(HDR should not be a problem)
     
    CodeRonnie likes this.
  6. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    596

    Checking your original image here. back into photoshop, the "glow" is apparent in the actual image.
    so this is a glow/blow/overlay layer your artist has likely created in their layer stack in photoshop, not something that unity is creating.

    you can see this going back into PS and selecting the object with an inverted black fill.
    - control click thumbnail in the layer stack, to select it
    - shift control N, to create a new layer
    - set your foreground fill to black
    - G, for fill bucket
    - Control shift i, to invert the selection
    - left click to fill

    you should see the same results as below.
    upload_2022-8-12_10-26-54.png

    You can also see the Alpha channel has this in unity by checking the inspector A channel.


    My recommendation for you is to inform your artist to remove the glow/blur on the problematic layer.
    or use image > threshold to remove it.


    I have gone ahead and made a Power of 2 version of all the above for you. the results are the "-fix" versions below
    linear in HDRP example
    upload_2022-8-12_11-1-28.png

    import this as you would with the sRGB check 'on' in the importer and linear colour space for your project
     

    Attached Files:

    c0d3_m0nk3y likes this.
  7. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    705
    What a great answer. I was about to say that the original author could at least have left a like but then I noticed that he posted it already in April.
     
  8. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    596
    Thanks :)

    The OP was some time ago sure.
    I still felt it a good place to resolve in case someone else stumbles on it.
     
    c0d3_m0nk3y likes this.
  9. Noors84

    Noors84

    Joined:
    Jul 12, 2016
    Posts:
    81
    Hi, i have the same problem in URP/linear.
    From what i get, the issue is Photoshop using alpha blending in gamma space.

    To me, alpha created in photoshop should be also gamma corrected in the shader.
    Or edit textures in 32bpc, which switches Photoshop in linear mode but has a lot of constraints
    Also UI might be rendered with a gamma cam, but that's not the solution for scene objects.

    I know it won't be 100% accurate but i guess it's a decent workaround.
    Can anyone confirm ?
    Thanks !
     
  10. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    596

    Shouldn't be an issue for UI.
    you could straight up convert a photoshop .png with transparency to sprite (2D and UI) in unity with no issues.


    If you're working linear in your project, for sRGB textures you just need to check the SRGB option and unity will convert it to linear colour space, for linear textures leave it unchecked.

    in this instance
    this will pack a DXT5|BC3 sRGB texture that is converted to linear colour space.


    However, if you're using shader work for data feeding, then you would want a Linear-Based texture, these are also called "data maps" and they're almost always linear-based ( HDRP mask map and detail maps for example should have sRGB ( colour Texture) checked off and the source texture be linear colour space already.


    If you're familiar with colour management then you could make your own linear ICC profile in photoshop and load it as a colour workspace, that way if you really wish to view the linear colours for side-by-side comparison in photoshop and unity editors then you can, be aware you'd still have to convert to linear in unity or elsewhere still, but for viewing purposes, you can do the following.

    -ctrl shift(cmd) k
    -working space > RGB > custom RGB
    -change gamma to 1.0 ( aka linear)
    -back on the RGB drop-down list click save
    -save the ICC profile

    you should now be able to load it whenever you want to
     
  11. Chengqi-Li

    Chengqi-Li

    Joined:
    Mar 11, 2016
    Posts:
    6
    Thanks for commenting.
    I tried first method, didn't go very far. From what I can recall, there were some problem when merging layers after changed color settings.

    I followed second method. I then realized the problem can be fixed in rendering stage. Following are the steps.
    https://cmwdexint.com/2019/05/30/3d-scene-need-linear-but-ui-need-gamma/
    Also for anything with color picker involved, I added a script to convert the colorspace.

    I thought this thread was dead, so I didn't post the solution I have found. In case anyone met this issue, hope the link above can help.
     
  12. Chengqi-Li

    Chengqi-Li

    Joined:
    Mar 11, 2016
    Posts:
    6
    The final image looks brilliant. I wish I had chance to test this out. Sadly, the UI assets has been produced. Thank you for your comment.
     
    HIBIKI_entertainment likes this.
  13. Noors84

    Noors84

    Joined:
    Jul 12, 2016
    Posts:
    81
    The issue is only with the alpha, and the artist has already authorized his sprites in photoshop.