[ad_1]
As a way to apply the metaball impact on a pixel within the Dest RenderTexture, I would like the minimal distance to each sport object that’s concerned in producing the metaball impact for that pixel. This implies I would like a non distinctive worth from a signed distance subject texture for that sport object on the level of that pixel. Right here is the compute shader methodology related to producing the metaball pixel shade:
[numthreads(THREAD_GROUP_WIDTH, THREAD_GROUP_WIDTH,1)]
void CSMainFirst (uint3 id : SV_DispatchThreadID)
{
//float4 srcPixel = max(ColorTextureArray.Load(uint3(id.xy, 0)), ColorTextureArray.Load(uint3(id.xy, 1)));
//float4 srcPixel = ColorTextureArray.Load(uint3(id.xy, 1));
float4 srcPixel = Src[id.xy];
//1. Case when pixel that's presently being processed is preliminary seed(a part of GO) and do not must be metaballed.
if(any(srcPixel.rgba > float4(0,0,0,0).rgba)) {
float4 displayPixel = float4(0,0,0,0);
uint visibleGameObjectCount = 0;
for(int i = 0; i < GameObjectListCount; i++) {
float4 colorAtDepth = ColorTextureArray.Load(uint3(id.xy, i));
if(any(colorAtDepth.rgba > float4(0,0,0,0).rgba)) {
displayPixel += colorAtDepth / GameObjectListCount;
visibleGameObjectCount++;
}
}
displayPixel *= (GameObjectListCount / visibleGameObjectCount);
if (all(Dest[id.xy].rgba <= float4(0,0,0,0).rgba)) {
Dest[id.xy] = displayPixel;
}
return;
}
//2. Case when pixel being processed is exterior sport object
else {
//Metaball impact
//variables
float closestDistanceProduct = 0;
int SDFcounter = 0;
int DistancePrimeCounter = 0;
uint visibleGameObjectCount = 0;
//Fetch blur shade
float metaballCoefficient = 0;
float metaballCoefficientOneUp = 0;
float finalMetaballCoefficient = 0;
float finalMetaballCoefficientOneUp = 0;
float metaballBlendingFactor = 0.055f; //0.025f = waterslime
float totalDistance = 0;
float4 metaballColor = float4(0,0,0,0);
//This loop should be carried out for each sport object in Src
for(int i = 0; i < GameObjectListCount; i++) {
//Present closest distance
float currentClosestDistance = SDFTextureArray.Load(uint3(id.xy, i));
// int currentDeltaX = (int)-DeltaXTextureArray.Load(uint3(id.xy, i));
// int currentDeltaY = (int)-DeltaYTextureArray.Load(uint3(id.xy, i));
//uint Modified Delta
// uint unsignedModifiedDeltaX = abs(currentDeltaX);
// uint unsignedModifiedDeltaY = abs(currentDeltaY);
//GCD
// int gcd = (int)binaryGCD(unsignedModifiedDeltaX, unsignedModifiedDeltaY);
// int minimumDeltaX = currentDeltaX / (gcd * 10);
// int minimumDeltaY = currentDeltaY / (gcd * 10);
//Present closest distance one up
// float currentClosestDistanceOneUp = SDFTextureArray.Load(uint3(uint2(id.x + minimumDeltaX, id.y + minimumDeltaY), i));
if(currentClosestDistance > 0) {
// if(currentClosestDistance > 24) {
// DistancePrimeCounter++;
// }
//Increment counter for seen SDF pixels at that id.xy
SDFcounter++;
//Replace complete distance
totalDistance += currentClosestDistance;
//Metaball coefficient replace
metaballCoefficient += exp2(-metaballBlendingFactor * currentClosestDistance);
}
}
//Compute weighted metaball shade
for(int j = 0; j < GameObjectListCount; j++) {
//(totalDistance - currentGameObjectDistance - ((SDFcounter * totalDistance - 2 * totalDistance) / SDFcounter)) / totalDistance
float currentClosestDistance = SDFTextureArray.Load(uint3(id.xy, j));
float4 currentClosestColor = ColorTextureArrayBeta.Load(uint3(id.xy, j));
if(currentClosestDistance > 0) {
float weight = (totalDistance - currentClosestDistance - ((SDFcounter * totalDistance - 2 * totalDistance) / SDFcounter)) / totalDistance;
metaballColor += currentClosestColor * weight;
}
}
finalMetaballCoefficient = -log2(metaballCoefficient) / metaballBlendingFactor;
//Metaball impact
//&& SDFcounter > 1
if(finalMetaballCoefficient < 0 && SDFcounter > 1) {
//Write to MetaballEdgeTex
//MetaballEdgeTex[id.xy] = float4(1,0,0,1);
Dest[id.xy] = metaballColor;
MetaballEdgeTex[id.xy] = float4(1,0,0,1);
// if(DistancePrimeCounter > 1) {
// MetaballEdgeTex[id.xy] = float4(0,0,1,1);
// }
}
return;
}
}
To date, the volumeDepth of SDFTextureArray has been set to the variety of instantiated sport objects since that approach, I can ensure that there are not any overlaps between generated SDF textures. With 3 different international texture arrays I am utilizing, simply 25 sport objects results in a complete volumeDepth of 100.
Am I forgetting to do some vital optimization step or is it regular that having a complete of 100+ textures(complete volumeDepth of 100+) massive sufficient to decelerate the whole sport for a tool with 8GB RAM? I actually didn’t suppose trendy computer systems have been feeble sufficient to not even be capable of course of 100 textures of dimension: 2778×1284, however that is the habits I am seeing.
[ad_2]