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. Dismiss Notice

Question Gamma color space - unexpected result?

Discussion in 'Universal Render Pipeline' started by unity_D4-7GldYdCcwUw, Sep 21, 2022.

  1. unity_D4-7GldYdCcwUw

    unity_D4-7GldYdCcwUw

    Joined:
    Nov 25, 2021
    Posts:
    2
    So, I created a simple new project in Unity 2021.3, set up URP, created a plane on a scene and attach a very simple shader to it:

    Code (csharp):
    1.  
    2. v2f vert (appdata v)
    3. {
    4.     v2f o;
    5.     o.vertex = UnityObjectToClipPos(v.vertex);
    6.     o.uv = v.uv;
    7.     return o;
    8. }
    9.  
    10. fixed4 frag(v2f i) : SV_Target
    11. {
    12.     float o = i.uv.x;
    13.     return fixed4(o.xxx, 1.0);
    14.  
    15. }
    16.  
    As you can see I am outputting a linear gradient from the shader (based on a UV coord).

    The project uses the Gamma color space and while I am outputting a linear gradient (not gamma-corrected), my expectation was that the resulting color gradient on the screen will not be linear. BUT that's what I get:

    upload_2022-9-21_22-23-28.png

    ... isn't that a linear gradient?! When I am sampling the middle pixel (just below the blue arrow) in Photoshop, I am getting the mid color value exactly:

    upload_2022-9-21_22-37-39.png

    What would indicate that the gradient is linear indeed.

    Is that expected? My understanding was that the output from a shader should always be gamma-corrected when using the Gamma color space in order to look consistent on the screen. Or am I missing something?

    An explanation of this unexpected result may be the fact that every time I switch from the Linear space to Gamma space in the project settings I get the following warning:

    Requested RenderTexture with sRGB format. sRGB formats are not supported in gamma mode, fallback to a UNorm format. Use a UNorm format instead of sRGB to silence this warning.
    UnityEditor.EditorGUI/PopupCallbackInfo:SetEnumValueDelegate (object,string[],int)/ICODE]
     
  2. unity_D4-7GldYdCcwUw

    unity_D4-7GldYdCcwUw

    Joined:
    Nov 25, 2021
    Posts:
    2
    It looks like the behavior is exactly the same when using the legacy render pipeline so it is not strictly URP-related. May I ask an admin to move the thread into the General Graphics subforum?
     
  3. MattDavis

    MattDavis

    Joined:
    Aug 11, 2013
    Posts:
    16