From de581501fb257bef2b65a9abcf63f51e0d1f5a79 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 22 Mar 2021 20:33:42 +0900 Subject: [PATCH] [vulkan] Early out from lights that are too distant Gives a 43% speed boost to bigass1 timedemo (366 -> 525 fps). --- libs/video/renderer/vulkan/shader/lighting.frag | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libs/video/renderer/vulkan/shader/lighting.frag b/libs/video/renderer/vulkan/shader/lighting.frag index 86e496991..3be1485ee 100644 --- a/libs/video/renderer/vulkan/shader/lighting.frag +++ b/libs/video/renderer/vulkan/shader/lighting.frag @@ -28,12 +28,17 @@ layout (location = 0) out vec4 frag_color; vec3 calc_light (LightData light, vec3 position, vec3 normal) { + float r = light.radius; vec3 dist = light.position - position; float d = sqrt (dot (dist, dist)); + if (d > r) { + // the light is too far away + return vec3 (0); + } + vec3 incoming = dist / d; float spotdot = dot (incoming, light.direction); float lightdot = dot (incoming, normal); - float r = light.radius; int style = light.data & 0x7f; // deliberate array index error: access intensity2 as well