I’ve been reading up on linear color space (https://developer.nvidia.com/gpugems/gpugems3/part-iv-image-effects/chapter-24-importance-being-linear). And I think my engine could be improved by implementing it. However, I’m unsure how I should treat data throughout my application to make this work.
A possible approach
So first things first, I can add a texture to my project. That texture will have ‘gamma’ values. As far as I can tell there’s no way to let the content pipeline know that I want to read the linear values from this texture. There’s no way to set an sRGB format in the content pipeline tool. So whenever I load the texture it will be set to
SurfaceFormat.Color and when reading from this texture I will get ‘gamma’ values.
The next step is the render targets. I’m using a deferred rendering architecture. I guess I can write all the diffuse (texture/color) data to a render target with
SurfaceFormat.BGRA32SRGB. Do I need to manually convert the data I read from the texture to linear space, before writing the data? Or does the GPU take care of that for me?
Now for the lighting data, here I blend several light sources. I’ll need more than 8 bits per channel to properly color correct later. There’s no surface format that supports
sRGB that has more than 8 bits per channel so I guess I don’t have to do anything here.
Then the next steps is blending the light data with the diffuse data. I guess I should read the light data and convert it to linear values. Then combine it with the already linear diffuse values. The surface format of this render target could also be one of the
SRGB ones I guess. But to be honest I would still prefer a format with more than 8 bits per channel here to allow for a higher quality in post processing.
The final step is presenting this data to the screen. If I feed the sprite batch a render target with an SRGB format will it properly gamma correct the values when rendering it to screen? Or should I convert the values back to gamma values in a shader?
So as you can tell I have a lot of questions. When to use the SRGB surface formats? When do I have to manually convert color data to/from linear, and when will it be done for me?
And another question. What is the easiest way to test that everything is working like it should?