Sign in to follow this  
OrangyTang

2D Sprite shadowing methods

Recommended Posts

You may or may not have read my dynamic 2d soft shadows article, which IMHO is quite nice and gives good results. However the snag with it is that like 3d shadow volumes it requires actual geometry to extrude, so doesn't work for sprites. Now I've got a crazy idea to do a different technique, almost a 2d version of traditional 3d shadow mapping, which would produce similar results but would work for any alpha-tested geometry. So before I start looking into it properly I'm interested in what other techniques there are out there. From what I've seen there is the old method of specifically drawn sprites for shadows, or tile-based LOS methods like those used for fog of war in Baulder's Gate. Gish is the only recent attempt to do it differently, and that just uses hard-edged shadow volumes in 2d (and came out way after my original article [grin]). They don't even attempt to fix the sprite problem - they just don't cast shadows from the sprites. Anyone seen anything new/different that I've missed? Or other thoughts on generating shadows for 2d sprites? Cheers

Share this post


Link to post
Share on other sites
Anyone? I've been poking around looking for related work, but it almost seems to be a dead area. :( My idea isn't even that complicated, it's just adapting shadow mapping to work in 2d, so I find it hard to belive that no-one else has done it yet.

Share this post


Link to post
Share on other sites
Its seems kind of foolish to apply 3d shadowing methods to 2D.. when in reality 2D graphics cant be lit like 3D. A better approachmay be to use some kind of "fake" approach. Here is an idea that might work:

render your sprite from the camera view to a texture, then map this on a flat quad, which you can then warp by some projection matrix, this would then produce appearance of a correct shadow in many circumstances.

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt Aufderheide
render your sprite from the camera view to a texture, then map this on a flat quad, which you can then warp by some projection matrix, this would then produce appearance of a correct shadow in many circumstances.

I think you're a little confused - I'm not talking about generating shadows for billboarded sprites in a 3d world (regular shadow mapping would work in that case), but for generating shadows for sprites in an entirely 2d world, and casting those shadows onto the rest of the sprites.

Share this post


Link to post
Share on other sites
You're right, what i suggested doesnt make sense does it? I cant see any way to use shadow mapping to do what you want.

What about some kind of fake per-pixel raytracing? If restricted to 2d, maybe you can make it fast enough...

But who uses 2D anymore anyway? Id say if you want to use 2d dont bother to do advanced rendering...its jst a bad hack otherwise.

Share this post


Link to post
Share on other sites
I think one of the difficulties you will face is that most 2D games are not strictly 2D in the mathematical sense. In nearly all 2D games, there is some 3D aspect that is either faked or implied, if only because our brains simply assume it's there.

Taking any two overlapping sprites, and a light-source equidistant from them, how do you decide who shadows who? Ultimately I believe you have to make some assumptions about how things relate in the hidden third dimension.

I also fear that by extracting a shadow from texture data, you will betray its true 2D-ness that we often work so hard to cover up... A Barrel (viewed from the side), for instance, is drawn to appear round even though it is a flat texture. How will you compensate to draw a shadow that appears correct? What about more essoteric shapes like half-barrels or extruded crescents?


All the more power to you if you've come up with a technique that works, but I suspect that the reason you're having difficulty finding an existing example is because the results simply don't warrant the effort required.

Share this post


Link to post
Share on other sites
I played around with this quite some time ago, so I've forgotten some of the details. My approach was to include a shadow polygon for each frame of a sprite, defined in an editor I came up with. Indeed it was a little tedious to create these, but you only needed a rough approximation of the sprite shape to get good results. I think I also had to modify the shadow generation code to allow for a concave polygon. In the end, it was a bit of a hack, and probably not practical for anything more then a little tech demo, but it worked.

Share this post


Link to post
Share on other sites
The way I see it, the only major different between casting shadows from sprites and casting from convex shapes is the silhouette detection for generating the extrusion.

Instead of trying to adapt shadowmapping into 2D, I think it would be easier to extend the shadow volume extrusion to work with sprites, since the shadow-volume approach is already well suited for 2D.

There are a few approaches to shadow volumes which use image-based techniques for silhouette generation. I think NeverWinter Nights uses such technique. It might be possible to do something similar in 2D with much better performance.

A drawback that immideatly comes to mind is the seemling unavoidable need to process the whole sprite to determine the shadow edges, but maybe you can use some variation of the horizon-mapping trick used for self-shadowing normal mapping.

Share this post


Link to post
Share on other sites
hi. just a random thought, since I've been playing with ambient occlusion recently:

for the sprite casting a shadow onto the ground or itself, have 2 textures; a ground texture and a sprite texture (RGB encodes the bent normal in world space either scaled already {so you can use a simple DOT3 computation to get results}, or A can encode the occlusion value). The ground texture can be used to show a soft shadow under the sprite (so it's decaled onto the floor, under the sprite's feet). The sprite texture would be basically the same thing...a bent normal map but for the sprite geometry itself.

This would be for self- and flat ground-shadowing only, so it's probably not what you're looking for, but might look fairly nice with moving lights.

edit: this could look really cool when rendering imposters! render the geometry with the (properly rotated) normal vector stuffed into the color for each vertex!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this