Let there be light!

For all intents and purposes Gladius is a 2D dimensional game viewed from a top-down perspective.

This is Gladius. Looks pretty ugly and flat.

The issue with this particular paradigm is that it’s difficult to create a sense of depth. Without depth the scene looks dull and it’s sometimes difficult to telegraph to the player what is supposed to be below or above them.

Most older games got around this by using an isometric perspective, like Age of Empires. Other games like GTA2 used 3D buildings on top of a flat plane to give an impression of depth.

All these games had the same issue. They didn’t have the access to modern hardware that we do now. Now we have the liberty to throttle our GPU’s and use 32 gigs of RAM to render our retro 16 bit platformers. (jk)

We can put this greater computing power to use and use it to light a scene. Light can create the depth that we need.

Gladius with a dynamic point light. (WIP)

Above is the initial draft of a 2D dynamic point light in Gladius. Already the scene is far more interesting to look at, with shadow’s being cast behind the collidable geometry.

The light here is just a simple polygon. An attached light texture creates the effect of fall off in the brightness.

Per frame the light searches for occluding geometry within a given radius. Because Gladius uses a tile system, this is relatively easy and the occluding shapes are simple quads. However this technique can easily be extended to pick up any sort of geometry of any sort of shape (in 2D obviously).

We then loop through all occluding edges and clamp these to the nearest ray cast angle. This is a ray cast from the point centre of the light. Effectively we perform a ray cast backward from a point that we know is occluded.

If this distance is shorter than the last ray cast distance at this particular angle then we overwrite this ray cast with the new distance. We then draw the polygon at the given angles and their corresponding lengths.

Because it’s a simple shape with alpha we can layer multiple lights of different colours.

Obviously there is a bit of tidy up involved to hide the odd edge that may snag or look weird. But even in it’s simple state it’s pretty nice to look at.

It’s not a brute force ray cast so we can have many lights without a significant drop in framerate.

Fully dynamic. Shadows can get cast at run time. (The odd artifacts are to do with the encoding of the GIF)

There’s still quite a bit of work to be done though. We could probably smooth out those hard shadow edges with a nice shader and perhaps find a way to offload more work to the GPU rather than the CPU.

Overall you can get some very nice results relatively easily. It’s surprising how much light can add to the character of a scene.

Leave a comment

Design a site like this with WordPress.com
Get started
search previous next tag category expand menu location phone mail time cart zoom edit close