I have written a shader which lets objects fade to black (progress < 1) and then back to their original color (progress > 1):
Code: Select all
vec4 col;
extern number progress;
number bright;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
col = texture2D(texture, texture_coords);
if (progress < 1.0)
{
bright=1.0-progress;
}
else
{
bright=1.0-(2.0-progress);
}
return vec4(col.r*bright, col.g*bright, col.b*bright, col.a);
}
What I tried:
After love.graphics.setPixelEffect, I draw a rectangle in the background color, filling the whole screen, before I draw anything else. However, using the shader above, this rectangle disappears when the shader is active. If I change the line
return vec4(col.r*bright, col.g*bright, col.b*bright, col.a);
to
return vec4(col.r*bright, col.g*bright, col.b*bright, 1);
then it does not disappear, but then the rectangle is being drawn black during the entire transition.
What am I doing wrong?
Also, I know it can be done using a canvas, but I want to avoid that for compatibility reasons.