#version 330 core #ifndef LIGHT_GLSL #define LIGHT_GLSL struct Material { vec3 ambient; vec3 diffuse; vec3 specular; sampler2D ambient_map; sampler2D diffuse_map; sampler2D specular_map; float shininess; }; struct Light { vec3 position; vec3 diffuse; vec3 specular; }; uniform Material material; uniform Light light; vec3 calc_ambient_light(in vec2 texture_coords) { return vec3(texture(material.ambient_map, texture_coords)) * material.ambient; } vec3 calc_diffuse_light(in vec3 light_dir, in vec3 norm, in vec2 texture_coords) { float diff = max(dot(norm, light_dir), 0.0); return light.diffuse * ( diff * (vec3(texture(material.diffuse_map, texture_coords)) * material.diffuse) ); } vec3 calc_specular_light( in vec3 light_dir, in vec3 norm, in vec3 view_pos, in vec3 frag_pos, in vec2 texture_coords ) { vec3 view_direction = normalize(view_pos - frag_pos); vec3 reflect_direction = reflect(-light_dir, norm); float spec = pow(max(dot(view_direction, reflect_direction), 0.0), material.shininess); return light.specular * ( spec * (vec3(texture(material.specular_map, texture_coords)) * material.specular) ); } #endif