I'm trying to do an effect sort of like the explosions in the old Atari game Missile Command, but not quite the same. This is where two explosions cancel each other out where they intersect. Essentially what I'm trying to do is XOR two circles. I thought that using a shader might be the best way to go about this. Also, it gave me an excuse to learn about shaders. This is what I came up with (full .love file is also included)
Shader
Code: Select all
extern Image explosionCanvas;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );
screen_coords.x = screen_coords.x / love_ScreenSize.x;
screen_coords.y = screen_coords.y / love_ScreenSize.y;
vec4 canvasPixel = Texel(explosionCanvas, screen_coords);
if (canvasPixel.r != 0) {
pixel.r = 0;
} else {
pixel.r = 1.0;
}
return pixel;
}
Code: Select all
love.graphics.setColor(255,255,0)
love.graphics.setCanvas(explosionCanvas)
love.graphics.clear()
love.graphics.setBlendMode("replace")
love.graphics.setShader(explosionShader)
for _,e in pairs(explosions) do
explosionShader:send("explosionCanvas",explosionCanvas)
love.graphics.circle("fill", e.x, e.y, e.rad, 32)
end
love.graphics.setCanvas()
love.graphics.setShader()
love.graphics.setBlendMode("alpha")
love.graphics.draw(explosionCanvas)
The green areas should be solid, but instead they come out garbled and super flickery. I have no idea whats going on. Obviously I am doing something horribly wrong.