I've got a an OpenGL scene rendered with a bunch of sprites, and I'd like to automagically add drop shadows to all of them. Here's a picture showing what I mean:

enter image description here

The scene uses orthographic projection, the sprites are textured quads, and I'm using the depth buffer to draw them front to back. I'm working with OpenGL ES 2.0, but thoughts from the iOS or non-ES worlds would be appreciated as well. I've tossed a few ideas around in my head of how I can go about this, and I'd like to find out which has the most promise.

  1. Draw each sprite twice, the first normally, the second with some kind of drop shadow shader a bit deeper in the scene. Not sure if this is possible?
  2. Draw a sprite, then draw it again, darkened and with some alpha, several times with some random jitter applied to the verticies. This may look silly and not at all like a shadow.
  3. Draw the base scene without background to a texture, then blur and darken it to create one large drop shadow. Then draw the base scene over the drop shadow texture, then finally over the background. This would lose the shadows between sprites, though.
  4. SSAO in a post-processing pass. Might be the most dynamic and automatic, but could look fuzzy/grainy and really slow things down.
  5. At creation time, generate a shadow texture for each sprite. For rendering, draw a sprite and then its shadow texuture a bit deeper in the scene. I think I'd like to avoid this due to the loading time and extra memory requirements, but this may be the fastest and best looking?

I don't want to do any shadow work with external textures, since I use the same sprite textures at varying scales, and pre-baked shadows would scale unnaturally.

So are any of these better than the others? Are there other options I'm not thinking of? Thanks!

  • \$\begingroup\$ I would try out #5 and see if the cost is too much. It doesn't seem that hard to set up. \$\endgroup\$
    – Kevin Reid
    Commented Mar 9, 2012 at 13:42
  • \$\begingroup\$ Yeah, I'm leaning towards that too. I'm sort of new to this sort of work in OpenGL - would I use an FBO and render each of my sprites to new textures using a drop-shadow shader? Turn this into an Answer and I'll probably accept it! \$\endgroup\$
    – Josh
    Commented Mar 9, 2012 at 14:59
  • \$\begingroup\$ I'm not familiar with implementing image filters, sorry. \$\endgroup\$
    – Kevin Reid
    Commented Mar 9, 2012 at 18:16

1 Answer 1


Your option #5 — generating shadow textures — has a low per-frame cost compared to performing blurs, is readily customizable, does not introduce a lot of complexity in other areas of the rendering process. I recommend trying it out and seeing whether the memory/startup cost is too much before investigating the other options.

Since you are using the depth buffer, you will need to draw the shadows after the opaque sprites and use a subtractive blend function, to avoid drawing-order dependencies.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .