Suppose I have some (fake) ambient occlusion data generated and baked into a texture, and I want to use this texture in a shader to reduce ambient lighting. Is there a way to do this with surface shader? Custom lighting model for surface shaders only seems to apply to actual lights, not ambient term.
I guess you could set the standard ambient term to 0 and include your own ambient term by setting the emission variable in the surface shader. (Then you have full control over the ambient term and can include your ambient occlusion.)
In surface shaders, the ambient term is calculated as “s.Albedo * ambient light color * 2”.
So one way to do it would be to pass your diffuse through twice. Once to o.Albedo with your AO multiplied in, once to o.CustomAlbedo without the AO multiplied in.
Other option would be to turn off ambient using the noambient parameter and add it yourself, in the lighting function…
fixed3 ambient = 0;
#ifdef FORWARD_BASE
ambient = UNITY_LIGHTMODEL_AMBIENT * ao * 2;
#endif
fixed4 c = [your stuff] + ambieny
Code’s off the top of my head, sorry,
1 Like
Nice idea! I just tried it - works like a charm!