how to display MTKView with rgba16Float MTLPixelFormat

后端 未结 2 813
攒了一身酷
攒了一身酷 2021-01-24 07:42

I have an MTKView set to use MTLPixelFormat.rgba16Float. I\'m having display issues which can be best described with the following graphic:

So the intended UIC

2条回答
  •  囚心锁ツ
    2021-01-24 08:41

    So, it looks like you are very close to the complete solution. But what you have is not quite correct. Here is a Metal function that will convert from sRGB to a linear value which you can then write in your Metal shader (I still suggest that you write to a sRGB texture but you can also write to a 16 bit texture). Note that sRGB is not a simple 2.2 gamma curve.

    // Convert a non-linear log value to a linear value.
    // Note that normV must be normalized in the range [0.0 1.0].
    
    static inline
    float sRGB_nonLinearNormToLinear(float normV)
    {
      if (normV <= 0.04045f) {
        normV *= (1.0f / 12.92f);
      } else {
        const float a = 0.055f;
        const float gamma = 2.4f;
        //const float gamma = 1.0f / (1.0f / 2.4f);
        normV = (normV + a) * (1.0f / (1.0f + a));
        normV = pow(normV, gamma);
      }
    
      return normV;
    }
    

提交回复
热议问题