- Home /
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 http://answers.unity3d.com/questions/180298/how-do-i-sample-a-shadowmap-in-a-custom-shader.html 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?
Answer by Nims · Jul 01, 2014 at 04:18 AM
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.
Your answer
Follow this Question
Related Questions
Shadow Support in Custom Shader 0 Answers
Edge outline & 2D shadow Shader for planar mesh 0 Answers
Make this shader receive and cast shadow? Can anyone help me thanks! 0 Answers
how can i catch the sky box and do a reflection in object 0 Answers
Combine Basic Shadow Shader and Transparency Shader in Unity 0 Answers