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

LUT Shader with linear mode?

Discussion in 'Universal Render Pipeline' started by FranFndz, Mar 19, 2020.

  1. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    I made a lut shader that goes inside my objects, Background, Characters etc so i can skip the post processing.

    The problem is that the shader work well when the project is set as GAMMA, but when is Linear there is a really small color offset.

    The LUT texture is marked as NOT SRGB.

    the shader is this one
    Code (CSharp):
    1. #if ENABLE_LUT
    2.  
    3. //LUT Texture size (height)
    4. #define COLORS 32.0
    5.  
    6. //Properties
    7. sampler2D _LUT;
    8. float4 _LUT_TexelSize;
    9. float _Contribution;
    10.  
    11. //Gamma to Linear
    12. // pow(color, 2.2)
    13. // color * color
    14. //Linear to Gamma
    15. //pow(color, 1/2.2)
    16. //sqrt(col)
    17.  
    18. inline float3 LUTColorGrading(float3 baseColor)
    19. {
    20.     //Convert to Gamma (Unity Linear mode i need this)
    21.     float3 color = pow(baseColor, 1/2.22);
    22.    
    23.     float maxColor = COLORS - 1.0;
    24.     float floatColX = 0.5 / _LUT_TexelSize.z; // Texture Width
    25.     float floatColY = 0.5 / _LUT_TexelSize.w; // Texture Height
    26.     float threshold = maxColor / COLORS;
    27.    
    28.     float xOffset = floatColX + color.r / COLORS * threshold;
    29.     float yOffset = floatColY + color.g * threshold;
    30.     float cell = floor(color.b * maxColor );
    31.    
    32.     float2 lutPos = float2(cell / COLORS + xOffset, yOffset);
    33.  
    34.     float3 gradedCol = tex2D(_LUT, lutPos).rgb;
    35.     //Back to Linear (Unity Linear mode i need this)
    36.     color = pow(gradedCol, 2.22);
    37.    
    38.     float3 returnColor = lerp(baseColor, color, _Contribution);
    39.  
    40.     return returnColor;
    41. }
    42.      
    What can be wrong?
     
  2. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    well the color shift is minimun, but unity post effect dont have the same issue. so is not about the lut texture.

     
  3. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    is not saturate :/
     
  4. Peter-Bailey

    Peter-Bailey

    Joined:
    Oct 12, 2012
    Posts:
    35
    Does it have to do with the way linear mode shades geometry?
     
  5. Yuira95

    Yuira95

    Joined:
    Jan 17, 2018
    Posts:
    5
    Try to disable mipmaps in textures.
     
  6. FranFndz

    FranFndz

    Joined:
    Sep 20, 2018
    Posts:
    178
    oh sorry, i fix it with shaderssss
     
  7. AwesomeAlexx

    AwesomeAlexx

    Joined:
    Jan 30, 2016
    Posts:
    18
    I'm facing the same pb, can you share the process to remove the color offset ?
     
    AcidArrow likes this.