Apple Metal Shader Language (MSL) Always Linear Color?

Viewed 203

I'm trying to understand color within the context of a metal fragment (or compute) shader.

My understanding is that within the context of a metal shader any color values are always linear. Whatever texture is attached to fragment or compute function, metal will apply the inverse of any linear transfer function (gamma) on the way into the shader, and apply it again on the way out.

With this in mind, if within the context of a shader, I return a value with an approximate linear middle grey value of around 22.25%, when rendered to the screen using metal kit via a simple .bgra8Unorm texture, I would expect to get a non-linear sRGB reading of around 128,128,128.

fragment float4 fragment_shader(
    TextureMappingVertex in [[stage_in]]
) {
    float middleGrey = float(0.2225);
    return float4(middleGrey, middleGrey, middleGrey, 1);
}

But in fact I get an output of 57,57,57 which is what I would expect if there were no conversion to and from the linear color space within the shader:

Linear Middle Grey

What am I missing here?

On the one hand, this certainly seems more intuitive, but it goes against what I thought were the rules for Metal shaders in that they are always in linear space.

0 Answers
Related