PavelDoGreat / WebGL-Fluid-Simulation

Play with fluids in your browser (works even on mobile)
https://paveldogreat.github.io/WebGL-Fluid-Simulation/
MIT License
14.67k stars 1.68k forks source link

Does this simulation implement the boundary conditions described in GPUGems? #81

Open spencerkohan opened 2 years ago

spencerkohan commented 2 years ago

Hi @PavelDoGreat, thanks for sharing the code, this is an amazing implementation.

I'm trying to translate this to compute shaders as a way of learning more about compute and also Vulkan. I've gotten pretty far, but my simulation doesn't seem to behave correctly at the boundaries, as yours does.

Reading through GPU gems, it looks like there should be a special case on the boundaries for both velocity and pressure. It looks like somehow you're handling this in your divergence shader with this segment:

        if (vL.x < 0.0) { L = -C.x; }
        if (vR.x > 1.0) { R = -C.x; }
        if (vT.y > 1.0) { T = -C.y; }
        if (vB.y < 0.0) { B = -C.y; }

But my question is, do you account for the boundary conditions in any other way, or should this be sufficient?

Best, Spencer

PavelDoGreat commented 2 years ago

@spencerkohan Hey. I know little about compute shaders at the moment. I may assume that compute shaders doesn't do texture boundary checks as fragment shaders do. In my simulation when I initialize textures and framebuffers, I set parameter CLAMP_TO_EDGE, which clamps texture accessing coordinate in fragment shader to 0-1.