Skip to content

Commit

Permalink
remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
jintaoyugithub committed Dec 12, 2024
1 parent e6abf7c commit 76d6201
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 79 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
### 2024.11.25

- [x] finish `advect` function, we can run interpolate in `afvect` first, then add advect
- [ ] add camera movement
- [x] add camera movement
- [ ] interpolate the velocity after `add source`

### 2024.12.03
Expand Down
73 changes: 4 additions & 69 deletions examples/fluidSim/fluidSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ double lastMousePosY = 0.0f;
bool isPressed = false;

// for debug
bool EnableAdvect = true;
bool EnableProject = true;
bool EnableAdvect = false;
bool EnableProject = false;
bool DebugDispDiv = false;
bool DebugDispProject = false;
bool DebugDispAdvect = false;
Expand All @@ -30,16 +30,6 @@ float deltaX = 0.01;
float deltaY = 0.01;
float deltaZ = 0.01;

struct testSphere
{
// center pos
float x = 0.0f;
float y = 0.0f;
float z = -0.1f;

float radius = 5.0f;
};

class ExampleFluidSim : public shift::AppBaseGLFW
{
void init(int _argc, const char **_argv, uint32_t width, uint32_t height) override
Expand All @@ -61,15 +51,7 @@ class ExampleFluidSim : public shift::AppBaseGLFW
velocityGrid = new VelocityFieldGrid(getWidth(), getHeight(), 1.0f);
velocityGrid->updateUniforms(UniformType::Radius, 15.0f);

velocityCube = new VelocityFieldCube(getWidth(), getHeight(), 512.0f);

velocityGrid->dispatch(ProgramType::Reset, 0);

// init the inter pos uniform with sphere
velocityCube->updateUniforms(UniformType::InterPosX, sphere.x);
velocityCube->updateUniforms(UniformType::InterPosY, sphere.y);
velocityCube->updateUniforms(UniformType::InterPosZ, sphere.z);
velocityCube->updateUniforms(UniformType::Radius, sphere.radius);
}
}

Expand Down Expand Up @@ -225,8 +207,8 @@ class ExampleFluidSim : public shift::AppBaseGLFW
{
std::cout << "Reset the program" << std::endl;
velocityGrid->dispatch(ProgramType::Reset, 0);
// EnableAdvect = false;
// EnableProject = false;
EnableAdvect = false;
EnableProject = false;
}

if (_event.keyboard.key == GLFW_KEY_A)
Expand Down Expand Up @@ -268,51 +250,6 @@ class ExampleFluidSim : public shift::AppBaseGLFW
}
break;

case GLEQ_KEY_REPEATED:
// control the sphere
if (_event.keyboard.key == GLFW_KEY_UP)
{
sphere.y += deltaZ;
std::cout << sphere.x << " " << sphere.y << " " << sphere.z << std::endl;

velocityGrid->updateUniforms(UniformType::InterPosY, sphere.y);
velocityGrid->updateUniforms(UniformType::InterVelX, 0.0f);
velocityGrid->updateUniforms(UniformType::InterVelY, 1.0f);

velocityGrid->dispatch(ProgramType::AddSource, 0);
}
if (_event.keyboard.key == GLFW_KEY_DOWN)
{
sphere.y -= deltaZ;
std::cout << sphere.x << " " << sphere.y << " " << sphere.z << std::endl;

velocityGrid->updateUniforms(UniformType::InterPosY, sphere.y);
velocityGrid->updateUniforms(UniformType::InterVelX, 0.0f);
velocityGrid->updateUniforms(UniformType::InterVelY, -1.0f);
velocityGrid->dispatch(ProgramType::AddSource, 0);
}
if (_event.keyboard.key == GLFW_KEY_LEFT)
{
sphere.x -= deltaX;
std::cout << sphere.x << " " << sphere.y << " " << sphere.z << std::endl;

velocityGrid->updateUniforms(UniformType::InterPosX, sphere.x);
velocityGrid->updateUniforms(UniformType::InterVelX, -1.0f);
velocityGrid->updateUniforms(UniformType::InterVelY, 0.0f);
velocityGrid->dispatch(ProgramType::AddSource, 0);
}
if (_event.keyboard.key == GLFW_KEY_RIGHT)
{
sphere.x += deltaX;
std::cout << sphere.x << " " << sphere.y << " " << sphere.z << std::endl;

velocityGrid->updateUniforms(UniformType::InterPosX, sphere.x);
velocityGrid->updateUniforms(UniformType::InterVelX, 1.0f);
velocityGrid->updateUniforms(UniformType::InterVelY, 0.0f);
velocityGrid->dispatch(ProgramType::AddSource, 0);
}
break;

case GLEQ_KEY_RELEASED:
break;
}
Expand Down Expand Up @@ -342,8 +279,6 @@ class ExampleFluidSim : public shift::AppBaseGLFW
}

private:
testSphere sphere;

bool _computeSupported;
bool _indirectSupported;

Expand Down
2 changes: 1 addition & 1 deletion examples/fluidSim/velocityField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ VelocityField::VelocityField(int simResX, int simResY, int simResZ)
_uParams.simResY = float(simResY);
_uParams.simResZ = float(simResZ);
_uParams.deltaTime = 0.02f;
_uParams.speed = 75.0f;
_uParams.speed = 120.0f;
_uParams.divOffsetX = 0.0f;
_uParams.divOffsetY = 0.0f;
_uParams.divOffsetZ = 0.0f;
Expand Down
2 changes: 1 addition & 1 deletion examples/fluidSim/velocityField.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ class VelocityField
}

public:
int solverItr = 10;
int solverItr = 50;

protected:
// group size of compute shader
Expand Down
7 changes: 5 additions & 2 deletions include/utils/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@
#define GLEQ_STATIC
#include <gleq.hpp>

const float SHIFT_DEFAULT_WIDTH = 512.0f;
const float SHIFT_DEFAULT_HEIGHT = 512.0f;
// const float SHIFT_DEFAULT_WIDTH = 512.0f;
// const float SHIFT_DEFAULT_HEIGHT = 512.0f;

const float SHIFT_DEFAULT_WIDTH = 1024.0f;
const float SHIFT_DEFAULT_HEIGHT = 1024.0f;
1 change: 0 additions & 1 deletion shaders/examples/fluidSim/quad_advect_fs.sc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $input v2f_texCoord0
#include "../../utils/bgfx_compute.sh"
#include "velocity_uniforms.sh"

#define bufferSize 512

BUFFER_RO(_isFluid, float, 0);
BUFFER_RO(_curVelX, float, 1);
Expand Down
1 change: 0 additions & 1 deletion shaders/examples/fluidSim/quad_divergence_fs.sc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $input v2f_texCoord0
#include "../../utils/bgfx_compute.sh"
#include "velocity_uniforms.sh"

#define bufferSize 512

BUFFER_RO(_divergence, float, 0);
BUFFER_RO(_isFluid, float, 1);
Expand Down
1 change: 0 additions & 1 deletion shaders/examples/fluidSim/quad_fs.sc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $input v2f_texCoord0
#include "../../utils/bgfx_compute.sh"
#include "velocity_uniforms.sh"

#define bufferSize 512

BUFFER_RO(_isFluid, float, 0);
BUFFER_RO(_curVelX, float, 1);
Expand Down
1 change: 0 additions & 1 deletion shaders/examples/fluidSim/quad_project_fs.sc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $input v2f_texCoord0
#include "../../utils/bgfx_compute.sh"
#include "velocity_uniforms.sh"

#define bufferSize 512

BUFFER_RO(_isFluid, float, 0);
BUFFER_RO(_curVelX, float, 1);
Expand Down
3 changes: 2 additions & 1 deletion shaders/examples/fluidSim/velocity_project_cs.sc
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ void main() {
/* Debug of the correction value */
// multiple 1.95 is call overrelaxtion
//float correction = 1.9 * divergence / neighboursNum;
float correction = 1.3 * divergence / neighboursNum;
//float correction = 0.1 * divergence / neighboursNum;
float correction = divergence / neighboursNum;
//float correction = divergence / neighboursNum;

// divergence > 0, too much outflow, less out, more in
// divergence < 0, too much inflow, less in, more out
Expand Down
2 changes: 2 additions & 0 deletions shaders/examples/fluidSim/velocity_uniforms.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ uniform vec4 uParams[5];
#define uOffsetY uParams[3].y
#define uDivOffsetZ uParams[3].z

#define bufferSize 1024

#define speedDeltaTime (uDeltaTime * uSpeed)

uint LEFT(uint idx) {
Expand Down

0 comments on commit 76d6201

Please sign in to comment.