simulation improvements
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-12-07 19:27:57 -05:00
parent c8cf14fed1
commit e40cc0a6d4
2 changed files with 28 additions and 30 deletions

View File

@ -59,7 +59,8 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
} else { } else {
permuteY = y + (CHUNK_SPACING * worldY); permuteY = y + (CHUNK_SPACING * worldY);
} }
int shift = randutils_map(randutils_rand2(environment->state.frame,permuteY),0,FLUID_CELLULAR_KERNEL_PERMUTATIONS - 1); // int shift = randutils_map(randutils_rand2(environment->state.frame,permuteY),0,FLUID_CELLULAR_KERNEL_PERMUTATIONS - 1);
int shift = environment->state.frame % FLUID_CELLULAR_KERNEL_PERMUTATIONS;
// int permutation = randutils_map(randutils_rand2(environment->state.frame,y + 1),0,FLUID_CELLULAR_KERNEL_PERMUTATIONS - 1); // int permutation = randutils_map(randutils_rand2(environment->state.frame,y + 1),0,FLUID_CELLULAR_KERNEL_PERMUTATIONS - 1);
for(int x = 0; x < DIM; x++){ for(int x = 0; x < DIM; x++){
for(int z = 0; z < DIM; z++){ for(int z = 0; z < DIM; z++){
@ -74,8 +75,6 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
float nBound = bounds[IX(x,y-1,z)]; float nBound = bounds[IX(x,y-1,z)];
if(nBound <= BOUND_CUTOFF_VALUE){ if(nBound <= BOUND_CUTOFF_VALUE){
if(d[IX(x,y-1,z)] <= MAX_FLUID_VALUE - FLUID_CELLULAR_DIFFUSE_RATE2){ if(d[IX(x,y-1,z)] <= MAX_FLUID_VALUE - FLUID_CELLULAR_DIFFUSE_RATE2){
// d[IX(x,y-1,z)] = d[IX(x,y,z)];
// d[IX(x,y,z)] = MIN_FLUID_VALUE;
float transfer = FLUID_CELLULAR_DIFFUSE_RATE2; float transfer = FLUID_CELLULAR_DIFFUSE_RATE2;
if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){ if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){
transfer = d[IX(x,y,z)]; transfer = d[IX(x,y,z)];
@ -118,32 +117,31 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
permuteZ = z + (CHUNK_SPACING * worldZ); permuteZ = z + (CHUNK_SPACING * worldZ);
} }
int permutation = (permuteZ % (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2)) + (((permuteX % (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2))) * (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2)); int permutation = (permuteZ % (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2)) + (((permuteX % (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2))) * (FLUID_CELLULAR_KERNEL_PERMUTATIONS / 2));
// for(int j = 0; j < FLUID_CELLULAR_KERNEL_SIZE; j++){ int nX = x + fluid_cellular_kernel_x[shift][permutation];
int nX = x + fluid_cellular_kernel_x[shift][permutation]; int nZ = z + fluid_cellular_kernel_z[shift][permutation];
int nZ = z + fluid_cellular_kernel_z[shift][permutation]; // printf("[%d %d %d] <%d,%d,%d>\n",worldX,worldY,worldZ,x,y,z);
// printf("[%d %d %d] <%d,%d,%d>\n",worldX,worldY,worldZ,x,y,z); // printf("%d %d \n",permuteX,permuteZ);
// printf("%d %d \n",permuteX,permuteZ); if(nX < 0 || nX >= DIM || nZ < 0 || nZ >= DIM){
if(nX < 0 || nX >= DIM || nZ < 0 || nZ >= DIM){ continue;
continue; }
} if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){
if(bounds[IX(nX,y,nZ)] <= BOUND_CUTOFF_VALUE){ continue;
if(d[IX(nX,y,nZ)] <= MAX_FLUID_VALUE - FLUID_CELLULAR_DIFFUSE_RATE2 && d[IX(nX,y,nZ)] < d[IX(x,y,z)]){ }
float transfer = FLUID_CELLULAR_DIFFUSE_RATE2; if(bounds[IX(nX,y,nZ)] <= BOUND_CUTOFF_VALUE){
if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){ if(d[IX(nX,y,nZ)] <= MAX_FLUID_VALUE - FLUID_CELLULAR_DIFFUSE_RATE2 && d[IX(nX,y,nZ)] < d[IX(x,y,z)]){
transfer = d[IX(x,y,z)]; float transfer = FLUID_CELLULAR_DIFFUSE_RATE2;
} if(d[IX(x,y,z)] < FLUID_CELLULAR_DIFFUSE_RATE2){
// printf("[%d %d %d] <%d,%d,%d> --> <%d,%d,%d> \n",worldX,worldY,worldZ,x,y,z,nX,y,nZ); transfer = d[IX(x,y,z)];
// printf("%f %d %d \n",transfer,permuteX,permuteZ);
// printf("%f %f \n",d[IX(x,y,z)],d[IX(nX,y,nZ)]);
// d[IX(nX,y,nZ)] = d[IX(x,y,z)];
// d[IX(x,y,z)] = MIN_FLUID_VALUE;
d[IX(nX,y,nZ)] = d[IX(nX,y,nZ)] + transfer;
d[IX(x,y,z)] = d[IX(x,y,z)] - transfer;
// printf("%f %f \n",d[IX(x,y,z)],d[IX(nX,y,nZ)]);
// printf("\n");
} }
// printf("[%d %d %d] <%d,%d,%d> --> <%d,%d,%d> \n",worldX,worldY,worldZ,x,y,z,nX,y,nZ);
// printf("%f %d %d \n",transfer,permuteX,permuteZ);
// printf("%f %f \n",d[IX(x,y,z)],d[IX(nX,y,nZ)]);
d[IX(nX,y,nZ)] = d[IX(nX,y,nZ)] + transfer;
d[IX(x,y,z)] = d[IX(x,y,z)] - transfer;
// printf("%f %f \n",d[IX(x,y,z)],d[IX(nX,y,nZ)]);
// printf("\n");
} }
// } }
} }
} }
} }

View File

@ -196,7 +196,7 @@ int fluid_sim_cellular_stability_test1(){
//dispatch and simulate //dispatch and simulate
int frameCount = 5000; int frameCount = 1000;
for(int frameCounter = 0; frameCounter < frameCount; frameCounter++){ for(int frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue); float currentSum = chunk_queue_sum(queue);
if(currentSum != originalSum){ if(currentSum != originalSum){
@ -265,7 +265,7 @@ int fluid_sim_cellular_stability_test2(){
//dispatch and simulate //dispatch and simulate
int frameCount = 5000; int frameCount = 1000;
for(int frameCounter = 0; frameCounter < frameCount; frameCounter++){ for(int frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue); float currentSum = chunk_queue_sum(queue);
if(currentSum != originalSum){ if(currentSum != originalSum){
@ -333,7 +333,7 @@ int fluid_sim_cellular_stability_test3(){
float originalSum = chunk_queue_sum(queue); float originalSum = chunk_queue_sum(queue);
//dispatch and simulate //dispatch and simulate
int frameCount = 50; int frameCount = 1000;
int frameCounter; int frameCounter;
for(frameCounter = 0; frameCounter < frameCount; frameCounter++){ for(frameCounter = 0; frameCounter < frameCount; frameCounter++){
float currentSum = chunk_queue_sum(queue); float currentSum = chunk_queue_sum(queue);