NEP Dev Update #2: The lighting engine

by Cuchaz
BEHOLD! LIGHT!
A screenshot of the game with pretty lights Click on images to enbiggen.

At long last I'm done with the lighting engine for my indie game, Non-Essential Personnel. For now, anyway.

I've finally crossed that glorious rendering threshold where screenshots of my game compress better as JPG images than PNG images! =D

What can the lighting system do?

NEP's lighting system has a lot of nifty prettiness-inducing features. Here's a quick overview.

A screenshot from the game showing lots of different lighting effects Diffusive lighting! Light spreads out from light sources, illuminates walls, and penetrates into blocks.
Thousands of simultaneous sources! Each sky block is actually a light source.
(Don't worry, that stone texture isn't final.)
Lighting effect detail Subtle shadows from light occlusion.
Lighting effect detail Subtle highlights also from occlusion.
Lighting effect detail Diffusion through the atmosphere! Notice how the light seems to "bend" around corners.
A screenshot of the game showing how textures are affected by lights Bump mapping! Sprites are lit with directional lights. No need to bake lighting into the sprite textures.
A screenshot showing light sources blending together Continuous blending! Notice the gradient on the roof of the cavern and walls. In the center, the lights blend to mostly white.

Shiny! How does it work?

Lighting systems are tricky. People are really good at looking at things. I mean really good. If something doesn't look right, you usually notice pretty quickly. Take a look at these two light sources.

Two different lights look different sizes Two light sources. Both red, but they're different somehow.

The one on the left looks pretty good, but the one on the right looks weird. It's hard to say why it's wrong though. It looks too bright somehow. Turns out, I changed the shape of the falloff function for light intensity. Physically, light intensity falls off exponentially from the source and anything else just doesn't look right. Lighting systems are full of little details like this, and if you don't get them just right, things just look weird.

On top of just looking good, the game has to run without any hiccups or pauses, so the lighting system needs to run in real-time. Voxel games in particular are extra tricky, because any block could be a light source. That means one scene in the game could have thousands of light sources in it. Designing a lighting system that runs at 60+ fps with potentially thousands of light sources is definitely challenging.

Lighting systems are hard, and I don't claim to be an expert at this, but here's one way I got something that looks pretty good. If you want to get into the nitty gritty details of my lighting system and how it works, read on. =)

The Technical Details Part 1: Shaders and materials

The Technical Details Part 2: Diffuse light

The Technical Details Part 3: Light channels