How to create a delay shader in Godot using a back-buffer?

Godot Version

4.4.1

Question

Hi everyone! I’m trying replicate this shader but I’m having a lot of difficult to adapt it’s back-buffer logic in Godot.

I tried consulting the tutorials on screen-reading shaders and SubViewports, but had no success.

How can I create a shader that stores it previous frame in a (back) buffer, reads it and mix with the current frame?

The shader I wrote so far is this one:

void fragment() {
    vec4 backbuffer = texture(iChannel0, SCREEN_UV);

    vec2 offset = vec2(sin(TIME), 0.5);
    float radius = 0.4;
	float dist = length(offset - UV) + radius;
	float dist_inv = 1.0 - dist;
    float dist_inv_rounded = round(dist_inv);
	float dist_inv_rounded_clamped = clamp(dist_inv_rounded, 0.0, 1.0);
    vec4 circle = vec4(dist_inv_rounded_clamped);

    COLOR = mix(circle, backbuffer, 0.9);
	// COLOR = circle;
}

I achieved the effect using two SubViewports, but I wonder if this is optimal:

Also, when I apply transparency to both SubViewports I get this ugly dark trail: