2d lighting

Started by
8 comments, last by moonshine 19 years, 8 months ago
I've been wondering if it's possible to make flat 2d planes react to light sources. Im using D3D 9.0b, and Im going to be using alpha channel transparency on my sprites, which rules out using the alpha channel as lighting info. Basicaly its going to be a 2d game, but I want sprites to react to light sources, preferably without using D3D's lights. The only thing I can think of is using an 8bit b/w image over each sprite and alphablend them, or multitexturing (not sure about older card support on that). does anyone have any idea how to do this? Bumpmapping could also be an option but I dont know how older cards deal with that.
Advertisement
In what way do you want them to "react to light"?
Imagine per-pixel lighting. When light hits it, the pixels on the side where the light source is lighten based on the distance/colour of the light.
Hmm. i had a similar idea recently, and i did a test program (with allegro though). I used gouraud shaded sprites and a little calculation to get the "light-strenth" for the four corners of each sprite. I could send you the source/exe if you want it, send me an email if you're intrested... (jonatanhedborg@hotmail.com)
Since your using D3D, use the same method used in 3D games. Multitexture the lightmap with the texture (MODULATE the two, alpha blending does not give you lighting). This will handle lighting the tiles on your map. To apply the lights to sprites that are above the tiles, do the same thing, but use the stencil buffer to mask away pixels that are not on the sprite.

You can do dot3 lighting and bump mapping as well, but it requires some extra work. Also, I've done this and it and it's significantly slower the regular lightmapping.
to have pixels react to the light, the pixels will need to know what direction their facing. Diablo 2 I think did somthing like this.
The only thing I can think of for that is a normal map, but I dont know if theyre supported on older cards etc
When you do per-pixel lighting on 2D Sprites, do you use DirectX functions or do you access the video memory/buffer manually and change each pixel at its address in memory?
"Learn as though you would never be able to master it,
hold it as though you would be in fear of losing it" - Confucius
Quote:Original post by moonshine
The only thing I can think of for that is a normal map, but I dont know if theyre supported on older cards etc


DOT3 is supported on a wide range of gpu. Most card sold in the last 4 years supports it as far as i know. Of course, you still have some problems with i815, older ati chipsets, and so on ;) You may have a look to the delphi3d hardware database to see wether your target gpu supports DOT3 or not (I'm not an OpenGL guru but I think this is the GL_xxx_texture_env_dot3 extensions, where xxx is ARB, EXT,...).

If you sprite are not too big, you can still try to emulate some kind of bump mapping on older adapters, using an embossing technique.

Yours,
Thanks, seems that it's supported all the way back to the first GeForce with nVidia which is good, and the Radeon 7000 series with ATi, which are the min specs I was aiming for. Thanks!

This topic is closed to new replies.

Advertisement