UNITY_LIGHTMODEL_AMBIENT multiply by 2. Why?

I was searching on the Internet how people are using UNITY_LIGHTMODEL_AMBIENT . I noticed that often people are using UNITY_LIGHTMODEL_AMBIENT multiplied by 2.

Here are some examples:

float3 ambient = UNITY_LIGHTMODEL_AMBIENT * 2 * sun;
float4 ambient = UNITY_LIGHTMODEL_AMBIENT * 2;
c.rgb = UNITY_LIGHTMODEL_AMBIENT.rgb * 2 * tex.rgb;

As I undestand it makes Ambient Color 2 times more intense.

Why this is made inside shader? Why not make it 2 times more intense in unity settings?

And why exactly 2, not 3 or 4? Is there some mathematical explanation for 2 or this is just a magical number?

1 Like

It’s a legacy magic number thing. Old versions of Unity halved the intensity of all light values, thus requiring a " * 2.0" in the shader to get the expected value. They only just removed in Unity 5.0.

So in Unity 5 the ambient light value no longer needs to be multiplied by 2, nor does any other light, but many shaders you’ll find online still do both, and the Unity 5 shader upgrade guide didn’t call out the ambient color specifically just lighting in general.

As for why, I suspect this is a fixed function legacy thing where Unity was originally passing Color32 values for lights, which can’t do >1.0 values, so instead they halved the light color value and multiplied by two in the shader later. Humorously, the variable that the UNITY_LIGHTMODEL_AMBIENT macro actually points to, glstate_lightmodel_ambient, still requires the multiply by two, they just have that macro do it now which they didn’t before. You should probably just use unity_AmbientEquator instead now anyway as it holds the same data and doesn’t require the multiply.

Hi, bgolus!
Thank you for detailed answer.