#version 330 struct Material { vec3 ambient; vec3 diffuse; vec3 specular; float shininess; bool hasTexture; }; in vec3 normal; in vec3 fragPos; in vec2 texCoord; uniform vec3 lightPos; uniform vec3 viewPos; uniform vec4 lightColor; uniform Material material; uniform sampler2D tex; out vec4 FragColor; void main() { vec3 lightDir = normalize(fragPos - lightPos); vec3 diffuse = max(0, dot(-normal, lightDir)) * material.diffuse; vec3 viewDir = normalize(fragPos - viewPos); vec3 reflectDir = reflect(-lightDir, normal); vec3 specular = pow(max(0, dot(viewDir, reflectDir)), material.shininess) * material.specular; vec4 lighting = vec4(material.ambient + diffuse + specular, 1) * lightColor; if (material.hasTexture) FragColor = lighting * texture(tex, texCoord); else FragColor = lighting; }