Subscribe to WolfCoder's Kawaii Column        RSS Feed
***** 1 Votes

LandTraveller - Bizarre Lighting Engine

Icon 1 Comments
Posted Image

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:

Posted Image

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).

Posted ImagePosted Image

The current source code for the light tiles can be found here.

UPDATE

Nevermind, I was able to get the dynamic lights to work easily:

Posted Image
Posted Image
Posted Image

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

Maplestory Icon

27 June 2013 - 01:38 PM
I LITTERALY BANGED MY FIST ON THE DESK SCREAMING "THAT IS SOOOOOO SICK!!" and I think my mom heard me. This is the first blog I seen so I guess it was a shock seeing a game taking the middle route between minecraft and terraria. I HAVE NO IDEA how the hell you coded this "Mainly cause I dont know anything yet" but DOOODE THIS IS FLIPPIN AWESOME!!!!! YES! I WOULD PLAY THE SHIZZLE OUT OF THIS GAME!! keep up the good work :D :D :D :D :D
0
Page 1 of 1

August 2014

S M T W T F S
     12
3456789
10111213141516
171819202122 23
24252627282930
31      

...

...

Information

Information