So I'm trying to implement a lighting system in my game. For colorless light, it works just fine, like this:
-Draw the game as normal.
-Set canvas to lighting canvas, clear it to black with 255 alpha.
-set blendmode to subtractive, and draw shapes from lighting sources.
-setCanvas() and draw lighting canvas.
To make the light colored, I tried adding the color using additive blendmode before the subtraction, but the problem is that the alpha goes to zero when two lights intersect, so the color falls out. I then tried adding some alpha to the entire canvas after all the lights are drawn, but this doesn't seem to work.
Any suggestions? I'd really like to avoid any per-pixel logic since this will probably make the whole system too slow.
Example of working white light:
Code: Select all
function love.load()
love.graphics.setBackgroundColor(255, 0, 255)
canvas = love.graphics.newCanvas(400,300)
love.graphics.setLineWidth(5)
end
function love.draw()
canvas:clear(0,0,0,255)
--lighting canvas
love.graphics.setCanvas(canvas)
love.graphics.setBlendMode("subtractive")
love.graphics.setColor(0, 0, 0,150)
love.graphics.rectangle("fill", 75, 75, 125, 125)
love.graphics.setColor(0, 0, 0,200)
love.graphics.rectangle("fill", 110, 110, 125, 125)
--outside lighting canvas
love.graphics.setCanvas()
love.graphics.setBlendMode("alpha")
love.graphics.setColor(0, 255, 0,255)
love.graphics.line(0,0,500,500)
love.graphics.draw(canvas)
end