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?