I’m confused about what effect the Gamma/Linear Color Space option in the Player Settings is actually doing in the graphics pipeline.
If it’s set to Gamma, everything is done in gamma-space in the shaders, nothing gets done in linear space. Textures are read in “as is”, lighting is done, and it’s pushed out to the display device, still in it’s gamma color space, which is what the display device expects. Cool.
If it’s set to Linear, all textures are read in (for example, all tex2D() sample calls) with gamma correction applied so we can work w/ the texture data in linear space. Lighting is done in linear space, and when the Renderer is finished, it maps the final image back to gamma space for the display device.
So, in photoshop, I create this 0-255 gradient, saving it as a PNG:
Due to how images work, this is actually stored in gamma color space. So a color value at the u = 0.25 column should be closer to 50% than 25%, do I have that right?
Now, I import it into unity, which is set to use the linear color space. I have the sRGB flag set to “true”:
If this flag is true, I expect the data to be coming in gamma-corrected. If it’s false, I expect the data to be coming in “as is”.
To verify this, I’ve written a shader that renders the red-channel of a texture as a heatmap:
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
if (col.r < 0.25)
{
return fixed4(1, 0, 0, 1);
}
else if (col.r < 0.5)
{
return fixed4(1, 0.5, 0, 1);
}
else if (col.r < 0.75)
{
return fixed4(1, 1, 0, 1);
}
else
{
return fixed4(0, 1, 0, 1);
}
}
Now, I’m currently in Linear Space. Ideally, if the flag is true (unity should decode the image data back into linear space), I expected to see something like this:
However, I’m actually seeing this:
When I turn the sRGB (Color Texture) flag to false, it looks “correct” like the first heatmap. It works opposite to what I expected.
Furthermore, when I have the color-space set to gamma, it looks like the first image, Shouldn’t it look like the second image because it’s reading the texture data “as is”? Not applying gamma correction when it reads the texture data?
What am I misunderstanding about how the linear vs. gamma color space works with respect to the Unity Pipeline?
Thanks