#version 450

layout(binding = 3) uniform sampler2D texSampler;

layout(binding = 1) uniform LightInfo {
    vec3 position;
    vec3 color;
    float ambient_strength;
    float specular_strength;
} light;

layout(binding = 2) uniform CameraInfo {
    vec3 position;
} camera;

layout(location = 0) in vec3 fragColor;
layout(location = 1) in vec2 fragTexCoord;
layout(location = 2) in vec3 fragNormal;
layout(location = 3) in vec3 fragWorldPos;

layout(location = 0) out vec4 outColor;

void main() {
    // Get base color from texture
    vec4 texColor = texture(texSampler, fragTexCoord);
    
    // Normalize vectors
    vec3 normal = normalize(fragNormal);
    vec3 lightDir = normalize(light.position - fragWorldPos);
    vec3 viewDir = normalize(camera.position - fragWorldPos);
    vec3 reflectDir = reflect(-lightDir, normal);
    
    // Ambient
    vec3 ambient = light.ambient_strength * light.color;
    
    // Diffuse
    float diff = max(dot(normal, lightDir), 0.0);
    vec3 diffuse = diff * light.color;
    
    // Specular
    float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32.0);
    vec3 specular = light.specular_strength * spec * light.color;
    
    // Combine lighting components
    vec3 lighting = (ambient + diffuse + specular);
    outColor = vec4(lighting * texColor.rgb, texColor.a);
}
