fix cellular border fluid transfer
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-07 11:03:07 -05:00
parent d6939ba8dd
commit f561d21bf3
2 changed files with 72 additions and 9 deletions

View File

@ -36,9 +36,9 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
int transferred = 0;
// printf("%f %f %f %d %d %d\n",bounds[IX(0,1,1)],bounds[IX(1,0,1)],bounds[IX(1,1,0)],currentChunk->x,currentChunk->y,currentChunk->z);
for(int x = 1; x < DIM-1; x++){
for(int y = 1; y < DIM-1; y++){
for(int z = 1; z < DIM-1; z++){
for(int x = 0; x < DIM; x++){
for(int y = 0; y < DIM; y++){
for(int z = 0; z < DIM; z++){
//diffuse density
// d[IX(x,y,z)] = d[IX(x,y,z)];
@ -98,7 +98,7 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
if(d[IX(x,y,z)] <= MIN_FLUID_VALUE){
} else {
//transfer straight down
{
if(y > 0){
float nBound = bounds[IX(x,y-1,z)];
if(nBound <= BOUND_CUTOFF_VALUE){
if(d[IX(x,y-1,z)] <= MIN_FLUID_VALUE){
@ -112,9 +112,11 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
for(int j = 0; j < FLUID_CELLULAR_KERNEL_SIZE; j++){
int nX = x + fluid_cellular_kernel_x[j];
int nZ = z + fluid_cellular_kernel_z[j];
if(nX < 0 || nX >= DIM || nZ < 0 || nZ >= DIM){
continue;
}
if(bounds[IX(nX,y,nZ)] <= BOUND_CUTOFF_VALUE){
if(d[IX(nX,y,nZ)] <= MIN_FLUID_VALUE){
printf("%d %d %d -> %d %d %d \n",x,y,z,nX,y,nZ);
d[IX(nX,y,nZ)] = d[IX(x,y,z)];
d[IX(x,y,z)] = MIN_FLUID_VALUE;
break;

View File

@ -38,8 +38,10 @@ int fluid_sim_cellular_cellular_tests_kernelz[27] = {
int fluid_sim_cellular_bounds_tests(){
int fluid_sim_cellular_bounds_test1(){
int rVal = 0;
printf("fluid_sim_cellular_bounds_test1\n");
Environment * env = fluid_environment_create();
int chunkCount = 27;
@ -71,7 +73,7 @@ int fluid_sim_cellular_bounds_tests(){
float borderVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-2)];
float transferedVal = queue[1]->d[CENTER_LOC][IX(1,1,0)];
rVal += assertEqualsFloat(borderVal,CELLULAR_TEST_PLACE_VAL,"Border value was overwritten! -- %f %f \n");
rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value want not transfered from border! -- %f %f \n");
rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value was not transfered from border! -- %f %f \n");
}
//dispatch and simulate
@ -85,7 +87,65 @@ int fluid_sim_cellular_bounds_tests(){
float transferedVal = queue[1]->d[CENTER_LOC][IX(1,1,0)];
rVal += assertEqualsFloat(borderVal,MIN_FLUID_VALUE,"Border value has not changed! -- %f %f \n");
rVal += assertEqualsFloat(orderBorderVal,CELLULAR_TEST_PLACE_VAL,"Border value has not moved! -- %f %f \n");
rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value want not transfered from border! -- %f %f \n");
rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value was overwritten on border! -- %f %f \n");
}
return rVal;
}
int fluid_sim_cellular_bounds_test2(){
int rVal = 0;
printf("fluid_sim_cellular_bounds_test2\n");
Environment * env = fluid_environment_create();
int chunkCount = 27;
Chunk ** queue = NULL;
for(int i = 0; i < chunkCount; i++){
arrput(queue,chunk_create(
fluid_sim_cellular_cellular_tests_kernelx[i],
fluid_sim_cellular_cellular_tests_kernely[i],
fluid_sim_cellular_cellular_tests_kernelz[i]
));
}
//link neighbors
chunk_link_neighbors(queue);
//fill them with values
for(int i = 0; i < chunkCount; i++){
chunk_fill(queue[i],0);
}
//set border of 0,0,0 to push a value into z
queue[1]->d[CENTER_LOC][IX(1,1,1)] = CELLULAR_TEST_PLACE_VAL;
//call bounds setter
fluid_solve_bounds(chunkCount,queue,env);
{
float borderVal = queue[1]->d[CENTER_LOC][IX(1,1,1)];
float transferedVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-1)];
rVal += assertEqualsFloat(borderVal,CELLULAR_TEST_PLACE_VAL,"Border value was overwritten! -- %f %f \n");
rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value was not transfered from border! -- %f %f \n");
}
//dispatch and simulate
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
fluid_solve_bounds(chunkCount,queue,env);
fluid_dispatch(chunkCount,queue,env);
fluid_simulate(env);
//assert that the density moved
{
float borderVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-2)];
float orderBorderVal = queue[0]->d[CENTER_LOC][IX(1,1,DIM-3)];
float transferedVal = queue[1]->d[CENTER_LOC][IX(1,1,0)];
rVal += assertEqualsFloat(borderVal,MIN_FLUID_VALUE,"Border value has not changed! -- %f %f \n");
rVal += assertEqualsFloat(orderBorderVal,CELLULAR_TEST_PLACE_VAL,"Border value has not moved! -- %f %f \n");
rVal += assertEqualsFloat(transferedVal,CELLULAR_TEST_PLACE_VAL,"Value was overwritten on border! -- %f %f \n");
}
return rVal;
@ -95,7 +155,8 @@ int fluid_sim_cellular_bounds_tests(){
int fluid_sim_cellular_cellular_tests(int argc, char **argv){
int rVal = 0;
rVal += fluid_sim_cellular_bounds_tests();
rVal += fluid_sim_cellular_bounds_test1();
rVal += fluid_sim_cellular_bounds_test2();
return rVal;
}