mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-29 16:25:42 +00:00
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,
This commit is contained in:
parent
de8b267780
commit
3af1129e75
1 changed files with 48 additions and 43 deletions
|
|
@ -152,6 +152,52 @@ float3 iblSkylightSpecular(Surface surface, ProbeData probe)
|
||||||
return color;
|
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
|
float4 main( PFXVertToPix IN ) : SV_TARGET
|
||||||
{
|
{
|
||||||
//unpack normal and linear depth
|
//unpack normal and linear depth
|
||||||
|
|
@ -168,10 +214,7 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
float blendFactor[MAX_PROBES];
|
|
||||||
float blendSum = 0;
|
float blendSum = 0;
|
||||||
float blendFacSum = 0;
|
|
||||||
float invBlendSum = 0;
|
|
||||||
int skyID = 0;
|
int skyID = 0;
|
||||||
float probehits = 0;
|
float probehits = 0;
|
||||||
//Set up our struct data
|
//Set up our struct data
|
||||||
|
|
@ -212,47 +255,9 @@ float4 main( PFXVertToPix IN ) : SV_TARGET
|
||||||
probes[i].contribution = 0;
|
probes[i].contribution = 0;
|
||||||
|
|
||||||
blendSum += probes[i].contribution;
|
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
|
#if DEBUGVIZ_ATTENUATION == 1
|
||||||
float attenVis = 0;
|
float attenVis = 0;
|
||||||
for (i = 0; i < numProbes; ++i)
|
for (i = 0; i < numProbes; ++i)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue