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

2D lighting

Started by Stru Nov 15, 2004 at 4:36 PM 4 replies 1.4k views
Original Post
Stru
Stru
I am doing 2D graphics in 3D and I would like to implement some form of lighting for doing effects like spotlights, muzzle flash, and flashlights. I have an idea about how to do it but im not sure how well it will work. I was thinking I draw the screen as normal and then after thats done I draw on top of that a solid black layer where I have subtracted alpha values for the lights. Is this a good way to do it? Are there any tutorials out there for doing something this? Thanks in Advance
matthughson
matthughson
What API is this being done in? If you're using DX or OGL, I would sugest using hardware lighting.

Matt Hughson
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Ilici
Ilici
That would be one way of doing it.

Other than that you could do vertex lighting and calculate your own lighting equation. Check out how OpenGL does the lighting (you can find the equation in the specs); it's fairly easy to implement it yourself.

If you want even better lighting you can do some sort of raycasting to find shadow areas (both umbra and penumbra). There's a tutorial in the Articles section written by OrangyTang about it.
matthughson
matthughson
Yeah, I guess I should mention also that vertex lighting doesn't look all that great in 2D games, unless you want to bump up the poly count in your sprite quads.

Matt Hughson
__________________________________[ Website ] [ Résumé ] [ [email=contact[at]matthughson[dot]com]Contact[/email] ][ Have I been Helpful? Hook me up! ]
Ademan555
Ademan555
the best way i can see for a spotlight is by blending a white triangle... it should "light" everything that its over (of course, if its pitch black before the triangle is applied, the triangle will just show a white-ish space)

the same thing can be done for muzzle flash, except id reccomend using a quad with a texture... a white texture with the strondest alpha values in the center and it falls off near the edges

hope that helps
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
Stru
Stru
Thanks for your replies. I am using DirectX with textured quads so per-vertex lighting would look hideous. I think I am going to try my original idea, and then if its not good enough I will look into raycasting.

Topic Locked

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

Sign in to reply to this topic.