47 lines
1.1 KiB
GLSL
47 lines
1.1 KiB
GLSL
#version 330 core
|
|
|
|
// material
|
|
uniform vec3 materialAmbient;
|
|
uniform vec3 materialKd;
|
|
uniform vec3 materialKs;
|
|
uniform float materialNs;
|
|
|
|
uniform vec3 dirLight[2];
|
|
uniform int nbPointLights;
|
|
uniform vec3 pointLights[8];
|
|
|
|
// fragment
|
|
in vec3 varNormal;
|
|
in vec2 varTexCoord;
|
|
|
|
in vec3 lightDirInView[5];
|
|
in vec3 halfVecInView[5];
|
|
|
|
// resultat
|
|
layout(location = 0)out vec4 outColor;
|
|
|
|
// --------------------
|
|
|
|
vec3 computeLight(in vec3 kd, in vec3 ks, in float ns, in vec3 color, in vec3 normal, in vec3 lightDir, in vec3 halfVec){
|
|
float diffuse = 0;
|
|
float specular = 0;
|
|
|
|
diffuse = dot(normal, lightDir);
|
|
diffuse = diffuse < 0 ? 0 : diffuse;
|
|
specular = dot(halfVec, normal);
|
|
specular = specular < 0 ? 0 : specular;
|
|
|
|
return color*diffuse*(kd+ks*pow(specular, ns));
|
|
}
|
|
|
|
void main(void) {
|
|
int i;
|
|
vec3 kd = materialKd;
|
|
vec3 light = 0.1*kd + computeLight(kd, materialKs, materialNs, dirLight[1], varNormal, lightDirInView[0], halfVecInView[0]);
|
|
for(i=1; i<nbPointLights+1; ++i)
|
|
light += computeLight(kd, materialKs, materialNs, pointLights[i*2 -1], varNormal, lightDirInView[i], halfVecInView[i]);
|
|
|
|
outColor = vec4(materialAmbient + light, 1);
|
|
}
|
|
|