Shader for Sprites to cast shadows and take normal maps

I think I finally got a shader working that allows Unity 4.3 Sprites to take normal maps (now properly) and cast shadows.

The sprite on the left is a 2D toolkit sprite and the one on the right is the Sprite GameObject animated (please ignore the poor animation :P).
An important step though is to enable casting and receiving shadows in your Sprite gameobject, since this is disabled in the Spriterenderer by default.
You use renderer.castShadows = true and receive.castShadows = true for this.

I posted this on the Shaderlab forum already, but thought it would be useful to share it here too.

1454955–79095–$Sprites-Bumped Diffuse.shader (1.38 KB)

1 Like

Works well for clipped sprites, but this also means no alpha and aliased edges when the edge is antialiased with transparency. What’s really needed is a shader that applies the alpha to the normal as well, or rather applies normal mapped lighting to the sprite and then applies alpha blending to the result. Maybe this needs a second pass?

Hi there,

it is working great! Thanks!
I only want the shadow to be visible. How can I hide the sprite that is casting the shadow?

Thanks a lot, I’ve been trying to write something like that for a while now.

I’ll try to modify it a bit if you dont mind

I know this thread is pretty old now, but I was wondering if the normal maps are applied to the currently animating sprite? e.g. Say I have a spritesheet for an object with normals laid out on it already. When I animate the spritesheet, will the corresponding normal be applied? Thank you for your time, if anyone stumbles across this and knows the answer.

~zedseven