Correct way of calculating tri color ambient light

Unity now supports a three color gradient for ambient light which is ace.
I’m trying to add support for this in my own shaders.
The shader docs say UNITY_LIGHTMODEL_AMBIENT should no longer be used by shaders and instead there are the following built in shader variables:

unity_AmbientSky
unity_AmbientEquator
unity_AmbientGround

What is the correct method of calculating ambient light to match what the standard shader does?
I looked at the latest built in shader sources and theres no refrence to the variables.
I tried just using the world normal to lerp between the 3 colors but it looks like the standard shader does something different.

Also surely we also need another variable to tell the shader which ambient light mode the scene in using? (flat / tricolor etc).

Cheers

Ok I had a poke around and I think Unity sets the alpha of unity_AmbientSky to 1 when using a gradiant for ambient light and 0 when its flat. Not 100% might be a false positive, it would be nice to know if this was true or theres another method of knowing what the current ambient lighting mode was in a shader.

I should’ve said I’m trying to do this when using vertex lighting, in a forward based lighting shader you can just call ShadeSH9() and it will calulate the proper ambient color from the defined spherical harmonic variables.
These variables aren’t defined when for vertex lighting so you need to fudge a way of faking the spherical harmonics.
I came up with a fudgy function that looks pretty accurate in most cases, here it is in case anyone else wants to it!

fixed3 calculateAmbientLight(half3 normalWorld)
{
	//Flat ambient is just the sky color
	fixed3 ambient = unity_AmbientSky.rgb * 0.75;
	
#if defined(TRI_COLOR_AMBIENT)	

	//Magic constants used to tweak ambient to approximate pixel shader spherical harmonics 
	fixed3 worldUp = fixed3(0,1,0);
	float skyGroundDotMul = 2.5;
	float minEquatorMix = 0.5;
	float equatorColorBlur = 0.33;
	
	float upDot = dot(normalWorld, worldUp);
	
	//Fade between a flat lerp from sky to ground and a 3 way lerp based on how bright the equator light is.
	//This simulates how directional lights get blurred using spherical harmonics
	
	//Work out color from ground and sky, ignoring equator
	float adjustedDot = upDot * skyGroundDotMul;
	fixed3 skyGroundColor = lerp(unity_AmbientGround, unity_AmbientSky, saturate((adjustedDot + 1.0) * 0.5));
	
	//Work out equator lights brightness
	float equatorBright = saturate(dot(unity_AmbientEquator.rgb, unity_AmbientEquator.rgb));
	
	//Blur equator color with sky and ground colors based on how bright it is.
	fixed3 equatorBlurredColor = lerp(unity_AmbientEquator, saturate(unity_AmbientEquator + unity_AmbientGround + unity_AmbientSky), equatorBright * equatorColorBlur);
	
	//Work out 3 way lerp inc equator light
	float smoothDot = pow(abs(upDot), 1);
	fixed3 equatorColor = lerp(equatorBlurredColor, unity_AmbientGround, smoothDot) * step(upDot, 0) + lerp(equatorBlurredColor, unity_AmbientSky, smoothDot) * step(0, upDot);
	
	return lerp(skyGroundColor, equatorColor, saturate(equatorBright + minEquatorMix)) * 0.75;
	
#endif // TRI_COLOR_AMBIENT	

	return ambient;
}