From 0330dd5bd261912c49bfe1656436f5f16415ccc2 Mon Sep 17 00:00:00 2001 From: iurii Date: Sat, 7 Sep 2024 22:04:05 +0300 Subject: upd --- res/shaders/colors.fs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'res/shaders') 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); } -- cgit 1.4.1-2-gfad0