#version 330 core

// Post-fx node: feedback echo / motion-persistence whose zoom punches outward on every beat.
// iChannel0 = the composited demo frame, iChannel1 = the previous presented frame ("feedback").
// uBeatPulse / uKick are beat-reactive built-ins supplied by PostProcessGraph from the shared BeatClock.
in vec2 ex_Uv;
out vec4 fragColor;

uniform sampler2D iChannel0; // demo (current)
uniform sampler2D iChannel1; // feedback (previous presented frame)

uniform float uBeatPulse; // 1.0 at a beat onset -> ~0 before the next beat
uniform float uKick;      // smoothed low-band energy [0,1]

uniform float decay;      // feedback retention per frame (0..1)
uniform float zoomBase;   // constant feedback zoom toward centre
uniform float zoomBeat;   // extra zoom added on each beat

void main() {
	// Feedback sampled slightly zoomed toward the centre; the zoom kicks outward on the beat.
	float z = zoomBase + zoomBeat * uBeatPulse;
	vec2 uvz = (ex_Uv - 0.5) * (1.0 - z) + 0.5;

	vec3 cur = texture(iChannel0, ex_Uv).rgb;
	vec3 prev = texture(iChannel1, uvz).rgb * decay;
	prev *= (1.0 + 0.3 * uKick); // kick lifts the trail brightness a touch

	fragColor = vec4(max(cur, prev), 1.0); // max = bright additive-looking trails
}
