normalization corner handling
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-12-17 17:48:24 -05:00
parent 4e1f29a718
commit 64e13e2457
2 changed files with 238 additions and 2 deletions

View File

@ -656,6 +656,242 @@ LIBRARY_API void fluid_pressurecell_recapture_density(Environment * env, Chunk *
//check corner -x, -y, -z
neighbor = CK(0,0,0);
if(chunk->d[neighbor] == NULL){
ghostIndex = IX(0,0,0);
adjacentIndex = IX(1,1,1);
if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){
invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex]));
estimatedLoss = dArr[adjacentIndex] / invertedForce;
dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss;
overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE;
pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE;
if(overdraw > 0){
chunk->pressureCellData.recaptureDensity += overdraw;
dArr[adjacentIndex] = MAX_FLUID_VALUE;
}
}
} else {
ghostIndex = IX(0,0,0);
adjacentIndex = IX(1,1,1);
if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){
chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex];
}
}
//check corner -x, +y, -z
neighbor = CK(0,2,0);
if(chunk->d[neighbor] == NULL){
ghostIndex = IX(0,DIM-1,0);
adjacentIndex = IX(1,DIM-2,1);
if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){
invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex]));
estimatedLoss = dArr[adjacentIndex] / invertedForce;
dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss;
overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE;
pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE;
if(overdraw > 0){
chunk->pressureCellData.recaptureDensity += overdraw;
dArr[adjacentIndex] = MAX_FLUID_VALUE;
}
}
} else {
ghostIndex = IX(0,DIM-1,0);
adjacentIndex = IX(1,DIM-2,1);
if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){
chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex];
}
}
//check corner +x, -y, -z
neighbor = CK(2,0,0);
if(chunk->d[neighbor] == NULL){
ghostIndex = IX(DIM-1,0,0);
adjacentIndex = IX(DIM-2,1,1);
if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){
invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex]));
estimatedLoss = dArr[adjacentIndex] / invertedForce;
dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss;
overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE;
pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE;
if(overdraw > 0){
chunk->pressureCellData.recaptureDensity += overdraw;
dArr[adjacentIndex] = MAX_FLUID_VALUE;
}
}
} else {
ghostIndex = IX(DIM-1,0,0);
adjacentIndex = IX(DIM-2,1,1);
if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){
chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex];
}
}
//check corner +x, +y, -z
neighbor = CK(2,2,0);
if(chunk->d[neighbor] == NULL){
ghostIndex = IX(DIM-1,DIM-1,0);
adjacentIndex = IX(DIM-2,DIM-2,1);
if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){
invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex]));
estimatedLoss = dArr[adjacentIndex] / invertedForce;
dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss;
overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE;
pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE;
if(overdraw > 0){
chunk->pressureCellData.recaptureDensity += overdraw;
dArr[adjacentIndex] = MAX_FLUID_VALUE;
}
}
} else {
ghostIndex = IX(DIM-1,DIM-1,0);
adjacentIndex = IX(DIM-2,DIM-2,1);
if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){
chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex];
}
}
//check corner -x, -y, +z
neighbor = CK(0,0,2);
if(chunk->d[neighbor] == NULL){
ghostIndex = IX(0,0,DIM-1);
adjacentIndex = IX(1,1,DIM-2);
if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){
invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex]));
estimatedLoss = dArr[adjacentIndex] / invertedForce;
dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss;
overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE;
pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE;
if(overdraw > 0){
chunk->pressureCellData.recaptureDensity += overdraw;
dArr[adjacentIndex] = MAX_FLUID_VALUE;
}
}
} else {
ghostIndex = IX(0,0,DIM-1);
adjacentIndex = IX(1,1,DIM-2);
if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){
chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex];
}
}
//check corner -x, +y, +z
neighbor = CK(0,2,2);
if(chunk->d[neighbor] == NULL){
ghostIndex = IX(0,DIM-1,DIM-1);
adjacentIndex = IX(1,DIM-2,DIM-2);
if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){
invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex]));
estimatedLoss = dArr[adjacentIndex] / invertedForce;
dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss;
overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE;
pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE;
if(overdraw > 0){
chunk->pressureCellData.recaptureDensity += overdraw;
dArr[adjacentIndex] = MAX_FLUID_VALUE;
}
}
} else {
ghostIndex = IX(0,DIM-1,DIM-1);
adjacentIndex = IX(1,DIM-2,DIM-2);
if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){
chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex];
}
}
//check corner +x, -y, +z
neighbor = CK(2,0,2);
if(chunk->d[neighbor] == NULL){
ghostIndex = IX(DIM-1,0,DIM-1);
adjacentIndex = IX(DIM-2,1,DIM-2);
if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] < 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){
invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex]));
estimatedLoss = dArr[adjacentIndex] / invertedForce;
dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss;
overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE;
pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE;
if(overdraw > 0){
chunk->pressureCellData.recaptureDensity += overdraw;
dArr[adjacentIndex] = MAX_FLUID_VALUE;
}
}
} else {
ghostIndex = IX(DIM-1,0,DIM-1);
adjacentIndex = IX(DIM-2,1,DIM-2);
if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){
chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex];
}
}
//check corner +x, +y, +z
neighbor = CK(2,2,2);
if(chunk->d[neighbor] == NULL){
ghostIndex = IX(DIM-1,DIM-1,DIM-1);
adjacentIndex = IX(DIM-2,DIM-2,DIM-2);
if((uArr[adjacentIndex] < 0 || vArr[adjacentIndex] > 0 || wArr[adjacentIndex] < 0) && dArr[adjacentIndex] > 0){
invertedForce = (1.0f - fabs(uArr[adjacentIndex])) * (1.0f - fabs(vArr[adjacentIndex])) * (1.0f - fabs(wArr[adjacentIndex]));
estimatedLoss = dArr[adjacentIndex] / invertedForce;
dArr[adjacentIndex] = dArr[adjacentIndex] + estimatedLoss;
overdraw = dArr[adjacentIndex] - MAX_FLUID_VALUE;
pressure[adjacentIndex] = pressure[adjacentIndex] + FLUID_PRESSURECELL_RECAPTURE_PRESSURE;
if(overdraw > 0){
chunk->pressureCellData.recaptureDensity += overdraw;
dArr[adjacentIndex] = MAX_FLUID_VALUE;
}
}
} else {
ghostIndex = IX(DIM-1,DIM-1,DIM-1);
adjacentIndex = IX(DIM-2,DIM-2,DIM-2);
if(vArr[adjacentIndex] > 0 && vArr[adjacentIndex] > 0 && wArr[adjacentIndex] > 0 && dArr[adjacentIndex] > 0){
chunk->pressureCellData.outgoingDensity[neighbor] += dArr[ghostIndex];
}
}
} }

View File

@ -39,10 +39,10 @@ int fluid_sim_pressurecell_normalization_test1(){
//setup chunk values //setup chunk values
float deltaDensity = 0.01f; float deltaDensity = 0.01f;
Chunk * currentChunk = queue[0]; Chunk * currentChunk = queue[0];
currentChunk->v[CENTER_LOC][IX(1,1,1)] = -0.8; currentChunk->vTempCache[IX(1,1,1)] = -0.8;
currentChunk->d[CENTER_LOC][IX(1,1,1)] = 0.2; currentChunk->d[CENTER_LOC][IX(1,1,1)] = 0.2;
currentChunk->v[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = 0.8; currentChunk->vTempCache[IX(DIM-2,DIM-2,DIM-2)] = 0.8;
currentChunk->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = 0.2; currentChunk->d[CENTER_LOC][IX(DIM-2,DIM-2,DIM-2)] = 0.2;
//actually simulate //actually simulate