From b0315b7ebc16fcbae6c3098db6c824f9057d2a71 Mon Sep 17 00:00:00 2001 From: HampusM Date: Mon, 20 Nov 2023 22:00:34 +0100 Subject: feat(engine): add materials --- engine/light.glsl | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'engine/light.glsl') diff --git a/engine/light.glsl b/engine/light.glsl index 3f1c601..0ceac16 100644 --- a/engine/light.glsl +++ b/engine/light.glsl @@ -1,18 +1,33 @@ #version 330 core -uniform vec3 light_color; -uniform vec3 light_pos; - -uniform float ambient_light_strength; -uniform float specular_light_strength; - -uniform uint specular_shininess; +struct Material { + vec3 ambient; + vec3 diffuse; + vec3 specular; + float shininess; +}; + +struct Light { + vec3 position; + + vec3 ambient; + vec3 diffuse; + vec3 specular; +}; + +uniform Material material; +uniform Light light; + +vec3 calc_ambient_light() +{ + return light.ambient * material.ambient; +} vec3 calc_diffuse_light(in vec3 light_dir, in vec3 norm) { float diff = max(dot(norm, light_dir), 0.0); - return diff * light_color; + return light.diffuse * (diff * material.diffuse); } vec3 calc_specular_light( @@ -27,8 +42,8 @@ vec3 calc_specular_light( vec3 reflect_direction = reflect(-light_dir, norm); float spec = - pow(max(dot(view_direction, reflect_direction), 0.0), specular_shininess); + pow(max(dot(view_direction, reflect_direction), 0.0), material.shininess); - return specular_light_strength * spec * light_color; + return light.specular * (spec * material.specular); } -- cgit v1.2.3-18-g5258