Hello everyone,
I am trying to build a custom lighting surface shader but I am facing some problems with the Color Space.
If you render the lightDir, Normal or viewDir you can see that they are different depending of the Color Space you use.
I made some test and the result I have in Linear Color Space is great but how can I obtain the same result in Gamma Color Space ?
Are there some transformations ? On what component should I apply those transformations ?
Thank you very much !
To go to linear, you want pow(color, 2.2) and to get back you want pow(color, 0.454545)
0.454545 recurring is 1.0 / 2.2, hard code it because it’s faster.
8 Likes
Thanks for your answer Farfarer, but what’s the process ?
- Convert to Linear (lightDir, Normal, viewDir, Albedo etc…)
- Calculate Diffuse lighting, Specular lighting, Fresnel etc…
- Go back to Gamma for Diffuse lighting, Specular, etc…
- Combine all this and output final Color
Is this the process ?
I just discovered that if I use the default Unity Specular Diffuse shader there are differences between Linear and Gamma Color Space. Is it possible to obtain the same render for both Color Space ?
Hmm… the point of the colour space is to change the resulting render.
The idea that it’s gamma corrected to behave closer to real-life. Only the input colours (diffuse texture, light colour) are converted to linear space, then the lighting calculations are computed in linear space and the final result is put back into gamma space. See here: http://filmicgames.com/archives/299
You could compensate for the result in linear space by returning pow(finalColor,2.2) from your pixel shader, but then the result would be wrong in gamma space (you’d want to just return finalColor). I guess you could set up a script to put in a global shader define depending on the lighting space.
1 Like