July 10, 2013

Graphics 3-4: light me up

Evening, our loyal followers. This bulletin comes a few days early, as no new tech is expected for the rest of the week, just testing and tuning.

These weeks were about lighting, and now we have a running light prepass system. It could be described as more of a hybrid, read on to find out the butler did it.

So what is light prepass?

In traditional forward lighting, you draw every mesh, and each mesh runs a loop over all lights to see if they happen to touch it. As you can imagine, this is inefficient the moment you have more than one light.

The first good solution to this, deferred rendering, draws the mesh data to a set of temp buffers containing the position, normal, and other values. Lights are additively blended to the main image based on the values in the temp buffers.

It works, but it's inflexible in the amount of material variation it can do. Light prepass was designed to be both scalable and flexible.

In light prepass, less mesh data is saved: normal and depth only. The lights are additively blended to a light buffer, then the meshes are drawn, and they decide what to do with the gathered amount of light.

Our new system is light prepass, but by default it avoids the double draw of each mesh, blending the lights with a standard screen quad.

The moment the flexibility is needed, a mesh can draw itself and interpret the light data as it sees fit; but by default, there is only one draw call, as most meshes use the light data in a standard way.

Here we have the first step, ambient light, working. Yours truly has a fascination with the color red; he thinks nothing more of it, perhaps he should.

It's a normal world. This is a new debug view, showing what a normal world looks like, on a normal day. It has already revealed issues with two karts, which would have made them react badly to light (think badgers and mushrooms).

The next frontier after ambient light, point lights. The picture is from a new old map, red light district, with kindly visualized lights.

The other topic for this biweekly session was rim lighting for the karts.

First, one needed to identify the karts, and paint them in this spring's fashionable colors. It may look like red to the untrained eye, but in reality it's a mix of Indian red, crimson, and salmon, with just a hint of blueberry and salvia.

Rim lighting in the graphical world is a trick with normals. You compare the surface's normal with the direction to the camera, and visualize the difference with suitable colors, giving each kart a bit of shiny edges.

That's it folks, a short post this time.


  1. You're going to make STK look so much nicer, it's hard to even visualize. THANK YOU. SO much.

  2. Cool, did you share the code on svn ?

  3. I downloaded SVN code, and ran throw a few tracks... Amazing! The mines track is is stunning with the lights

  4. fun, informative, inspiring. thank you.