Home       About Me       Contact       Downloads       Part 35    Part 37   

Part 36: More Lighting

October 6, 2011

I've continued on the Minecraft lighting. I tried using ambient occlusion to preprocess the 3D shapes I added in Part 34. Rays are cast from all the vertexes in the shape, to see which hit other triangles of the shape. Unfortunately, I can only do this at the vertexes. Real ambient occlusion would create a texture map over the entire surface. Since my shapes are simple, there aren't enough sample points to do a really nice job. In Figure 1, you can see the results on the bed and bookcase.

Fig 1: ambient occlusion

The bed has some of the lighting I would expect -- darker on the inside of the rails and frame, and on the ends of the pillow. There should be a dim area under the pillow, but there are no vertexes there to shade.

On the bookshelf, you can see a diagonal line on the inside top left face. This is not due to a computed shadow. It's because there are only four vertexes on the inside face to test. The top-left corner is bright and the others are dark, giving this pattern.

I'd like to do the AO algorithm over the entire shape, but that would mean building new texture patterns out of all the individual triangles, giving each pixel the correct shading. Possible, but not worth it at the moment.

Putting It All Together

To use all this lighting info, I rewrote my shaders to combine the sky light and torch light values from the Minecraft data with my computed "ambient" light. Doing this in the shader means I can vary the sky or torch intensity from frame to frame without recomputing any of the chunks. This would let me flicker the torches the way Notch is doing, or change the color of the sky light as the sun rises and sets.

See Figure 2 for the daylight view, and Figure 3 for night. Click on the images for larger views.

Fig 2: Daylight with ambient light
Fig 3: Night time with ambient light

Here's a video of the final result. The world is from the TwentyMine.com server.

Problems Remain

I have a few remaining problems. Minecraft has a half-high block, and when the neighboring block tries to use the lighting on this cell, it gets zero and turns black. Either Notch has some special rule for these, or I'm not interpreting the lighting values correctly. I'm stumped. See Figure 4.

A similar problem happens with my new 3D shapes which replace the old Minecraft blocks. In Figure 5, there's a crafting table. In Minecraft, you can't see the floor beneath it, so there's no lighting value.

Fig 4: Steps are special?
Fig 5: Minecraft does not need a floor

There must also be more to smooth lighting than I realize. Although corners are darkened the way I expected, ordinary blocks are still not smoothed at all. See Figures 6 and 7. I don't have enough information to do anything more with this.

Fig 6: Minecraft Lighting
Fig 7: Not smooth enough

If someone can tell me what I'm doing wrong, I'll revisit this. But for now, I think I've done enough for a Minecraft data export utility! Next up -- fog, clouds, sunrise and sunset, which will be used in my real game.

No demo this week. There will be one with the next part, when lighting is complete.

Home       About Me       Contact       Downloads       Part 35    Part 37   

blog comments powered by Disqus