From 4ac43dac362ecc609be93b37414251efb7392208 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 17 Oct 2018 09:03:18 +0200 Subject: [PATCH] - fix distance attenuation for PBR materials --- wadsrc/static/shaders/glsl/material_pbr.fp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wadsrc/static/shaders/glsl/material_pbr.fp b/wadsrc/static/shaders/glsl/material_pbr.fp index 6ef60b66f..6859c28bb 100644 --- a/wadsrc/static/shaders/glsl/material_pbr.fp +++ b/wadsrc/static/shaders/glsl/material_pbr.fp @@ -56,6 +56,11 @@ float quadraticDistanceAttenuation(vec4 lightpos) return attenuation; } +float linearDistanceAttenuation(vec4 lightpos) +{ + float lightdistance = distance(lightpos.xyz, pixelpos.xyz); + return clamp((lightpos.w - lightdistance) / lightpos.w, 0.0, 1.0); +} vec3 ProcessMaterialLight(Material material, vec3 ambientLight) { @@ -93,7 +98,7 @@ vec3 ProcessMaterialLight(Material material, vec3 ambientLight) vec3 L = normalize(lightpos.xyz - worldpos); vec3 H = normalize(V + L); - float attenuation = quadraticDistanceAttenuation(lightpos); + float attenuation = linearDistanceAttenuation(lightpos); if (lightspot1.w == 1.0) attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y); if (lightcolor.a < 0.0) @@ -133,7 +138,7 @@ vec3 ProcessMaterialLight(Material material, vec3 ambientLight) vec3 L = normalize(lightpos.xyz - worldpos); vec3 H = normalize(V + L); - float attenuation = quadraticDistanceAttenuation(lightpos); + float attenuation = linearDistanceAttenuation(lightpos); if (lightspot1.w == 1.0) attenuation *= spotLightAttenuation(lightpos, lightspot1.xyz, lightspot2.x, lightspot2.y); if (lightcolor.a < 0.0)