Love2D Lighting Demo

What

This week I have worked on a playable demo of our game as to test efficient and good looking methods for lighting in out game. The demo is written by me ground up in the Love2D framework. I chose Love2D because of how many of the modules it shared with SFML and the similarities of the features provided in the framework.

How

The first problem I wanted to solve was “how can we make lighting without mask shaders” as I have had bad experiences using masks in the past. So disregarding raycasting for the lighting, I thought to use blend modes with textures instead. I originally had the idea of using the ”add” blend mode when drawing the lighting as this seemed logical, in that it raises the value levels of the colors just like real world lighting does. Tove pointed out that this wouldn’t work as the color resolution of the background would create artifacts when raised.

I have visualized this below using a darkened image of a cat. The left image shows a portion of the image with raised levels experiencing a posterizing effect. The middle image shows the RGB color resolution of the left image before raising the levels, whilst the right image shows the color resolution of a grayscale gradient.



 

I solved this by lowering all other colors instead. This was achieved using the ”multiply” blend mode which actually provided solutions for many upcoming problems such as colored lighting and the adding of multiple light sources.

I first tested this technique in Adobe After Affects to see if the method would be cinematically pleasing. This is a rendered video of the test:

 

After seeing how well the technique worked I started making the prototype. The first step was figuring out what how I would layer the sprite drawing logically and practically. The finalized model uses two framebuffers holding the diffuse drawings on one and the lights on the other. The player is drawn after the light but can be incorporated in the first pass and other passes such as bloom and blur can be drawn subsequently.

This proved to be very efficient in the unoptimized Love2D demo with up to 8 players with individual lights. This is a screen recording of the first Love2D demo:

Why

The demo did not only provide a practical preview of the in-game graphics and rendering information, but it also allowed for quick gameplay testing. We could test using the light strength tactically (which the game encourages) and see how light spills through walls thinner than the light range. We also got a better understanding of the control scheme in practice as this had mixed interpretations in the group.

Personally I got to practice some coding for future tasks while developing the demo, as well as getting a better understanding for the framework modules.

 

About Oscar Selstam

2015 Graphics