Unity 2d Lightning; Casting chadows

I’ve been looking around for a few hours and can’t really find any up-to-date guides on how to deal with lightning in 2d.

I am making a top-down game and want the simplest type of shadows, like in the Image (Stardew Valley) below. I suspect the shadows here are actually drawn on the tiles themselves. Which I guess is a plan B, but is there some way to achieve this in Unity with lights and shaders? I’ve downloaded some toolkits, and played around with lights and shaders, but no real success yet.

There are a couple of things you can do.

You could write an actual 2D based shadow renderer, like described here, but it is somewhat costly, and will most likely only work well when using a sideview. For an ISO or Top-Down perspective, you just don’t have enough information in the sprites themselves to do convincing shadows.

That said, there are ways to alleviate that, which we experimented with for a while. Essentially, you build an actual 3D mesh that approximates your sprite, and manually project the sprite on top of it. Looks a bit like this:


This gives you an actual 3D mesh, with which you can cast (and receive) actual 3D shadows. There are some downsides to this, for one the workflow is quite convoluted (and obviously much more work than just dropping sprites), and the shadows tend to end up looking too realistic, which might not be what you’re going for.

I think most games go with some form of sprite based shadows. Either just simple blob shadows (probably the most common), or you can take the actual sprite and skew it to align with the floor. The latter can be a bit tricky in practice, since they obviously won’t behave like actual shadows do, but might be enough depending on what you’re going for.

Can also do some simple tricks with the blob shadows to somewhat follow the lightsource and/or mask/blend with lightsources so that they are only visible when in range of a light source.

1 Like

Great answer, thanks a lot!
Could you expand on blob shadows? Or link to some information on it? :slight_smile: No idea what it is.

I think a far simpler approach would to just have a sprite with that level of darkness and transparency move across your scene at the top most layer. Would take less than an hour to put the art and code together.

1 Like

Literally just circular ‘blobs’ beneath the character, like this:

They are usually done as a separate, semi-transparent black Sprite that just moves with the character. For Trees etc. you can make somewhat more sophisticated blobs, but might be a good Idea to keep them separate regardless. That way you could for example move them around little bit, to simulate the time of day. Or hide them at night entirely.

1 Like

Hi,

You can also use SpriteRenderer and 2DxFX : Unity Asset Store - The Best Assets for Game Making

(at 0:25)
To achieve that result, you need to rotate the y of your sprite a little, so the shadow can be projected in the background. You need to thinks in false 3D.

Hope it’s help.