How seblague/fluid-sim works
Main Components
• Simulation Engine:
• This is largely found under the Assets/Scripts/Simulation and Assets/Scripts/Sim2D directories. It contains compute shaders (HLSL files), computation logic (FluidSim.compute, FluidMaths3D.hlsl, FluidSim2D.compute, etc.) and classes such as FluidSim.cs and FluidSim2D.cs. These manage the actual fluid behavior simulation.
• Rendering Pipeline:
• Helper Utilities:
• The Assets/Scripts/Helpers folder contains utilities like ComputeHelper, GPU Sort (including count sort and scan mechanisms), and Spatial Hash (with modules for both 2D and 3D). These libraries underpin both simulation and rendering processes for performance and organization.
• Demo and Scene Integration:
• The Assets/Scenes directory holds multiple Unity scene files that illustrate different simulation and rendering setups. This is where the user interacts with the simulation (selecting a demo scene like Fluid MarchingCubes or Fluid Particles) and ties together all components.
• Unity Core & Project Framework:
• The standard Unity project structure (including ProjectSettings, Packages, and Assets) indicates that these systems are integrated into Unity’s game loop, messaging, and rendering pipeline.
Relationships and Data Flow
• User/Scene Level:
• At the highest level, Unity scenes (from Assets/Scenes) are the entry points. They instantiate and drive the simulation and rendering components.
• Simulation Flow:
• Spawner components (e.g., Spawner2D.cs, Spawner3D.cs) initiate the fluid simulation. The simulation engine computes fluid dynamics using compute shaders and simulation mathematics.
• Data processing modules (using GPU sorts, spatial hashing) supply optimized, preprocessed data for visualization.
• Rendering Flow:
• The rendering subsystem takes the simulation output and converts it into visual geometry or effects. Different rendering components (e.g., marching cubes for fluid surfaces, screen space shaders for particle thickness and depth smoothing, raymarching for volumetric effects) process this data.
• Helper Interaction:
• Helper utilities act as shared libraries used by both the simulation engine and the rendering pipeline to optimize processing, manage data structures, and perform GPU computations.
• Integration:
Architectural Patterns
• Modular Design:
• Data-Driven & Compute-Intensive:
• With multiple compute shader integrations, it is important to show how compute tasks (like sorting and spatial hashing) support both simulation and rendering.
• Integration with Unity:
• That the entire system is integrated into Unity’s architecture – scenes set up the testing environments that instantiate simulation and rendering components, linking them via Unity’s MonoBehaviour scripts.
Final Advice
• Component is labeled with its corresponding folder or script names where applicable, making it easier to trace in the directory structure.
• Directional data flows so that it’s evident how an event starting in a scene cascades into simulation updates and finally into rendered output.