I have a game idea with lots of pretty lights (literally) in mind that I would really love to implement, but I have essentially zero experience with shadow mapping, deferred rendering, the lot of it. I've done some research into 2D shadow-casting, and I think I might try a method similar to this, but I haven't a fathom how to create a virtual rectangular manipulation of a polar image (from the point-light's perspective on the map).

My question: How can I create a virtual rectangular manipulation of a polar image whose process is quick enough that it can be run twice per frame every time a light moves in-game?

I'd like to be able to handle at least 4 dynamic lights on-screen at any time, but I'll take what I can get. I've started to learn OpenGL, so hopefully this isn't too high above my skill level.


closed as too broad by Josh Feb 26 '14 at 16:12

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ Try out this tutorial redblobgames.com/articles/visibility I implemented it in XNA and I have to say it is pretty fast indeed! \$\endgroup\$ – Roy T. Feb 25 '14 at 18:20
  • \$\begingroup\$ Um, how did this get changed back? This post was heavily edited from this version. \$\endgroup\$ – igrad Feb 26 '14 at 16:30
  • \$\begingroup\$ It got rolled back because the answers (including the one you accepted) didn't address the modified question, but instead the original :( \$\endgroup\$ – Josh Feb 26 '14 at 16:35
  • \$\begingroup\$ (Since comments shouldn't be used for extended discussion, if you want more information I can explain it to you in the Game Development Chat). \$\endgroup\$ – Josh Feb 26 '14 at 16:36

2D Shadows Via Shader

Here is a link to a very good article on implementing a 2D shadow mapping system. Also see here for a slightly different version.

These techniques have the advantage of working on all 2D objects, even those with complex shapes as a result of transparency in their textures. These versions are reliant on fragment shaders but if you are working with opengl or directx this should not be a problem.

These techniques also have the advantage of being very efficient and only scaling with the screen resolution. In other words; increased image complexity will not result in a change in performance.

2D Ray Casting

Some other techniques are more akin to ray casting. The link posted by Roy T. is an excellent example.

Often these techniques involve casting rays towards vertices of scene geometry to test visibility, but sadly they require that all shadow casting objects have a geometric definition. Luckily this is often a requirement anyway since many games feature a physics engine which has a similar requirement and so there are plenty tools to help create these definitions for your art assets, such as this.

A further drawback to this form of 2D shadows is that its complexity scales with the scene geometry complexity. Adding more objects to the scene means, not only more vertices to test the visibility of, but also more objects to detect ray collisions with. So unlike the technique above, you may find that this technique limits your scene budget.

However, the advantage to this technique is that it's fairly straight forward to understand/implement. Also, it can generally be applied in any system, whether your using C++ and opengl or HTML5 and javascript. That being said, shaders are becoming more ubiquitous.

There are, of course, some very good reasons to use this method. Firstly, you may have actually already have most of the main functionality required or are planning to implement it for other reasons; efficient ray/edge intersection testing and 2d object geometry as an edge/vertex list. Secondly, you may find that for your typical scene or the rendering system you happen to be using that this method is more efficient than the shader based shadow mapping. As always, picking the technique is entirely based on why you want to use it.

Something Hacky

As a little extra that doesn't really address the question - if you fancy a simpler, hackier method and you are lighting an appropriate tile map based scene (or just one with a really low resolution) you can always try light propagation. Use Bresenham's Line Algorythm to cast rays out along the tile map from the light source until you reach a non-empty cell, reducing the light contribution at each step.


Not the answer you're looking for? Browse other questions tagged or ask your own question.