Deferred 2D Lights continued

The lighting engine is available on Github here. The code also includes a example project that creates the brick wall in the previous article.

How does this work? I use a normalmaps.  The normalmap stores for each pixel what direction it faces. This way it ‘tells’ the engine if a pixel should be lit when light comes from a specific direction. Normalmaps are quite common in 3D graphics but can be used in a 2D context as well.

Now the game should render the gameworld twice: once with all the color information (the regular graphics we’re used to) and again with the normalmap information. It means that you should have your game assets twice.

For example; this is a test dungeon in Tiled:

  1. Note the 2 layers, one is the “diffuse” or colormap of the dungeon, the second (‘hidden’ in the screenshot) is the normalmap information.
  2. Note the 2 tilesets. These have identical tiles. You can optimize this to have both the diffuse and normal data in one texture.

You can create these normalmaps using tools such as Sprite LampSprite Illuminator, Sprite DLight  or this plugin for GIMP.

Draw the Tiled layers in your game to the diffuse/colormap and normalmaps and you’re good to go:

The screenshot isn’t the best example of what’s possible but there are several of good examples out there that use this to great effect such as Legend of Dungeon (see the Devlog by RobotLovesKitty) or Full Bore (also a Devlog worth checking out!).

Take a look at the code on GitHub and be sure to have a look at the example code!

Geef een reactie

Het e-mailadres wordt niet gepubliceerd. Verplichte velden zijn gemarkeerd met *