#version 330 core

uniform mat4 viewMatrix = mat4(1);
uniform mat4 projectionMatrix = mat4(1);

layout(location=0)in vec2 vertex;
layout(location=1)in vec4 texCoord;
layout(location=2)in vec4 texCoord2;
layout(location=3)in vec4 color;
layout(location=4)in vec2 scale;
layout(location=5)in float angle;
layout(location=6)in float blend;

out struct
{
	vec2 scale;
	vec4 texCoord;
	vec4 texCoord2;
	vec4 color;
	float angle;
	float blend;
}gInfo;

vec4 hsv2rgb(vec4);

void main()
{
	gInfo.texCoord = texCoord;
	gInfo.texCoord2 = texCoord2;
	gInfo.scale = scale;
	gInfo.angle = angle;
	gInfo.blend = blend;
	gInfo.color = hsv2rgb(color);
	gl_Position = projectionMatrix*viewMatrix*vec4(vertex.xy, 0, 1);
}

vec4 hsv2rgb(vec4 hsv)
{
	hsv.x = mod(hsv.x, 360.0);
	float vmin = hsv.z*(1.0-hsv.y);
	float a = (hsv.z-vmin)*mod(hsv.x, 60.0)/60.0;
	float vinc = vmin+a;
	float vdec = hsv.z-a;

	switch(int(hsv.x/60.0))
	{
	case 0:  return vec4(hsv.z, vinc, vmin, hsv.a);
	case 1:  return vec4(vdec, hsv.z, vmin, hsv.a);
	case 2:  return vec4(vmin, hsv.z, vinc, hsv.a);
	case 3:  return vec4(vmin, vdec, hsv.z, hsv.a);
	case 4:  return vec4(vinc, vmin, hsv.z, hsv.a);
	default: return vec4(hsv.z, vmin, vdec, hsv.a);
	}
}