From 3dc6ddbcc3981dd298cc66bc1a0309d9935aec1f Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 19 May 2018 19:20:45 +0200 Subject: [PATCH] - check light direction in the shader. There are situations where lights on the wrong side of a linedef may be passed and those need to be skipped in the shader code. --- wadsrc/static/shaders/glsl/material_normal.fp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/wadsrc/static/shaders/glsl/material_normal.fp b/wadsrc/static/shaders/glsl/material_normal.fp index b048f4559..c251351d9 100644 --- a/wadsrc/static/shaders/glsl/material_normal.fp +++ b/wadsrc/static/shaders/glsl/material_normal.fp @@ -9,6 +9,9 @@ vec3 lightContribution(int i, vec3 normal) float lightdistance = distance(lightpos.xyz, pixelpos.xyz); if (lightpos.w < lightdistance) return vec3(0.0); // Early out lights touching surface but not this fragment + + float dotprod = dot(normal, lightdir); + if (dotprod < 0.0) return vec3(0.0); // light hits from the backside. This can happen with full sector light lists and must be rejected for all cases. float attenuation = clamp((lightpos.w - lightdistance) / lightpos.w, 0.0, 1.0); @@ -18,7 +21,7 @@ vec3 lightContribution(int i, vec3 normal) if (lightcolor.a < 0.0) // Sign bit is the attenuated light flag { vec3 lightdir = normalize(lightpos.xyz - pixelpos.xyz); - attenuation *= clamp(dot(normal, lightdir), 0.0, 1.0); + attenuation *= clamp(dotprod, 0.0, 1.0); } if (attenuation > 0.0) // Skip shadow map test if possible