Correct way to calculate ambient lighting?

Hi there, I am working on a custom shader and had a question about which way I should be calculating my ambient lighting.

I have tried two different techniques:

float4 ambient = UNITY_LIGHTMODEL_AMBIENT;
and
float ambient = ShadeSH9(float4(worldNormal, 1));

Below I have a comparison image using the two techniques, with UNITY_LIGHTMODEL_AMBIENT on the left and ShadeSH9(float4(worldNormal, 1)) on the right.


Comparing to the diffuse color tint I have set, it would seem that UNITY_LIGHTMODEL_AMBIENT is a bit more accurate, but I’m still not sure.
3390487--266530--Screen Shot 2018-02-13 at 11.17.51 AM.png

Which technique should I be using to calculate my ambient lighting? Is one of these techniques more correct than the other? Thanks!

ShadeSH9 is the “correct” way to calculate ambient lighting in terms of it being what Unity uses internally for most of its shaders, and will correctly handle the directional lighting from light probes.

UNITY_LIGHTMODEL_AMBIENT is just a solid color that is a constant average of the skybox’s color, the ambient color, or the equator color depending on what setting you’re using for ambient lighting. This can produce more favorable results depending on the use.

1 Like

Thanks for the information!