0

I am using Unity and I can choose between two color space mode in the settings: Gamma or Linear Space.

I am trying to build a Custom Lighting Surface shader but I am facing some problems with those Color Space. Because the render is not the same depending of the Color Space.

If I render the lightDir, Normal or viewDir I can see that they are different depending of the Color Space I use.

I made some test and the result I have in Linear Space is great but how can I obtain the same result in Gamma Space ? Are there some transformations ? On what component should I apply those transformations ?

genpfault
  • 51,148
  • 11
  • 85
  • 139
MaT
  • 1,556
  • 3
  • 28
  • 64
  • "Gamma space" probably refers to sRGB, which uses a gamma exponent of 2.2. It is pretty trivial to convert between sRGB and linear (gamma exponent = 1.0). You can do this by raising the color components to 2.2 or 1.0/2.2 depending on which way you want to go. – Andon M. Coleman May 01 '14 at 22:38
  • @AndonM.Coleman: Actually sRGB is not using a simple power mapping. It uses`sRGB_gamma(x) = x < 0.0031308 ? 12.95*x : pow(x, 2.4)*1.055 - 0.055` – datenwolf May 01 '14 at 23:25
  • 1
    Yeah, the piece-wise definition is more precise. However, even the IEC 1966-2.1 spec states: "The above equations closely fit a simple power function with an exponent of 2.2. This maintains consistency with the legacy of desktop and video images." Granted if you graph both curves, I'd say they look nothing alike, but others seem to think they "closely fit". – Andon M. Coleman May 01 '14 at 23:56
  • Thank you for your answers, where those transformations should be applied ? On final color only, each component (lightDir, Normal, Albedo, etc...) – MaT May 02 '14 at 07:27
  • 2
    Final color is generally where you would re-map the color space. In fact, if the hardware is doing gamma correction for you then you would leave that out of the equation altogether. This is because if you convert from gamma 2.2 (or whatever exponent/curve is used) to linear at the end of your shader, then blending will occur in linear space. Hardware gamma correction, on the other hand, occurs after blending. Consider reading the [following](http://http.developer.nvidia.com/GPUGems3/gpugems3_ch24.html). – Andon M. Coleman May 02 '14 at 20:27

0 Answers0