prop :: properties {
	time : float @time;
	resolution : float2 @resolution;
}

vertex main :: (pos : float3 @position) -> float4 @position {
	return float4(pos, 1.0);
}

pixel main :: (pos : float4 @outposition) -> float4 @target {
	p := float2(2.0 * pos.x - prop.resolution.x, 2.0 * pos.y - prop.resolution.y) / prop.resolution.y;
	tau := 3.1415926535 * 2.0;
	a := atan(p.x, p.y);
	r := length(p) * 0.75;

	uv := float2(a / tau, r);

	x_col := (uv.x - (p.time / 3.0)) * 3.0;
	x_col = mod(x_col, 3.0);
	hor_colour := float3(0.25, 0.25, 0.25);
	
	if x_col < 1.0 {
		horColour.r += 1.0 - xCol;
		horColour.g += xCol;
	} else if x_col < 2.0 {
		xCol -= 1.0;
		horColour.g += 1.0 - xCol;
		horColour.b += xCol;
	} else {
		x_col -= 2.0;
		hor_colour.b += 1.0 - x_col;
		hor_colour.r += x_col;
	}

	uv = (2.0 * uv) - 1.0;
	beam_width = (0.7+0.5*cos(uv.x*10.0*tau*0.15*clamp(floor(5.0 + 10.0*cos(iTime)), 0.0, 10.0))) * abs(1.0 / (30.0 * uv.y));
	hor_beam = float3(beam_width);
	result := float4(((hor_beam) * hor_colour), 1.0);
}
