Lighting system

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Chief
Party member
Posts: 101
Joined: Fri Mar 12, 2010 7:57 am
Location: Norway, 67° north

Lighting system

Post by Chief »

Oy! I'm trying to make a little lighting system for my project here... but i cant figure out a nice way to do it. What i want is to first draw the map, then have the "darkness" draw on top of the map. Each light is basically a open hole in the darkness. I do this to allow multiple light sources, which i need. Here's an example:

Image

Image


Here's the draw code for the example:

Code: Select all

local x, y = GetIsometricMouse()
love.graphics.setColor( 255, 255, 255, 255 )
love.graphics.draw( grad, x, y, 0, 1, 1, 128, 128 )
-- grad is an image of a round gradient, with white pixles in the middle.
			
love.graphics.setColor( 255, 255, 255, 255 )
love.graphics.draw( grad, 512, 256, 0, 1, 1, 128, 128 )
				
love.graphics.setBlendMode( "multiplicative" )	
	love.graphics.setColor( 255, 255, 255, 255 )
	love.graphics.draw( rock, 0, 0, 0, 1, 1, 0, 0 )
        -- rock is an image of some rocky texture. >>>( THE "MAP")<<<
love.graphics.setBlendMode( "alpha" )
The reason why i can't use this, is because it's the map itself that is turning dark, and not a layer over it.

So my question is: How can i make a layer over the map that turns dark where there's no "light".
Last edited by Chief on Sun Feb 13, 2011 9:07 pm, edited 2 times in total.
User avatar
Taehl
Dreaming in associative arrays
Posts: 1025
Joined: Mon Jan 11, 2010 5:07 am
Location: CA, USA
Contact:

Re: Lighting system

Post by Taehl »

I think your best bet would be to draw everything normally with no lighting, then render a framebuffer where faded white spots were placed at light sources, then draw the framebuffer over top of everything with a multiplicative blend.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
User avatar
Chief
Party member
Posts: 101
Joined: Fri Mar 12, 2010 7:57 am
Location: Norway, 67° north

Re: Lighting system

Post by Chief »

Yes, perfect! That was just what I needed. :ultrahappy: Never understood the true awesomeness of framebuffers!

Case closed.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest