From 9b2b87c569466d9705d82bf5228c8c23524cccb1 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Tue, 26 Mar 2019 12:41:20 -0500 Subject: [PATCH] cleanups and perf: only need to subtract the alpha post-blending, not pre and post, contribution>1 shouldn't happen, so max(result,0) suffices, and no need for a for-all-probes-loop if we already know ya only got one probe hitting the pixel under examination. --- .../advanced/reflectionProbeArrayP.hlsl | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl index 9e2bd737b..fc8caa22a 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl @@ -202,34 +202,30 @@ float4 main(PFXVertToPix IN) : SV_TARGET probehits++; } - if (probes[i].contribution>1 || probes[i].contribution<0) - probes[i].contribution = 0; + probes[i].contribution = max(probes[i].contribution,0); blendSum += probes[i].contribution; invBlendSum += (1.0f - probes[i].contribution); - - alpha -= probes[i].contribution; } - // Weight0 = normalized NDF, inverted to have 1 at center, 0 at boundary. // And as we invert, we need to divide by Num-1 to stay normalized (else sum is > 1). // respect constraint B. // Weight1 = normalized inverted NDF, so we have 1 at center, 0 at boundary // and respect constraint A. - for (i = 0; i < numProbes; i++) + if (probehits>1.0) { - if (probehits>1.0) - { - blendFactor[i] = ((probes[i].contribution / blendSum)) / (probehits - 1); + for (i = 0; i < numProbes; i++) + { + blendFactor[i] = ((probes[i].contribution / blendSum)) / (probehits - 1); blendFactor[i] *= ((probes[i].contribution) / invBlendSum); blendFacSum += blendFactor[i]; } - else - { - blendFactor[i] = probes[i].contribution; - blendFacSum = probes[i].contribution; - } } + else + { + blendFactor[i] = probes[i].contribution; + blendFacSum = probes[i].contribution; + } // Normalize blendVal