I'm new to GLSL, so I suspect I've done something silly here. I have a very basic shader.
Code: Select all
vec4 effect(vec4 color, sampler2D texture, vec2 texture_coords, vec2 screen_coords) {
int blur_size = 16;
float x_pixel_size = 1.0 / 800.0;
float y_pixel_size = 1.0 / 600.0;
vec4 sum;
for (int i = -blur_size; i < blur_size; i++) {
for (int k = -blur_size; k < blur_size; k++) {
vec2 offset_pos = texture_coords + vec2(i * x_pixel_size, k * y_pixel_size);
sum += texture2D(texture, offset_pos);
}
}
return sum;
}
I draw to a canvas then render the canvas using the shader.
Code: Select all
love.graphics.setCanvas(canvas)
love.graphics.clear()
local objects = collision_sim.objects
for i = 1, #objects do
local object = objects[i]
if object.is_colliding then
love.graphics.setColor(220, 120, 120)
else
love.graphics.setColor(255, 255, 255)
end
love.graphics.rectangle(
"fill",
object.x,
object.y,
object.width,
object.height
)
end
love.graphics.setCanvas()
love.graphics.setColor(255, 255, 255)
love.graphics.setShader(cool_effect)
love.graphics.draw(canvas)