#version 150 in vec3 vertPosition; in vec2 vertTexCoord; in vec3 vertNormal; in vec4 vertColor; uniform vec3 light0Position; uniform vec3 light1Position; uniform vec3 light0Color; uniform vec3 light1Color; uniform vec3 ambientColor; uniform float specularity; uniform float shininess; uniform float emissiveness; uniform vec3 cameraPosition; uniform sampler2D colorTexture; out vec4 fragColor; vec3 applyLight(vec3 lightPosition, vec3 lightColor, vec3 ambientColor, vec3 surfaceColor, vec3 normal, vec3 surfacePosition, vec3 surfaceToCamera) { vec3 surfaceToLight = normalize(lightPosition - surfacePosition); float diffuseStrength = max(dot(normal, surfaceToLight), 0.0); vec3 diffuseColor = diffuseStrength * lightColor; float specularStrength = pow(max(0.0, dot(surfaceToCamera, reflect(-surfaceToLight, normal))), shininess); vec3 specularColor = specularity * specularStrength * lightColor; return (ambientColor + diffuseColor + specularColor) * surfaceColor; } void main() { vec4 textureColor = texture(colorTexture, vertTexCoord) * vertColor; vec3 surfaceToCamera = normalize(cameraPosition - vertPosition); vec3 normal = normalize(vertNormal); vec3 litColor = applyLight(light0Position, light0Color, ambientColor, textureColor.rgb, normal, vertPosition, surfaceToCamera); litColor += applyLight(light1Position, light1Color, ambientColor, textureColor.rgb, normal, vertPosition, surfaceToCamera); fragColor = vec4(emissiveness * vec3(textureColor) + (1.0 - emissiveness) * litColor, textureColor.a); }