shader_type spatial;
render_mode unshaded;

uniform vec4 fill_color: source_color = vec4(1.0, 1.0, 1.0, 1.0);
uniform vec4 bg_color: source_color = vec4(0.0, 0.0, 0.0, 0.0);
uniform vec4 outline_color: source_color = vec4(0.0, 0.0, 0.0, 1.0);

uniform float scale = 2.0;
uniform float rotation = 0.0;
uniform float outline_width = 0.03;


void vertex() {
	float sine = sin(rotation);
	float cosine = cos(rotation);
	// Billboarding
	MODELVIEW_MATRIX = VIEW_MATRIX * mat4(INV_VIEW_MATRIX[0], INV_VIEW_MATRIX[1], INV_VIEW_MATRIX[2], MODEL_MATRIX[3]);
	// Scale
	MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(MODEL_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(MODEL_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(MODEL_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));
	// Rotation
	MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(cosine, -sine, 0.0, 0.0), vec4(sine, cosine, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));

	MODELVIEW_NORMAL_MATRIX = mat3(MODELVIEW_MATRIX);
}

void fragment() {
	vec2 pt = abs(scale * (UV - 0.5));
	float curve = sqrt(pt.x) + sqrt(pt.y);
	vec4 color = bg_color;
	if (curve < 1.0 + outline_width) {
		color = outline_color;
		if (curve < 1.0) {
			color = fill_color;
		}
	}
	ALBEDO.rgb = color.rgb;
	ALPHA = color.a;
}