Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lighting

Started by unreason Jun 21, 2004 at 12:49 PM 6 replies 950+ views
Original Post
unreason
unreason
I'd like to use 2D tiles to create an Isometric game, but I'm trying to figure out a way of doing lighting (and shadows if possible). Staticly, of course, this can easily be done in advance. But does anyone know any methods for dynamic lighting and shadows in a 2D isometric tiled environment? Since the tiles are really only 2D with an illusion of 3D, I can't really use the standard algorithms or methods. Obviously I could color vertexes, but I was wondering if there were any better ways I could handle this....
JTippetts
JTippetts
Coloring vertices works "well enough" for most isometric games. Simply lighting 4 verts per tile can result in fairly "chunky" stair-stepped shadow edges, so for increased shadow detail it may be desirable to split each tile up into a grid of vertices (3x3, 5x5, 7x7 or whatever) and light each vertex.

Standard lighting algorithms of course will apply. For simplicity, I typically use a straightforward (Range-Distance)/Range calculation for each point, using the radius of the light and the distance from the light center to the point being lit. To avoid square root calculations, (Range^2-Distance^2)/Range^2 can be used instead, which will give a quadratic fall-off rather than a linear fall-off to the light pool.

Objects sitting on a tile, such as walls or characters, can derive their lighting values by sampling the vertex grid location they are closest to, or by sampling a number of vertex grid locations as in the case of a wall. This is quick and dirty, but in the case of tall walls your wall will be evenly lit for it's entire height, without regard to the distance of the wall's top vertices to the light source. A quick hack to fix that might include attenuating the light values derived from the tile by a factor of the distance of the top of the wall from the ground. This may or may not be necessary, depending on your game.

Each vertex will be lit by a given light source as long as an LOS calculation from the light source to the vertex. I typically use grid-based LOS. Conceptually, I draw a line from one point to the other, and locate all the places where the line crosses a tile boundary, either in the X direction or in the Y direction. These intersections can be found by finding the first intersection in each axis, then stepping along the line using the tile dimensions as step values to calculate subsequent tile boundary intersections. The tile on each side of an intersection is checked for solidity.

You can, of course, make use of hardware accelerated lighting if your tiles are drawn as triangles or quads in OpenGL/DirectX. Simply set up light sources as you would in a standard 3D game, and assign materials to your tiles for lighting parameters. Of course, video card limitations will apply in that case.

I hope that helps a little, and good luck.
Ilankt
Ilankt
VertexNormal, I saw you are doing a 3D version of your game!
it looks very nice!
How appropriate, you fight like a cow!
Daerax
Daerax
Your best bet would indeed be vertex lighting as I believe this fellow over here did. As for shadows, in a 2D game accurate shadows are an unrealistic goal. You could have the shadow be a part of the real image but that would be a waste of space. Nonetheless it is up to you.
Archi
Archi
Quote:
Original post by OrangyTang
Quote:
Original post by Daerax
As for shadows, in a 2D game accurate shadows are an unrealistic goal.

*cough* With a little tweeking I'm sure it could be adapted to an isometric perspective as well.


But still not the dynamic shadows.
Daerax
Daerax
Quote:
Original post by OrangyTang
Quote:
Original post by Daerax
As for shadows, in a 2D game accurate shadows are an unrealistic goal.

*cough* With a little tweeking I'm sure it could be adapted to an isometric perspective as well.


I apologize for having not thoroughly read your article but from what I skimmed does not your shadow system only work for polygons and not sprites? Would it not be incompatible with 2D bitmap images?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.