We have a toon surface shader with a custom lighting function: csharp** **fixed4 LightingToon (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten)** **
and we use this shader on the Unity terrain but we want to bake all shadows on the terrain to have better performance so we use Baked GI.
As soon as GI is baked - this function just stops working. (not launching, probably replaced by Lambert)
So I did a little research and found that methods like this are obsolete now and replaced by:
fixed4 Lighting<Name>(SurfaceOutput s, half3 viewDir, UnityGI gi)
fixed4 Lighting<Name>(SurfaceOutput s, UnityGI gi)
half4 Lighting<Name>_Deferred (SurfaceOutput s, half3 viewDir, UnityGI gi, out half4 outDiffuseOcclusion, out half4 outSpecSmoothness, out half4 outNormal)
half4 Lighting<Name>_Deferred (SurfaceOutput s, UnityGI gi, out half4 outDiffuseOcclusion, out half4 outSpecSmoothness, out half4 outNormal)
fixed4 Lighting<Name>(_PrePass (SurfaceOutput s, half4 light)
void Lighting<Name>_GI(SurfaceOutput s, UnityGIInput data, inout UnityGI gi)
I managed to rewrite my Lighting function using the new form (with GI as parameter) and combined it successfully with the existing light color. I used gi.light.dir instead of missing light dir from param and i used 1 for my attenuation since I use only directional light in this case. Everything works fine - I can bake GI and my toon terrain texture is mixed now with lightmap shadow. The only problem left is: the output differs from the original lighting function - my terrain gets less indirect light. As a test i use Precomputed GI (which was also working for the original lighting function).
As soon as I figure out what’s going on I will write new update here In the meantime any of Your help is appreciated !
It turned out that the original lighting function works with baked GI ( i mean is normally called - my mistake ) but the output is wrong because it adds GI to the color multiplied by lighting 0 (light is disabled for objects with lightmap) - so the output is GI * Albedo which in my case is wrong because i have specific surface color (toon) not simple albedo - i changed this lighting function for my case to not include zero lighting in computation and it works fine !
I know this is an old thread, but would it be possible to shed some light on how you made it work (perhaps code =D)?
I’m kinda stuck attempting to do the same. While the light interact with objects, it seems masked by the GI and thus doesn’t show on the whole object.