realtime lighting for 2D topdown game?

Started by
6 comments, last by fakemind 22 years, 4 months ago
The only way I can think of that would do good and quick real time lighting for my 2D game is bump mapping. Wouldnt it be quite simple to precalculate the bump maps for the tiles and sprites? While I think this would work, Im not sure that it would be exactly what I want. I want an explosion next to a robot to cast a shadow behind the robot .. for example. Since its only 2D and a top-down view, Im assuming it would be simplier than if the scene was 3D. Does anybody have any ideas or suggestions? - jeremiah http://fakemind.com
- jeremiah http://fakemind.com
Advertisement
You could stretch out an image behind the robots sprite to simulate a shadow being cast. You would need a shadow-image of the robot to do this though.

-----------------------
0wn 0wn 0wn your goat
gently down the pw33n
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack
Or, you could just use the sprite itself. You could use the outline of the actual sprite, you''d just have to stretch/squash it to make it look like the shadow is being cast in the right direction along the right plane. If your sprite has a colorkey then just go through and make black any pixel that''s not the colorkey, now you have a sillhouette that you can use. Either save this sillhouette for every frame of the sprite, and use later, or make the sillhouette on the fly for the current frame if you can spare the resources.

------------
- outRider -
unfortunatly bumpmapping wont help you too much since its meant just for adding bumpiness to surfaces and not for lighting effects as you suggest. now you can use the method mentioned by the previous posters of using a shadow map sprite. in fact it may be cooler to go one step further and if the game has a non relaistic look, you could use the trick of a gradient fade away from the robot which gets less opaque as you get farther from the robot. this method can further be enhanced by making the gradient you use be affected by the height of the robot. for instance if the center is higher then the sides, the center of the shadow gradient will go farther out then the sides.
thanx for the replies.

yeah, i wasnt too sure about the bump mapping approach. i liked the ideas, but im not sure they are exactly what im looking for. while they would be good if there is nothing in the shadows way im not sure they would work if, say, another robot was in the path of the shadow. in this case the shadow would need to be cast on top of the robot to be realistic.

perhaps we could take bump mapping one step farther. lets say we have a light source with two variables, its brightness and its height. if we are given a pixel to figure out the brightness of we would only need to know its distance from the light, whether or not there is line of sight from the pixel to the light, and its angle toward the light. the distance from the light is simple, like finding the length of the hypotenuse when you have adjacent and opposite legs of a right triangle. the angle towards the light is easy too and if im not mistaken bump mapping uses something simple to accomplish this. the only thing which would be non-trivial is line-of-sight.

to fix the line-of-sight problem we might be able to simply test and see if there are any objects (robots and missles in my case, given the world is flat) in between; if there are, then we would need to do some calculations to see if the object(s) would block the light or not.

does this sould feasible? any ideas?

the following was added because i got some more ideas
what if, for the line-of-sight problem, instead of having each pixel calculate it, we would have the light source calculate it for us. given the lights position, we could see if there were any objects within the lights radius; if not, then all pixels within the lights range would need to be lighted; if yes, then perhaps we could find out which pixels are behind the object.

also, to handle the objects case, perhaps we could have a height-map for our flat 2D world, and the objects would be added to the heightmap whereever they stand. this way, objects dont bother us at all, we would just need to figure out a way to take the heightmap into play when lighting.

*big sigh* i dunno, just some ideas.

- jeremiah
http://fakemind.com

Edited by - fakemind on December 16, 2001 12:26:30 AM
- jeremiah http://fakemind.com
the only problem with per pixel solutions is speed issues. bumpmapping is pretty intense as is, adding the line of site stuff will only increase that. it may be acceptable if you break the world into grids and use interpolation on the pixel level. though as you start adding all this 3d info about yur structures, you may just want to use volume shadowing techniques with the 3d card (keep your tilemap exactly the same) with only the sprites as 3d objects and the floor is a plane.

bumpmapping may be decent approach, your best bet is to actually implement the ideas you have now, and see which works out best.
just a quick thought before i goto bed.

could i use anything similar to voxels, as i know (if im not mistaken) its like a world made up of a hieghtmap.

- jeremiah
http://fakemind.com
- jeremiah http://fakemind.com
quote:Original post by outRider
Or, you could just use the sprite itself.


He mentioned that is a topdown game, so I gather that the sprites are images of the top of everything. Given that, a stretched top image wont look right for a shadow, although am image from the front/side of something will look a lot better stretched out on the ground.

-----------------------
0wn 0wn 0wn your goat
gently down the pw33n
-----------------------"When I have a problem on an Nvidia, I assume that it is my fault. With anyone else's drivers, I assume it is their fault" - John Carmack

This topic is closed to new replies.

Advertisement