diff options
author | iurii <[email protected]> | 2024-09-07 21:04:05 +0200 |
---|---|---|
committer | iurii <[email protected]> | 2024-09-07 21:04:05 +0200 |
commit | 0330dd5bd261912c49bfe1656436f5f16415ccc2 (patch) | |
tree | 72acbe628538690bdab2859d0c5e9177d43896cb | |
parent | 8e77fd544fa40d787f34ed667d5d818ca4bfc6e9 (diff) | |
download | funhalla-0330dd5bd261912c49bfe1656436f5f16415ccc2.tar.gz |
upd
-rw-r--r-- | res/shaders/colors.fs | 12 | ||||
-rw-r--r-- | src/main.odin | 4 |
2 files changed, 16 insertions, 0 deletions
diff --git a/res/shaders/colors.fs b/res/shaders/colors.fs index 56762e1..142d843 100644 --- a/res/shaders/colors.fs +++ b/res/shaders/colors.fs @@ -6,6 +6,7 @@ struct Material { sampler2D diffuse; sampler2D specular; float shininess; + }; struct Light { @@ -13,6 +14,10 @@ struct Light { vec3 ambient; vec3 diffuse; vec3 specular; + + float constant; + float linear; + float quadratic; }; in vec3 Normal; @@ -39,6 +44,13 @@ void main() { float spec = pow(max(dot(view_dir, reflect_dir), 0.0), material.shininess); vec3 specular = light.specular * spec * texture(material.specular, TexCoords).rgb; + float distance = length(light.positon - FragPos); + float attenuation = 1.0 / (light.constant + light.linear * distance + light.quadratic * (distance * distance)); + + abient *= attenuation; + diffuse *= attenuation; + specular *= attenuation; + vec3 result = ambient + diffuse + specular; FragColor = vec4(result, 1.0); } diff --git a/src/main.odin b/src/main.odin index db25478..eee26e2 100644 --- a/src/main.odin +++ b/src/main.odin @@ -206,6 +206,10 @@ main :: proc() { shader_set_vec3(lighting_shader, cstring("light_position"), &light_pos) shader_set_vec3(lighting_shader, cstring("view_position"), &camera.position) + shader_set_f32(lighting_shader, "light.constant", 1.0) + shader_set_f32(lighting_shader, "light.linear", 0.09) + shader_set_f32(lighting_shader, "light.qudratic", 0.032) + aspect: f32 = 800.0 / 600.0 projection := linalg.matrix4_perspective_f32( linalg.to_radians(camera.zoom), |