
Dynamic lightning in 2D
I was playing C&C: Tiberian Sun the other day, and I keep asking myself: how the hell do they do dynamic lightning so fast without even using a 3D accel.?! Do they pre-render the tiles at runtime? Its seems to be to smooth and to dynamic for that. Any ideas would be appriciated. God i hate playing good games..makes me feel like a complete moron
Cheers!

I''ve seen books on this kind of thing. The equations are pretty big so you probubly should just look at some 3D rendering books under "lighting" to see if they give examples.
E:cb woof!
E:cb woof!
E:cb woof!
Yeah, doing the equations are one thing (i can pull that off pretty easy
), but what I was wondering was how they do it so fast?

computers are fast. They probably still use the same equations. Maybe they calculate the color of the wall when they map the wall''s picture onto it. Thatway you''re only calculating the distance once. If you want quick and dirty, just draw the pixel darker the further away it is, ignoring the angle of the wall to you.
E:cb woof!
E:cb woof!
E:cb woof!
But I still have the problem with pixel-per-pixel plotting speeds *sigh*. Anyways, I figure that out somehow. Thanks for helping out.
If you want to do really fast pixel plotting with dynamic lights then you have to use assembler to optimize your code. The lighting itself is probably not calculated at runtime instead it''s probably done with lookup tables (kind of like lightmaps).
store all the surfaces which will be lit and a canvas buffer in system memory. this is the best way to do pixel plotting in 2d. also, organize your data to be mmx friendly and use mmx routines to calculate and plot the pixels in groups of 4. at the end of lighting copy this canvas to a video memory back buffer. then add to the back buffer any overlays from video memory surfaces which do not need lighting. if you werent doing any of these already, your frame rate should jump about 10x.
a faster way would be to store precalculated tiles if you have the memory. but this is the fastest i can think of for dynamic lighting in 2d.
a faster way would be to store precalculated tiles if you have the memory. but this is the fastest i can think of for dynamic lighting in 2d.
Carl "trixter"[email=carl@trixoft.com]carl@trixoft.com[/email]http://www.trixoft.com
You may also use dark images / tiles to draw. Then you build an alpha adictive blending routine (asm for speed).
Merge the alpha points that are near (for example, the troops that are near each other) and the points not too near doing a rectangular intersection, so you do not need to do a blending for every unit.
Then you do some circle gradients on the alpha channel (starting from black to white so it gives impression of lights near and shades far) and blit with the addictive alpha to the surface.
That''s the fastest way i know, but if you are talking about of terrain shading, you could store the terrain shades for the tiles on another surface, then blit tile-by-tile, so it''s slower. You can use a color lookup table to speed things up on this case.
Merge the alpha points that are near (for example, the troops that are near each other) and the points not too near doing a rectangular intersection, so you do not need to do a blending for every unit.
Then you do some circle gradients on the alpha channel (starting from black to white so it gives impression of lights near and shades far) and blit with the addictive alpha to the surface.
That''s the fastest way i know, but if you are talking about of terrain shading, you could store the terrain shades for the tiles on another surface, then blit tile-by-tile, so it''s slower. You can use a color lookup table to speed things up on this case.
-Chronno-
Im already using assembly (addative) routines (with MMX) but im still not quite satisfied with the speed - with all the surfaces in system memory. I'll try out some of the things you suggested - we'll see if it gets any better. Thanks a bunch!
Edited by - Staffan on 2/8/00 3:08:23 PM
Edited by - Staffan on 2/8/00 3:08:23 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement