bigwheels icon indicating copy to clipboard operation
bigwheels copied to clipboard

Fluid simulation - Initial implementation

Open dnovillo opened this issue 2 years ago • 0 comments

This is a BigWheels adaptation of the original WebGL implementation at https://github.com/PavelDoGreat/WebGL-Fluid-Simulation..

This initial implementation only implements the following:

  • All the original WebGL shaders have been translated to HLSL.
  • The simulation stops after generating the initial splash of color.

The code is organized in 3 files:

sim.cpp Contains the main simulation logic. Everything is driven by class FluidSimulation. Simulation actions generate dispatch records (ComputeDispatchRecord, GraphicsDispatchRecord), which describe the shader to execute and its inputs. Dispatch records are scheduled for execution using FluidSimulation::ScheduleDR. Most of this code resembles the original JavaScript implementation (https://github.com/PavelDoGreat/WebGL-Fluid-Simulation/blob/master/script.js)

shaders.cpp Contains most the logic required to interact with the BigWheels API to setup and dispatch compute and graphic shaders. Compute and graphic shaders all inherit from a common class Shader. The main method in those classes is GetDR(), which generates a dispatch record with all the necessary inputs to execute the shader (textures to use and scalar inputs in struct ScalarInput.

main.cpp Contains the BigWheels API calls needed to launch the application and execute the main rendering loop. On startup, a single instance of class FluidSimulation is created and an initial splash of color computed by calling FluidSimulation::GenerateInitialSplat. The main rendering loop (see ProjApp::Render) proceeds as follows:

 1.  All the scheduled compute shaders are executed by calling `FluidSimulation::DispatchComputeShaders`.
 2.  All the generated textures are drawn by calling `FluidSimulation::DispatchGraphicShaders`.
 3.  The resources used by compute shaders are released by calling `FluidSimulation::FreeComputeShaders`.
     This prevents running out of pool resources and needlessly executing compute operations over and over.
 4.  The next iteration of the simulation is executed (NOTE: This is still not implemented).

Thanks to @chaoticbob for helping me with a bunch of the basics needed to get this initial version going.

dnovillo avatar Nov 30 '22 14:11 dnovillo