Proper shadows in custom fragment shader

I try to get proper shadowing working in a custom fragment CG shader. I don’t want to write a surface shader as my shader uses a very specific rendering algorithm and is optimized for the very purpose of it and for mobile.

I followed the advise from this How do I sample a shadowmap in a custom shader? - Unity Answers thread.

It works, but the problem is that this way, the LIGHT_ATTENUATION(i) macro is not only returning a darker value for pixels on surfaces facing the lightsource and being shadowed, but also for pixels lying on surfaces that do not face the the lightsource (so, triangles on a rotating object pop instantly dark when their surface doesn’t face the lightsource anymore), darkening the areas of an object that point away from the light source additionally (they are already darkened by the shading model).

The surface shaders do not seem to suffer from this problem. Do I need to manually mask the ‘LIGHT_ATTENUATION()’ to affect only light-facing pixels, or is there another macro to use?

My answer my sound odd but it works…just activate the FallBack at the end of your shader with a Unity shader. It seems the fallback does more than just being a fall back - it contains passes for correctly applying shadows. Just make sure that at the end, your program is using your shader rather than the fallback.