How dblsai/webgl-fluid works
Main components
• User Interface & Input Handler – Represent the HTML layer (index.html) that initializes the WebGL canvas, and input devices (mouse clicks, wheel for zoom, etc.) to drive interactions.
• WebGL Rendering Engine – Include the core simulation engine (main.js, tracer.js, webgl-utils.js) that sets up the WebGL context, handles the rendering loop, and orchestrates the shader pipeline.
– Height Map Shader: Adjusts vertex heights based on inputs (mouse, object interaction).
– Normal Map Shader: Computes the water surface normals.
– Step Simulation Shader: Propagates the wave and attenuates the simulation.
– Additional shaders for computing raytraced reflection/refraction, caustics, god rays, and shadows.
• Asset Management and 3D Object Loading – Show the inclusion of external libraries (like Three.js with its OBJ loader and additional modules in the threejs folder) that load and render OBJ files from the objs directory.
• Utility Libraries – Represent supporting libraries (for instance, glMatrix-0.9.5.js for matrix operations, primitives.js for geometric primitives) and external assets like shaders and WebGL extensions.
Relationships and Data Flow
• Rendering Engine to the Shader Pipeline blocks. Illustrate that raw simulation data flows into the Height Map Shader, then cascades into the Normal Map and Step Simulation shaders.
• That the outputs of the simulation shaders are used by the final water mesh shader in the rendering process.
• That the Asset Management module (powered by Three.js loaders) feeds 3D object data into the scene and then interacts with water simulation (for example, the OBJ interaction effects).
• Feedback loops where simulation outputs (like caustics, reflections, and refractions) are rendered back to the texture map and influence subsequent simulation frames.
Architectural Patterns and Design Principles
• Separation of concerns: the project divides its responsibilities between user interaction handling, real-time simulation, and asset loading.
• Mention the use of shader-based computation: this is a classic application of GPGPU techniques applied to fluid dynamics and rendering (e.g., using offscreen textures for simulation data).
• Integration of third-party libraries (Three.js, glMatrix) which abstract common tasks in 3D mathematics and object handling.
Adding Details
– The simulation process: a step-by-step view from user inputs, shader computations, texture updates, and final water rendering.
– The object interaction pipeline: showing how OBJ files from the objs folder are loaded via Three.js, then interact with the water simulation (e.g., through bounding sphere interactions and reflection/refraction modes).