Anyone have a clue?
by nature sprites aren’t going to cast shadows, because they aren’t 3D. The only way to get sprites to cast shadows is to write your own special method for it, because its not something most developers use in 2D games, and instead they rely on artists who just “bake in” the shadows to the artwork…
Sprites are 3D (they’re similar to the quad primitive), but the SpriteRenderer component doesn’t work with shadows. You can use a quad with a transparent/cutout shader instead.
–Eric
In what way Eric5h5? Do you mean as in using them instead Unity Sprites at all?
Yes; SpriteRenderer is not used by shadows in Unity, so if you want shadows then as far as I know you can’t use SpriteRenderer.
–Eric
Ok! Thanks. Here’s to hoping that’ll feature come in some future update.
ooh right I should have clarified the 3d part better, listen to this guy lol
Casting and receiving shadows is disabled on SpriteRenderer by default because it is not a common use case.
Use Unity - Scripting API: Renderer.receiveShadows and http://docs.unity3d.com/Documentation/ScriptReference/Renderer-castShadows.html to reenable the functionality.
TomasJ,
I added a script enabling castShadows and receiveShadows to my Sprite gameobject and it still won’t cast any shadow.
Will have to agree here.The following pictures show this with a Sprite Rock I tested. The characters in the picture are using a custom CutoutShader (Unity Asset Store - The Best Assets for Game Making) which is incompatible with the Sprite Render. It’s there to show the desired behavior, but something I want to move away from, and just use sprites.
Also the Sprite is lit just fine, using the supplied Sprite/Diffuse shader, but reverting this back to the default doesn’t help with shadows.
If it’s hard to see, the shadow on the right is being cast by the little samurai, not the rock, indeed the samurai’s shadow is going through the rock. The rock is neither recieving, nor projecting a shadow.
Shadows are not supported by the default sprite shaders. Setting castShadows/receiveShadows to true doesn’t change that.
You have several options though, dependent on the desired effect:
- Duplicate the default sprite diffuse shader and add the surface parameter “addshadows”. To get cutout shadows you’ll need to change the fallback and introduce the _Cutout material parameter as well.
- Simply use Quads straight away as @Eric5h5 stated (so using the MeshRenderer instead) and alpha cutout shaders.
- Use invisible shadow casters (although these might not necessarily interact well with you sprite animations) i.e. create you shadow meshes and use a shader only invoking the vertex lit’s shadow collector and caster passes (this technique is helpful if you want “shadow shafts”)
Pic of options 1:

And option 3 used for “shadow shafts”:

Hey Trevex, thanks for the info!
I’m a complete shader n00b - can you post that modified shader code for option 1, or let me know the syntax for adding the surface parameter, and introducing _Cutout material param - I can probably muddle through this, but if you have the code handy much appreciated ![]()
3 looks like a cool option - did you use the 2d volumetric lighting plugin for that or is that something you rolled yourself? Your game looks cool! Been playing a lot of starbound lately, and while not for my current 2d project, at some point I want to take a look at doing something similar to their lighting system.
Trevex,
I’m trying option 1 and for some reason I can’t get it to work. Could take a look at my shader and point me in the right direction to solve the problem, please?
https://www.dropbox.com/s/b93m7jnd541a8j4/Sprites-Bumped%20Diffuse.shader
Hi
I’m curious - how did you get the characters’ shadows to project large like that? Your lighting is really nice and would love to know how you did this. I’m only learning now about lighting/shaders etc, and would really appreciate the advice.
Also, anyone have any updates yet on projecting shadows from sprites with Unity 2d? I have the CutoutShader mentioned above, too, but as mentioned, it doesn’t work. I’m currently using the sprite>diffuse, but no shadows
You need to actually use the Lit3d cutout shader, if you’re using the sprite → diffuse it’s not working - that’s the reason why I posted ![]()
Hopefully @trevex can drop a bit more mad shader knowledge up in here
Since my shader involves a lot more than just the shadow part here is a short guide on how to enable shadow casting on sprites:
-
Get the unity shader sources, duplicate the Sprite-diffuse.shader and rename it
-
Add the addshadow parameter to the surface shader, i.e. Line 28 will look like this:
#pragma surface surf Lambert alpha addshadow vertex:vert -
As previously mentioned castShadow needs to be set to true manually
-
You should now be able to see shadows casted by your sprite, although they will be most likely squares.
-
To solve this the shadow caster of the cutout shader needs to be used. This can be done by changing the fallback to it, i.e. Line 60 will look like this:
Fallback “Transparent/Cutout/VertexLit” -
The cutout shader also needs the cutoff value, otherwise you’ll still have just squares, so add it to your material uniforms, i.e. add this after Line 7:
_Cutoff (“Shadow alpha cutoff”, Range(0,1)) = 0.5 -
See your shadows in action!
Knowledge dropped! Going to check this out - will post results. Cheers!
The shader I posted above has all these modifications you suggest, trevex, and it still doesn’t work :S
I tried doing it from scratch anyway, and no success.
Please Jesse, let me know if you achieve anything.

