#version 330 core
precision highp float;

// Fullscreen white noise (TV static) whose intensity PULSATES on a timer. The demopart composites it
// with additive blending (blend mode set in the JSON), so the static BRIGHTENS the image rather than
// darkening it. The demopart supplies the peak intensity via `alpha` (keyframed); the throb is a sine
// of iTime, so it is deterministic per frame and identical under --record.

uniform float iTime;
uniform float alpha;

in vec2 fragCoord; // pixel coordinates
out vec4 fragColor;

float hash(vec2 p) {
	return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
}

void main() {
	float frame = floor(iTime * 60.0); // integer frame index -> new static each frame, record-safe
	float n = hash(fragCoord + vec2(frame, frame * 1.7));

	// ~2 Hz throb (close to the 127 BPM feel), oscillating the opacity in [0.2, 1.0] of `alpha`.
	float pulse = 0.6 + 0.4 * sin(iTime * 12.56637061);

	fragColor = vec4(vec3(n), alpha * pulse);
}
