Post news RSS Lighting in K.I.S.A

A devlog post about the lighting engine in K.I.S.A, with a couple of reasons explaining why it's so fast.

Posted by on

Kisa in moonlight and torchlight
Kisa in moonlight and torchlight.

I had it relatively easy when it came time to create the lighting engine for K.I.S.A. Because the game world is purely 2D, I didn't have to worry about normal mapping, ray tracing, or anything that ends in -ometry. Still, there are a few things about K.I.S.A's lighting engine that I find interesting enough to share.

I'm not going to get too deep into the base workings of the lighting engine, because what the engine does is very boring and common. In a nutshell: I draw gradients onto a surface (canvas for you non GameMaker folks), then render that surface over the top of the game area with blend modes.

Below are 3 lighting practices used in K.I.S.A that are not, to my knowledge, common and boring:

The lighting surface is not the size of the level. In K.I.S.A, levels sizes measure in the tens of thousands of pixels - surfaces of this size would not be feasible. Surfaces take time to draw on and take up memory just by existing, so they should be as small as possible. In this case, I made the surface equal to the size of the game window and always draw the surface at the (0,0) position on screen. When I render the lights, I offset their coordinates so that they are correctly positioned relative to the position of the game window.

Coders reading this are probably thinking "This is obvious! There's nothing special here!", but I see too many games and tutorials that make use of massive surfaces. I desperately wish that this was common and boring, because it should be.

The lighting surface is scaled. I lied earlier. The lighting surface is not the size of the game window: it's smaller.

I think that very few games require pixel perfect lighting, and K.I.S.A is not one of them. It's just not necessary. The beautiful thing about scaling is that it's not a tradeoff between quality and speed, because there is next to no sacrifice of quality. The nature of lighting usually means thatscaling does not significantly affect the quality of lighting. Lighting in K.I.S.A is all about gradients, and gradients are one of the few things that interpolated scaling handles very, very well.

The left image is 50% quality, the right is 100%. Can you tell the difference? (Click to enlarge)

In K.I.S.A, the highest quality lighting sets the scaling at 50% and the lowest at 25%. This means that the lighting surface is drawn at 25-50% size, and then stretched to fill the game window. 50% scaling is nearly indistinguishable from 100% quality, and if I did not have to worry about straight edges, which interpolated scaling does not handle well, I could afford to go much lower.

Scaling is a really simple way to speed up a 2D lighting engine, with almost no loss in graphics quality.

The lighting is not static.
Light floods into doorways, torches flicker, etc. This is pretty common in 3D games, but I do not see it very much when I play 2D games. I'll let this final image speak for itself.

Kisa intimidates doors into opening by punching them.


wow, nice and fluid moves.

Reply Good karma Bad karma+1 vote
Oracizan Author

Thank you! We're using skeletal animation, which makes animations really smooth and memory light. I'd like to also point out that this was screen captured at 20fps, so the game proper looks about 3x smoother at 60fps.

Reply Good karma+1 vote

Wow, Amazing work. I'm thoroughly enjoying reading everything about this game because I'm a GMS user myself. I just hope there's more coverage on the game and its mechanics.

Reply Good karma Bad karma+1 vote
Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.