Archived

This topic is now archived and is closed to further replies.

Zenroth

Direct3d for 2d games and lighting

Recommended Posts

A few quick questions im running into some issues with, please forgive me if ive missed this topic on the forum before I ran a search and came up empty. Now for the question. Im using Direct3d or I guess you could say DirectGraphics(D3D version 8)I''ve been using the spirit interface so far to do 2d graphics.Now my question, I am wanting to add static and dynamic lighting and colored lighting effects to the engine/game. Here is a example of what I mean, say I have a laser and someone fires this laser, I want the tiles below and around the laser(this is a 2d tilebase engine)to gain some color lighting from the laser shot while the laser is on screen. Is there a easy way to do this? Is it possible to do using the spirit interface? If it isn''t no big deal ill make the quads manually and do the 2d graphics that way, then id think I could do vertex type lighting and such im guessing. Any ways any help on this would be most appreciated a answer would be great, a point in the right direction , whatever.

Share this post


Link to post
Share on other sites
You need vertex normals to do vertex lighting. If the sprites represent the ground, they should be quite easy for you to do - just point them in the up direction and out for slopes (you can calculate the normals for both polygons of a sprite given the 4 vertices and a couple of crossproducts.)

An extension of this which can also be used to make sprites look more 3D where supported in hardware is DOTPRODUCT3 texture lighting where you store normals for every pixel of the texture.

Probably easier and more "2D" in approach (ie. the way you might do it on native 2D hardware like GBA) is to draw alpha blended sprites (actually ONE:INVSRCALPHA or SRCALPHA:ONE might be better for lasers) which represents the light cast by the laser. This is the same idea as lightmaps in 3D.


--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites