51 lines
983 B
GLSL
51 lines
983 B
GLSL
#version 330 core
|
|
|
|
in vec3 normal;
|
|
in vec3 fragmentPosition;
|
|
in vec2 textureCoordinate;
|
|
|
|
|
|
uniform vec4 ambientColor;
|
|
uniform vec4 diffusionColor;
|
|
uniform vec4 specularColor;
|
|
|
|
uniform float shininess;
|
|
|
|
uniform vec4 ambientLight;
|
|
uniform vec3 lightPosition;
|
|
uniform vec4 lightColor;
|
|
|
|
uniform sampler2D myTexture;
|
|
|
|
|
|
float emissionStrength = 0.0;
|
|
|
|
|
|
void main() {
|
|
vec4 color = texture(myTexture, textureCoordinate);
|
|
|
|
vec3 norm = normalize(normal);
|
|
vec3 lightDir = normalize(lightPosition - fragmentPosition);
|
|
vec3 eyeDir = -normalize(fragmentPosition);
|
|
|
|
float diff = max(dot(norm, lightDir), 0.0);
|
|
|
|
vec3 halfway = (lightDir + eyeDir) / length(lightDir + eyeDir);
|
|
float specular = pow(max(dot(halfway, norm), 0.0), shininess);
|
|
|
|
|
|
gl_FragColor =
|
|
// EMISSION
|
|
diffusionColor * emissionStrength +
|
|
|
|
// // AMBIENT
|
|
ambientLight * ambientColor +
|
|
|
|
// DIFFUSION
|
|
diff * lightColor * diffusionColor +
|
|
|
|
// SPECULAR
|
|
specular * lightColor * specularColor;
|
|
|
|
gl_FragColor = color;
|
|
} |