Top Related Projects
Play with fluids in your browser (works even on mobile)
Fluid Particles - http://david.li/fluid
Quick Overview
GPU-Fluid-Experiments is a WebGL-based fluid simulation project that demonstrates real-time fluid dynamics in the browser. It showcases advanced graphics techniques and physics simulations, providing an interactive and visually appealing experience for users interested in computational fluid dynamics and web-based graphics programming.
Pros
- High-performance fluid simulation running in real-time on the GPU
- Interactive web-based implementation accessible through modern browsers
- Visually stunning results with customizable parameters and effects
- Educational resource for learning about fluid dynamics and WebGL programming
Cons
- May require a powerful GPU for smooth performance on high resolutions
- Limited documentation for understanding the underlying algorithms and implementation details
- Potential compatibility issues with older browsers or devices lacking WebGL support
- Not designed as a standalone library, making integration into other projects challenging
Code Examples
// Initialize the fluid simulation
const fluid = new GPUFluid(canvas, {
resolution: 512,
iterations: 16,
viscosity: 0.001,
diffusion: 0.0001
});
// Add force to the fluid
fluid.addForce(mouseX, mouseY, forceX, forceY);
// Update and render the fluid simulation
function animate() {
fluid.update();
fluid.render();
requestAnimationFrame(animate);
}
animate();
// Customize fluid appearance
fluid.setColorGradient([
{ position: 0.0, color: [0, 0, 1, 1] },
{ position: 0.5, color: [0, 1, 1, 1] },
{ position: 1.0, color: [1, 1, 1, 1] }
]);
// Add obstacles to the fluid simulation
fluid.addObstacle(x, y, radius);
Getting Started
-
Clone the repository:
git clone https://github.com/haxiomic/GPU-Fluid-Experiments.git
-
Open
index.html
in a modern web browser with WebGL support. -
Interact with the fluid simulation using your mouse or touch input.
-
Experiment with different parameters in the UI to adjust the fluid behavior and appearance.
Competitor Comparisons
Play with fluids in your browser (works even on mobile)
Pros of WebGL-Fluid-Simulation
- More interactive features, including mouse interaction and color customization
- Better performance optimization, allowing for smoother simulations on various devices
- Cleaner and more organized codebase, making it easier to understand and modify
Cons of WebGL-Fluid-Simulation
- Less physically accurate simulation compared to GPU-Fluid-Experiments
- Fewer advanced fluid dynamics features, focusing more on visual appeal than scientific accuracy
- Limited documentation and explanations of the underlying algorithms
Code Comparison
WebGL-Fluid-Simulation:
const splatStack = [];
const pointers = [];
class Pointer {
constructor() {
this.id = -1;
this.x = 0;
this.y = 0;
this.dx = 0;
this.dy = 0;
this.down = false;
this.moved = false;
this.color = [30, 0, 300];
}
}
GPU-Fluid-Experiments:
class Fluid {
public var width(default, null):Int;
public var height(default, null):Int;
public var cellSize(default, null):Float;
public var density(default, null):Float;
var velocityRenderTarget:RenderTarget2Phase;
var pressureRenderTarget:RenderTarget2Phase;
var divergenceRenderTarget:RenderTarget;
}
The code comparison shows that WebGL-Fluid-Simulation uses JavaScript and focuses on user interaction, while GPU-Fluid-Experiments uses Haxe and emphasizes fluid dynamics properties.
Fluid Particles - http://david.li/fluid
Pros of fluid
- Implements multiple fluid simulation techniques (SPH, PIC/FLIP, APIC)
- Supports both 2D and 3D simulations
- Includes a GUI for parameter adjustment and visualization
Cons of fluid
- Less focus on GPU acceleration compared to GPU-Fluid-Experiments
- May have higher computational requirements for complex simulations
- Documentation could be more comprehensive
Code Comparison
fluid:
void FluidSolver::advect(float dt) {
for (auto& particle : particles) {
particle.position += particle.velocity * dt;
}
}
GPU-Fluid-Experiments:
const advectionProgram = new GLProgram(advectionShader);
advectionProgram.bind();
gl.uniform2f(advectionProgram.uniforms.texelSize, 1.0 / simWidth, 1.0 / simHeight);
gl.uniform1i(advectionProgram.uniforms.uVelocity, velocity.read.attach(0));
gl.uniform1f(advectionProgram.uniforms.dt, dt);
gl.uniform1f(advectionProgram.uniforms.dissipation, config.VELOCITY_DISSIPATION);
blit(velocity.write);
velocity.swap();
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Cross-platform GPU fluid simulation
Demo
This repo is a little old and dusty and likely doesn't build with the latest tools, If you're looking for a version with working build instructions check out this fork: BathBombFluidDynamics by Oliver Curtis which adds some interesting effects.
I'm currently working on a rewrite so watch this space :)
If you have an idea and you want to collaborate, feel free to get in touch with me haxiomic@gmail.com
Top Related Projects
Play with fluids in your browser (works even on mobile)
Fluid Particles - http://david.li/fluid
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot