- Home /
Writing a 2D shadow shader for top-down game
Hi, I'm trying to write a shader (my first!) for sprites that will be in a top down game like this one.
I've been playing around with the shader here, however I simply can't get it to produce the effect that I need. This shader projects a shadow onto the X-Z plane, but I need mine on the X-Y plane. My lights are situated "above" the game in the Z-axis.
One of my main problems is the height factor, when the sprite moves in the X-Y plane like it is supposed to in a Unity 2D game, the shadow moves further away from it. Even if this particular problem was solved, the shadow from this shader just doesn't look right.
How can I cast a shadow (deform a sprite based on the light) where:
The light is high on the Z axis
The object casting the shadow is on the X-Y plane
The object receiving the shadow is also on the X-Y plane, and
The base of the shadow remains at the base of the caster regardless of X-Y movement
Any ideas?
Currently I am thinking of just keeping everything in 3-d space, moving the sprite around in the X-Z plane, and having a shader that just flattens the sprite into X-Y at render time (the camera is orthogonal and looks at the X-Z plane from above).
This means I can just use Unity lighting and shadows (if I used quads for the sprites).