Re: Missile Command Splosion Effect
Posted: Tue Dec 29, 2015 7:04 pm
An interesting solution to this problem, without using any shaders would be to use the wonderful stencils.
Note: You cannot pass variables to stencils and need to make all the values global for that file at least. (the following is untested psuedo code)
EDIT: Found and fixed a small logical error with the shader buffer clearing and added more explanations.
Note: You cannot pass variables to stencils and need to make all the values global for that file at least. (the following is untested psuedo code)
Code: Select all
local r, x, y = 100, 200, 200
local function circleStencil()
love.graphics.circle("fill", x, y, r, 50)
end
function love.draw()
r, x, y = -- Whatever the first explosion is
love.graphics.stencil(circleStencil, "increment", 1, false) -- This increments and clears the previous frame's the shader buffer (think of it as a depth buffer) in the circle's region by 1
r, x, y = -- Whatever the second explosion is
love.graphics.stencil(circleStencil, "increment", 1, true) -- The true ensures that the shader buffer is retained
-- Only allow rendering on pixels which have a stencil value less than or equal to 1 (not in intersection).
love.graphics.setStencilTest("lequal", 1)
-- Draw all explosions with the yellow color
-- Only allow rendering on pixels which have a stencil value greater than 1 (in intersection).
love.graphics.setStencilTest("greater", 1)
-- Draw all explosions with the green color
end