diff options
Diffstat (limited to 'engine/light.glsl')
-rw-r--r-- | engine/light.glsl | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/engine/light.glsl b/engine/light.glsl index 92d3ec3..1bc23a4 100644 --- a/engine/light.glsl +++ b/engine/light.glsl @@ -36,6 +36,18 @@ struct PointLight AttenuationProperties attenuation_props; }; +struct DirectionalLight +{ + LightPhong phong; + vec3 direction; +}; + +struct CalculatedLight +{ + vec3 diffuse; + vec3 specular; +}; + vec3 calc_ambient_light(in Material material, in vec2 texture_coords) { return vec3(texture(material.ambient_map, texture_coords)) * material.ambient; @@ -88,40 +100,34 @@ float calc_attenuation(in PointLight point_light, in vec3 position) * pow(light_distance, 2)); } -vec3 calc_point_light( - in PointLight light, +void calc_light( + in vec3 light_direction, + in LightPhong light_phong, in VertexData vertex_data, in vec3 view_pos, - in Material material + in Material material, + out CalculatedLight calculated_light ) { - vec3 light_direction = normalize(light.position - vertex_data.world_space_pos); vec3 norm = normalize(vertex_data.world_space_normal); - vec3 diffuse_light = calc_diffuse_light( + calculated_light.diffuse = calc_diffuse_light( material, - light.phong, + light_phong, light_direction, norm, vertex_data.texture_coords ); - vec3 specular_light = calc_specular_light( + calculated_light.specular = calc_specular_light( material, - light.phong, + light_phong, light_direction, norm, view_pos, vertex_data.world_space_pos, vertex_data.texture_coords ); - - float attenuation = calc_attenuation(light, vertex_data.world_space_pos); - - diffuse_light *= attenuation; - specular_light *= attenuation; - - return diffuse_light + specular_light; } #endif |