UNITY_LIGHTMODEL_AMBIENT doesn't work in Editor mode

I’m trying to use UNITY_LIGHTMODEL_AMBIENT, the ambient light color. It works in Game mode, but in Editor mode, it just returns a gray color always.

Also, a separate issue: even in Game mode, it’s not quite returning the right values, it’s like the color I pick divided by 2.2 or something. If I pick white, it gives me rgb(188,188,188) instead of triple 255.

Are you in gamma or linear light mode?

Linear, but i tried both. I actually ended up deciding I didn’t to do this, now that I realized you can have global shader values.

Well, if you’re in linear, then you’ll get the gamma-corrected version of the light colour;
pow(UNITY_LIGHTMODEL_AMBIENT.rgb, gammaValue); (with gammaValue being 2.2 on a PC and 1.8 on a Mac).

And everything in your shader will get converted back to gamma space at the end (via pow(result, 1/gammaValue); ).

Also, I think, by default the built-in shaders and surface shaders multiply it by 2. Essentially, fixed3 ambientLight = s.Albedo * UNITY_LIGHTMODEL_AMBIENT.rgb * 2;

I suspect that it’s being set somewhere in script, though, as it should show up in the editor as well as in game mode. What happens if you make it a really bright green?

:face_with_spiral_eyes: OS X was switched to 2.2 by default in 2009.

Oh, I didn’t know (not really a Mac person) :stuck_out_tongue:

I ended up making my own ambient light picker and using Shader.SetGlobalColor. However, I am getting the same gamma related issue. I tried pow(color, 2.2), which is really close, but isn’t quite exactly there. I think it’s close enough for what I need though. Maybe the differences are due to the precision of the 8-bit floats.

Oh wait, I just pass in color.linear to the SetGlobalColor function.

I think Unity might use a flat 2.0 for gamma. I read that somewhere in the docs but I’m not sure where.

The color.linear method will be more accurate, though (and less instructions in the shader).