From 3af1129e75383f6609ca3e1dddeae0d1705c3035 Mon Sep 17 00:00:00 2001 From: Azaezel Date: Sun, 24 Mar 2019 18:04:41 -0500 Subject: [PATCH] refactor: shift probe to probe blending logic itsself on out to it's own method to make thatg end easeier to deal with in isolation. (though does still depend on a bit of upstream calculation in the form of tracking how many probes hit a given pixel, and 'how hard' as it wetre from the attenuation calcs, --- .../advanced/reflectionProbeArrayP.hlsl | 91 ++++++++++--------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl b/Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl index 5dd8e7724..9cef9c298 100644 --- a/Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl +++ b/Templates/Full/game/shaders/common/lighting/advanced/reflectionProbeArrayP.hlsl @@ -152,6 +152,52 @@ float3 iblSkylightSpecular(Surface surface, ProbeData probe) return color; } +void blendProbes(ProbeData probes[MAX_PROBES], float blendSum, float probehits) +{ + int i = 0; + float blendFactor[MAX_PROBES]; + float blendFacSum = 0; + // 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) + { + blendFactor[i] = ((probes[i].contribution / blendSum)) / (probehits - 1); + blendFactor[i] *= ((probes[i].contribution) / (1.0-blendSum)); + blendFacSum += blendFactor[i]; + } + else + { + blendFactor[i] = probes[i].contribution; + blendFacSum = probes[i].contribution; + } + } + + // Normalize blendVal +#if DEBUGVIZ_ATTENUATION == 0 //this can likely be removed when we fix the above normalization behavior + if (blendFacSum == 0.0f) // Possible with custom weight + { + blendFacSum = 1.0f; + } +#endif + //use probehits for sharp cuts when singular, + //blendSum when wanting blend on all edging + if (blendSum>1.0) + { + float invBlendSumWeighted = 1.0f / blendFacSum; + for (i = 0; i < numProbes; ++i) + { + blendFactor[i] *= invBlendSumWeighted; + probes[i].contribution = blendFactor[i]; + } + } +} + float4 main( PFXVertToPix IN ) : SV_TARGET { //unpack normal and linear depth @@ -168,10 +214,7 @@ float4 main( PFXVertToPix IN ) : SV_TARGET } int i = 0; - float blendFactor[MAX_PROBES]; float blendSum = 0; - float blendFacSum = 0; - float invBlendSum = 0; int skyID = 0; float probehits = 0; //Set up our struct data @@ -212,47 +255,9 @@ float4 main( PFXVertToPix IN ) : SV_TARGET probes[i].contribution = 0; blendSum += probes[i].contribution; - invBlendSum += (1.0f - 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) - { - 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; - } - } - - // Normalize blendVal -#if DEBUGVIZ_ATTENUATION == 0 //this can likely be removed when we fix the above normalization behavior - if (blendFacSum == 0.0f) // Possible with custom weight - { - blendFacSum = 1.0f; - } -#endif - //use probehits for sharp cuts when singular, - //blendSum when wanting blend on all edging - if (blendSum>1.0) - { - float invBlendSumWeighted = 1.0f / blendFacSum; - for (i = 0; i < numProbes; ++i) - { - blendFactor[i] *= invBlendSumWeighted; - probes[i].contribution = blendFactor[i]; - } } + blendProbes(probes, blendSum, probehits); + #if DEBUGVIZ_ATTENUATION == 1 float attenVis = 0; for (i = 0; i < numProbes; ++i)