#version 140 // created by Thorsten Thormaehlen for educational purpose in vec3 normalInterp; in vec3 vertPos; out vec4 outputColor; uniform int mode; uniform vec3 lightPos; const vec3 ambientColor = vec3(0.1, 0.0, 0.0); const vec3 diffuseColor = vec3(0.5, 0.0, 0.0); const vec3 specColor = vec3(1.0, 1.0, 1.0); void main() { vec3 normal = normalize(normalInterp); vec3 lightDir = normalize(lightPos - vertPos); float lambertian = max(dot(lightDir,normal), 0.0); float specular = 0.0; if(lambertian > 0.0) { vec3 viewDir = normalize(-vertPos); // this is blinn phong vec3 halfDir = normalize(lightDir + viewDir); float specAngle = max(dot(halfDir, normal), 0.0); specular = pow(specAngle, 16.0); // this is phong (for comparison) if(mode == 2) { vec3 reflectDir = reflect(-lightDir, normal); specAngle = max(dot(reflectDir, viewDir), 0.0); // note that the exponent is different here specular = pow(specAngle, 4.0); } } outputColor = vec4(ambientColor + lambertian * diffuseColor + specular * specColor, 1.0); }