#version 330 core

uniform mat4 mWorld;
uniform mat4 mView;
uniform mat4 mProjection;
uniform vec3 vEye;

in float zPos;
in vec3 norm;

out vec4 frag_colour;

vec3 hsv_to_rgb(float h, float s, float v)
{
	float c = v * s;
	h = mod((h * 6.0), 6.0);
	float x = c * (1.0 - abs(mod(h, 2.0) - 1.0));
	vec3 color;

	if (0.0 <= h && h < 1.0) {
		color = vec3(c, x, 0.0);
	} else if (1.0 <= h && h < 2.0) {
		color = vec3(x, c, 0.0);
	} else if (2.0 <= h && h < 3.0) {
		color = vec3(0.0, c, x);
	} else if (3.0 <= h && h < 4.0) {
		color = vec3(0.0, x, c);
	} else if (4.0 <= h && h < 5.0) {
		color = vec3(x, 0.0, c);
	} else if (5.0 <= h && h < 6.0) {
		color = vec3(c, 0.0, x);
	} else {
		color = vec3(0.0, 0.0, 0.0);
	}

	color.rgb += v - c;

	return color;
}

void main () {
    vec3 materialColor = hsv_to_rgb(zPos, 1, 1);
	float diffuse = clamp(dot(norm, -normalize(vec3(1,1,1))), 0.0, 0.6);
	vec3 color = materialColor*diffuse;

	frag_colour = vec4(color, 1.0);
}