2D Lighting

ChrisS
Unregistered
 
Post: #1
Hey all,

I'm currently working on a top down game which is a pretty basic RPG. Everything is pretty well on track but I have on effect I'm trying to get a handle on. I'd like for the torches or whatever light source (point) being used to give off a light which is brighter at the center and fades until it's black at a certain radius. However, I'm unsure exactly how to go about this. I've thought about using masks or a combination of Bresenham's line and circle algorithm but I'm thinking there's a better way to go about it. Any ideas? Oh, the game is all in SDL. Thanks in advance!

Chris
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
additive blending of a bitmap image?
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #3
Will the areas not lit by the torch me darkened out or would it just brighten the area by the torch?

A very easy method you can use is a circle bitmap with a fading alpha map as you go towards the center. So mask gets darker the further it is away from the source (your torch)

This is what OSC was talking about but i felt like clearing it up incase you arent too knowledgable about the lingo.

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
I have some code laying around to do that along with shadow casting. I posted a thead up about it a while back, but I don't remember what it was called. I'll see if I can find it, it was pretty sweet.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #5
I had a simpler example made in SDL, but this will have to do. LightingExample

You have to run it from the command line by launching RubyGameCommon. The code for it is mostly in Ruby/main.rb.

The basic idea is that you take any line segment that would cast a shadow and use it to stencil a quad with the opposite edge projected away from the light source. Once you've cast all the shadows, blend the lightmap onto the background using the stencil as a mask.

You could use the same shadow effect for for visibility too.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #6
Might just be me, but I get this nice message when I try to run it:
Code:
Nicholas-Gravelyns-Computer:~ NicholasGravelyn$ /Users/NicholasGravelyn/Desktop/LightExample/RubyGameCommon; exit
dyld: /Users/NicholasGravelyn/Desktop/LightExample/RubyGameCommon can't open library: @executable_path/../Frameworks/OpenAL.framework/Versions/A/OpenAL  (No such file or directory, errno = 2)
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #7
Oops. My fault. Forgot to reinstall OpenAL after I reformatted the hard drive. Cool demo.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #8
Works fine for me, I like it too looks pretty cool.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
KiroNeem
Unregistered
 
Post: #9
If anyone has used the gamedev.net article for 2d lighting
http://www.gamedev.net/reference/article...le2032.asp
There is a typo that had me running in circles last night, the way to calculate the normals or edges is listed as

nx = currentPoint.y - prevPoint.y;
ny = currentPoint.x - prevPoint.x;

Where it should be

nx = currentPoint.y - prevPoint.y;
ny = prevPoint.x - currentPoint.x;

I just decied to post this just in case anyone was having a similar problems when reading this article, and I know that this one gets passed around a bunch. I also sent an e-mail to the writer so hopefully he will fix that.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #10
Is this maybe due to the y-axis coordinate inversion that mac os x (annoyingly) uses?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
KiroNeem
Unregistered
 
Post: #11
Nope, this is just pure math
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #12
unknown Wrote:Is this maybe due to the y-axis coordinate inversion that mac os x (annoyingly) uses?

??? Since when?

Anyway, if you use fuzzy shadows, tell me how it goes. I wasn't convinced that it was an interesting enough effect given the headaches and limitations over hard shadows.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #13
Since Mac OS X 10.0, the use the standard mathematical coorinate system. Origin at bottom, left.
Which is completly insane and has caused me so much hassle, im sure sure many millions of other people.
Computers start at the top left, why do they want to change it!?!

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #14
Wow, I'd actually completely forgotten about that. Wacko
Guess I need to do more Cocoa programming again.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #15
Id remain avoiding it.. Rasp

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Post Reply