Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Sampling textures without sRGB conversion

Discussion in 'Shaders' started by NoiseFloorDev, Jun 30, 2017.

  1. NoiseFloorDev

    NoiseFloorDev

    Joined:
    May 13, 2017
    Posts:
    104
    I'm trying to sample a vector displacement map from a 32-bit (HDR) texture, and I seem to be getting sRGB conversions applied. I'm testing by creating an image filled with 0.5,0.5,0.5 grey. I tested that the file really contains 0.5 grey by reading the file with a test tool using the OpenEXR library, and confirmed that the values really are 0.5. I attach it to a test fragment shader:

    float4_t color = tex2D(_MainTex, i.uv);
    if(color.g > 0.4 && color.g < 0.6)
    return float4(0,1,0,1);
    else
    return float4(0,0,1,1);

    This should output green, since the value should be 0.5, but it's blue. If I change it to "g > 0.6 && g < 0.8", I get green. The sampler is actually reading 0.729, which is 0.5 with the 2.2 gamma curve applied.

    That would make sense if it was color data, but it's vector data, which should never have color conversions applied. Unchecking "sRGB (Color Texture)" in texture properties should disable this conversion, but it doesn't--I always get 0.729. It happens with both EXR and HDR files.

    It seems like the sRGB flag is broken, which makes sampling non-color data like vector maps impossible. I can't reverse a gamma curve in the shader, since vector maps have negative values. Any suggestions?
     
  2. NoiseFloorDev

    NoiseFloorDev

    Joined:
    May 13, 2017
    Posts:
    104
    If I set my entire project to linear space this stops happening, but that doesn't make sense. I don't need HDR rendering (that setting is a huge hammer and is not a trivial thing to turn on), I just need to sample specific textures without sRGB conversions.