38 lines
741 B
GLSL
38 lines
741 B
GLSL
#version 330
|
|
|
|
// material
|
|
uniform vec3 materialKd;
|
|
uniform vec3 materialKs;
|
|
uniform float materialNs;
|
|
|
|
// texture
|
|
uniform sampler2D baseTexture;
|
|
|
|
// fragment
|
|
in vec3 varNormal;
|
|
in vec2 varTexCoord;
|
|
|
|
// 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) {
|
|
vec3 kd = vec3(texture2D(baseTexture, varTexCoord));
|
|
|
|
outColor = vec4(kd, 1);
|
|
}
|
|
|