- fix distance attenuation for PBR materials

This commit is contained in:
Magnus Norddahl 2018-10-17 09:03:18 +02:00
parent c0cf19e9b5
commit 4ac43dac36

View file

@ -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)