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