Page 1 of 1

Lighting system

Posted: Sat Feb 12, 2011 10:53 pm
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".

Re: Lighting system

Posted: Sat Feb 12, 2011 11:33 pm
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.

Re: Lighting system

Posted: Sun Feb 13, 2011 6:47 pm
by Chief
Yes, perfect! That was just what I needed. :ultrahappy: Never understood the true awesomeness of framebuffers!

Case closed.