Razorblade's Isometric Dynamic Lighting Algorithm
In most isometric engines, the light source is directional and is permanently fixed when the tiles are created. At the time of writing, there is only one isometric game that I know of that has point light sources, which is Command & Conquer 2: Tiberian Sun, but it has not come out yet as of writing this.
The approach shown here uses specially made tiles in which each pixel has two values. The first value is a value which is the RGB color of the pixel, and the second value is a 8-bit value which designates the direction the pixel faces. The 8-bit value is actually a two 4 bit values, one which is the rotation of the normal of the pixel around the y axis in a right handed system, and the other being the elevation of the normal of the pixel. The rotation is from 0-15 with 0 designating 0 degrees, and 15 designating 360 degrees. The elevation is from 0-15 with 0 designation straight down and 15 straight up.
Before each tile is drawn while rendering, a table of lighting values (monochromatic or RGB) is calculated using the locations and distances of each light source. The rotation/elevation combination for each direction acts as an index in this table. Here is pseudocode for calculating this table in with simple monochromatic dynamic lighting as well as ambient lighting:
calculate tile lighting table
zero out table
from i = 0 to i = 15
from j = 0 to j = 15
table[j] = 0
calculate point lighting
from i = 0 to i = number of light sources
distance = sqrt( ( tile.x - light.x )^2 +
( tile.y - light.y )^2 + ( tile.z - light.z )^2 )
if distance^2 < light.intensity
received_light = light.intensity - distance^2
if abs( light.x - tile.x ) = 0
if light.x - tile.x < 0
rotation_angle = 0
else
rotation_angle = pi
else
rotation_angle = atan( light.z - tile.z / light.x - tile.x )
if abs( light.z -tile.z ) = 0
if light.z - tile.z < 0
elevation_angle = 0
else
elevation_angle = pi
else
elevation_angle = atan( light.y - tile.y / light.z - tile.z )
if elevation_angle > pi
elevation_angle = elevation_angle - pi
from r = 0 to r = 15
row_light = cos( rotation_angle - ( 2pi / 16 ) * r ) * received_light
from e = 0 to e = 15
table[r][e] = table[r][e] + cos( elevation_angle -
( pi / 16 ) * e ) * row_light
calculate ambient lighting
from r = 0 to r = 15
from e = 0 to e = 15
table[r][e] = table[r][e] + ambient.intensityThe direction value with each pixel is used as an index in the lighting table as if the lighting table had only one index, not two indexes. The lighting value is then extracted from the selected location in the table and is used in draw the selected pixel in the tile, but I will not discuss methods of doing this here because they are very dependent on whether the isometric uses indexed or RGB colors, monochromatic or RGB lighting, and other factors, such as quality vs. speed. All tiles must be assigned a location in 3D space in this engine, even if they are assumed to be on the ground do to the details of this engine. Unfortunately, tiles do not cast shadows with this engine.
Related Tutorials
Balancing Game Development and Creative Direction in Indie Production
A practical look at how indie developers can balance creative direction with hands-on game development. This article co…
My Unreal Engine Development Process: From Core Idea to Playable Build
A practical overview of my Unreal Engine development process, covering how I move from a core game idea to a playable b…
Introducing LaneGraph: The Ultimate Road Network Solution for Unity
Discover the power of LaneGraph, a lightweight and flexible lane-based navigation system for Unity. LaneGraph makes it…
Retargeting Mixamo Characters with Root Motion In Unreal Engine 5.4.
I have always found Retargeting Mixamo Characters To have Root Motion is a serious lengthy Tast, Recently I stumbled up…
How To Make A SIMPLE Main Menu In Unity
In this tutorial for unity, i go over how to make a simple main menu for unity, it's an unlisted video because i do not…
Guide to Gameplay Balance
A perspective on competitive gameplay balance, from a background of "shooter" sandbox design.
Discussion
More from Travis Bemann
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion