pressurecell improvements
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-15 21:46:05 -05:00
parent 9fb2f3f2e1
commit f009326ed3
5 changed files with 17 additions and 21 deletions

View File

@ -10,7 +10,7 @@
/** /**
* Spacing of cells * Spacing of cells
*/ */
#define FLUID_PRESSURECELL_SPACING 1.0f #define FLUID_PRESSURECELL_SPACING (1.0f/DIM)
/** /**
* Multiplier applied to pressure calculations to encourage advection * Multiplier applied to pressure calculations to encourage advection
@ -25,17 +25,12 @@
/** /**
* Diffusion constant * Diffusion constant
*/ */
#define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.0001f #define FLUID_PRESSURECELL_DIFFUSION_CONSTANT 0.01f
/** /**
* Viscosity constant * Viscosity constant
*/ */
#define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.0001f #define FLUID_PRESSURECELL_VISCOSITY_CONSTANT 0.01f
/**
* Amount that density contributes to the pressure
*/
#define FLUID_PRESSURECELL_DENSITY_CONST 0.001f
/** /**
* Amount of the residual to add to the pressure field each frame * Amount of the residual to add to the pressure field each frame

View File

@ -66,14 +66,15 @@ LIBRARY_API void pressurecell_advect_density(Environment * environment, Chunk *
float s0, s1, t0, t1, u0, u1; float s0, s1, t0, t1, u0, u1;
float interpolated; float interpolated;
float vecU, vecV, vecW; float vecU, vecV, vecW;
float interpConst = environment->consts.dt / FLUID_PRESSURECELL_SPACING;
for(y = 1; y < DIM-1; y++){ for(y = 1; y < DIM-1; y++){
//TODO: eventually skip y levels if there is no density to advect //TODO: eventually skip y levels if there is no density to advect
for(z = 1; z < DIM-1; z++){ for(z = 1; z < DIM-1; z++){
for(x = 1; x < DIM-1; x++){ for(x = 1; x < DIM-1; x++){
//calculate the real (float) position we are at //calculate the real (float) position we are at
vecU = u[IX(x,y,z)] * environment->consts.dt; vecU = u[IX(x,y,z)] * interpConst;
vecV = v[IX(x,y,z)] * environment->consts.dt; vecV = v[IX(x,y,z)] * interpConst;
vecW = w[IX(x,y,z)] * environment->consts.dt; vecW = w[IX(x,y,z)] * interpConst;
if(vecU > 0.999f){ if(vecU > 0.999f){
vecU = 0.999f; vecU = 0.999f;
} else if(vecU < -0.999f){ } else if(vecU < -0.999f){

View File

@ -82,8 +82,8 @@ LIBRARY_API void pressurecell_approximate_pressure(Environment * environment, Ch
for(y = 0; y < DIM; y++){ for(y = 0; y < DIM; y++){
for(x = 0; x < DIM; x++){ for(x = 0; x < DIM; x++){
phi0[IX(x,y,z)] = divArr[IX(x,y,z)]; phi0[IX(x,y,z)] = divArr[IX(x,y,z)];
// pressureTemp[IX(x,y,z)] = pressureCache[IX(x,y,z)]; pressureTemp[IX(x,y,z)] = pressureCache[IX(x,y,z)];
pressureTemp[IX(x,y,z)] = 0; // pressureTemp[IX(x,y,z)] = 0;
if(divArr[IX(x,y,z)] > 3){ if(divArr[IX(x,y,z)] > 3){
printf("invalid divergence!\n"); printf("invalid divergence!\n");
printf("%f \n", divArr[IX(x,y,z)]); printf("%f \n", divArr[IX(x,y,z)]);

View File

@ -59,7 +59,7 @@ LIBRARY_API void pressurecell_diffuse_velocity(Environment * environment, Chunk
float * uTemp = chunk->uTempCache; float * uTemp = chunk->uTempCache;
float * vTemp = chunk->vTempCache; float * vTemp = chunk->vTempCache;
float * wTemp = chunk->wTempCache; float * wTemp = chunk->wTempCache;
float D = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * environment->consts.dt; float D = FLUID_PRESSURECELL_DIFFUSION_CONSTANT * environment->consts.dt / (FLUID_PRESSURECELL_SPACING * FLUID_PRESSURECELL_SPACING);
for(z = 1; z < DIM-1; z++){ for(z = 1; z < DIM-1; z++){
for(y = 1; y < DIM-1; y++){ for(y = 1; y < DIM-1; y++){
for(x = 1; x < DIM-1; x++){ for(x = 1; x < DIM-1; x++){
@ -125,7 +125,7 @@ LIBRARY_API void pressurecell_advect_velocity(Environment * environment, Chunk *
float s0, s1, t0, t1, u0, u1; float s0, s1, t0, t1, u0, u1;
float interpolatedU, interpolatedV, interpolatedW; float interpolatedU, interpolatedV, interpolatedW;
float magnitude; float magnitude;
float interpConst = environment->consts.dt; float interpConst = environment->consts.dt / FLUID_PRESSURECELL_SPACING;
for(y = 1; y < DIM-1; y++){ for(y = 1; y < DIM-1; y++){
for(z = 1; z < DIM-1; z++){ for(z = 1; z < DIM-1; z++){
for(x = 1; x < DIM-1; x++){ for(x = 1; x < DIM-1; x++){
@ -344,11 +344,11 @@ LIBRARY_API double pressurecell_project_velocity(Environment * environment, Chun
//normalize if the projection has pushed us wayyy out of bounds //normalize if the projection has pushed us wayyy out of bounds
//ie, large pressure differentials can create huge imbalances //ie, large pressure differentials can create huge imbalances
if(magnitude > 1.0f){ // if(magnitude > 1.0f){
uArr[IX(x,y,z)] = uArr[IX(x,y,z)] / magnitude; // uArr[IX(x,y,z)] = uArr[IX(x,y,z)] / magnitude;
vArr[IX(x,y,z)] = vArr[IX(x,y,z)] / magnitude; // vArr[IX(x,y,z)] = vArr[IX(x,y,z)] / magnitude;
wArr[IX(x,y,z)] = wArr[IX(x,y,z)] / magnitude; // wArr[IX(x,y,z)] = wArr[IX(x,y,z)] / magnitude;
} // }
// magnitude = sqrt(uTemp[IX(x,y,z)] * uTemp[IX(x,y,z)] + vTemp[IX(x,y,z)] * vTemp[IX(x,y,z)] + wTemp[IX(x,y,z)] * wTemp[IX(x,y,z)]); // magnitude = sqrt(uTemp[IX(x,y,z)] * uTemp[IX(x,y,z)] + vTemp[IX(x,y,z)] * vTemp[IX(x,y,z)] + wTemp[IX(x,y,z)] * wTemp[IX(x,y,z)]);

View File

@ -29,7 +29,7 @@ public class FluidAcceleratedSimulator implements ServerFluidSimulator {
/** /**
* The gravity constant * The gravity constant
*/ */
public static final float GRAVITY_CONST = -10000f; public static final float GRAVITY_CONST = -100f;
/** /**
* Load fluid sim library * Load fluid sim library