#version 330
out vec4 fragColor;

uniform mat4 proj, model, view;

uniform int hasTexture;
uniform vec4 couleur;
uniform vec3 directional;
uniform samplerCube skybox;

in vec4 vsoModPos;
in vec3 vsoNormal;
in vec3 viewVector;

const float reflectMod = 0.2;

vec2 rotate(in vec2 vector, float angle){
	return vec2(vector.x * cos(angle) - vector.y * sin(angle),
				vector.x * sin(angle) - vector.y * cos(angle));
}

void main() {
	// Phong
	vec3 n = normalize(vsoNormal);
	//vec3 Ld = normalize(vsoModPos.xyz - Lp.xyz);
	vec3 Ld = normalize(directional);
	float intensite_diffus = clamp(dot(n, -Ld),0.0,1.0);
	// Specular
	vec3 R0 = reflect(Ld, n);
	float intensSpecular = pow(clamp(dot(-normalize(viewVector), R0),0.0,1.0),100.0);
	vec4 specular = intensSpecular * vec4(1.0);

	// Réflection
	vec3 viewR = reflect(viewVector, n);
	
	fragColor = intensite_diffus * couleur +
		(texture(skybox, viewR) + specular);
}
