This has to have been the strangest and most frustrating thing I've ever written. The problem is that you have 3D lighting information and you want to light the complicated YZ isometric world like its between Terraria and Minecraft. Lighting is very important in terms of gameplay for this particular game, not just visually appealing. It helps you get more a sense of the 3D shape and structure of blocks than without it. Light has always been a gameplay element in itself too for these types of games- some blocks react to high or low light.
There were many solutions, but the trick is that you can't light it too closely and exhaustively because it won't run fast enough, but it needs to be lit well enough that it does its job of giving shape to the objects for this isometric game.
My solution was to add a function that pretends to draw a "light tile" on top of every regular tile, complete with Z-Buffer values. Then the lighting engine culls light tiles under other light tiles to limit the amount of visible light tiles to the visible grid spaces on screen (about 350 or so light tiles). Each light tile may be either a single light value, or a 4x4 grid of "light fragments". Currently, sunlight is calculated for the whole tile and the values become blurred over fragments according to surfaces to produce a lightmap that looks like this:
Sun is actually calculated 1/0 for the tile. A block in the game is exposed to the sunlight, or not. It does not have varying light levels like in Minecraft or Terraria. The gradient you see is calculated after the original 1/0 sun light was calculated. For every tile not yet lit by the sun, a flood-fill algorithm reaches out for the nearest lit sun block position (if any) and finds its taxicab distance Td(dx,dy) = ABS(dx)+ABS(dy) to determine how bright the sun effect should be on this light tile.
Note that these are tiles, not cubes. All volume information is lost when the tiles were flattened into a 2D grid. However, each light tile knows where it originally was in 3D space, so it can calculate all these terms requiring 3D space information. I was able to reduce the strain on the computer to get a lighting model that's fast enough, but I fear what the performance hit will be once I add dynamic point lights from entites and effects (the torches you need to light the underground, for example).
The current source code for the light tiles can be found here.
Nevermind, I was able to get the dynamic lights to work easily:
It's not doing too bad on the performance either, I haven't even tested the engine with all the optimizations you get when you Release Build yet.
1 Comments On This Entry
Page 1 of 1
Page 1 of 1
Find New MMORPG Games!