Testing shadow mapping

In Alien Blitz lights are computed using a mix between a 2d light texture and some custom code to get smooth lights are avoid artifacts on walls.

It’s a good solution as it is requires some time when loading level but it is quite quick afterwards.

I’ve decided to try to implement shadow mapping, I don’t know if I will apply it to Alien Blitz, maybe just the PC version. We will see… but it is still a good exercise and I’d love to see what it could look like.

I’ve not at all completed the task, but I’ve decided to post some “Work in progress” screenshots.

The scene

I’ve made a custom level, with just some basic walls and one light, here is the current result


Light point of view

In order to generate the shadow map we need to set a camera on the light itself (what the light can “see”). For testing purposes it is easier to actually use the game camera first.

For the first tests I’ve decided to use a directional light, point lights need to generate 6 textures (surrounding cube), so I will do that later. This light “looks at” and follows the player


Depth map

And now the shaders need to be changed to only get a depth map


(the UI elements are added after the 3d rendering, so they will not be saved when using a framebuffer later)

The black & white are inverted in this screenshot, else the wall in the back would be almost invisible/pitch black.

Using a frame buffer

Next step is to revert view to its original state and use a frame buffer to render the light’s camera.


Black and whites are now correctly rendered, I’ve changed the FOV on the camera to be able to view the pillar with the 1:1 ratio (1024×1024)

(I’ve saved the texture using the screenshot code from libgdx, it just needs to be called before ending the frame buffer)

Applying shadow/depth map

Removing previous lighting


First try



Something is happening, it doesn’t crash, and lines move when player moves, we’re getting there


After some correction


Hmmm it looks like letters and signs… Oops forgot to bind the texture, so it’s using another one (the one used by the font apparently)



Something is obviously off



Hey! it looks like there’s a small mecha there…



Ok, there’s obviously a mecha there, and it moves accordingly. Good, but there are way too much artifacts…



After a bunch of tests and corrections, pillars’ shadows seem correctly placed, but the light does not go far away (should illuminate walls), there doesn’t seem to be any shadow for the mecha and there are still artifacts…



Some more tests, still a lot of artifacts but I’m beginning to like what is displayed…



Haa a lot better, let’s remove the right part



Nice, I also have the “expected” artifacts near the center of the light. They are normal artifact due to distortion, they are to be expected at this point (and corrected afterwards of course).


A small video

What’s next ?

This was a simple example with lots of limitations

  • Shadows are computed each frame
  • Only one light
  • No light color
  • Badly written code

So there’s lots of code to do… but it’s a start and I’m pleased I’ve been able to get some shadow mapping so fast.

Comments are closed.