float hueHelper(float m1, float m2, float h)
{
	h = compare(h, h + 1.0, compare(1.0 - h, h - 1.0, h));
	return compare(h * 6.0 - 1.0, m1 + (m2 - m1) * h * 6.0, compare(h * 2.0 - 1.0, m2, compare(h * 3.0 - 2.0, m1 + (m2 - m1) * (2.0 / 3.0 - h) * 6.0, m1)));
}

vec4 HSLToRGB(vec4 hsl)
{
	vec4 result = hsl;
	float h = hsl.x, s = hsl.y, l = hsl.z;
	float m2 = compare(l - 0.5, l * (s + 1.0), l + s - l * s);
	float m1 = 2.0 * l - m2;
	result.r = hueHelper(m1, m2, h + 1.0 / 3.0);
	result.g = hueHelper(m1, m2, h);
	result.b = hueHelper(m1, m2, h - 1.0 / 3.0);
	return result;
}

kernel vec4 redImage(float value, float size)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(value, coord.y, coord.x, 1.0);
}

kernel vec4 greenImage(float value, float size)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(coord.y, value, coord.x, 1.0);
}

kernel vec4 blueImage(float value, float size)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(coord.x, coord.y, value, 1.0);
}

kernel vec4 hueImage(float value, float size)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(value, coord.x, coord.y, 1.0));
}

kernel vec4 saturationImage(float value, float size)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(coord.x, value, coord.y, 1.0));
}

kernel vec4 lightnessImage(float value, float size)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(coord.x, coord.y, value, 1.0));
}

kernel vec4 redSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(coord.y, y, x, 1.0);
}

kernel vec4 greenSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(y, coord.y, x, 1.0);
}

kernel vec4 blueSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(x, y, coord.y, 1.0);
}

kernel vec4 hueSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(coord.y, 1.0, 0.5, 1.0));
}

kernel vec4 saturationSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(x, coord.y, y, 1.0));
}

kernel vec4 lightnessSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(x, y, coord.y, 1.0));
}

kernel vec4 redHSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(coord.x, y, x, 1.0);
}

kernel vec4 greenHSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(y, coord.x, x, 1.0);
}

kernel vec4 blueHSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return vec4(x, y, coord.x, 1.0);
}

kernel vec4 hueHSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(coord.x, 1.0, 0.5, 1.0));
}

kernel vec4 saturationHSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(x, coord.x, y, 1.0));
}

kernel vec4 lightnessHSliderImage(float size, float x, float y)
{
	float scale = 1.0 / size;
	vec2 coord = destCoord() * scale;
	return HSLToRGB(vec4(x, y, coord.x, 1.0));
}

