diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-20 22:00:34 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-20 22:00:34 +0100 |
commit | b0315b7ebc16fcbae6c3098db6c824f9057d2a71 (patch) | |
tree | c7473fbdbcc59aff933790892ee015a6f05d8565 /engine/light.glsl | |
parent | a65c8abcae46b382b2e1bb7cc5d13768325083b4 (diff) |
feat(engine): add materials
Diffstat (limited to 'engine/light.glsl')
-rw-r--r-- | engine/light.glsl | 35 |
1 files changed, 25 insertions, 10 deletions
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); } |