uniform mat4 mvp;

in vec4 Position;
in vec4 Color;
in vec2 TexCoord;

uniform highp vec2 pixelsPerCell;
uniform highp vec2 offset;
out lowp float velocity;
out lowp vec2 tc;
out lowp float selected;
out lowp float alpha;
out lowp float aspectRatio;

out lowp float chance;

void main() {
	vec2 pos = Position.xy;
	velocity = Position.w;
	pos *= pixelsPerCell;
	pos -= offset;

	pos.x += 2.f;
	pos.y += 2.f;
	pos.x = floor(pos.x / 2.f) * 2.f;
	// pos.y = floor(pos.y/2.f) * 2.f;

	tc = TexCoord.xy;
	pos -= tc * 2.0;
	alpha = 1.f - Color.a * 0.5;

	selected = Color.z;
	chance	 = Color.x;

	float thickness = 2.f + selected * 4.f;

	// Position.z is width, height = 1
	vec2 actualDims = vec2(Position.z, 1.0) * pixelsPerCell;
	aspectRatio		= actualDims.x / actualDims.y;
	vec2 inset		= vec2(thickness) / actualDims;
	vec2 amt		= tc * 2.0 - vec2(1.0);
	tc += inset * amt;

	gl_Position = mvp * vec4(pos, 0.f, 1.f);
}