This project visualizes BFS-based flowfields using WebGPU in the browser. It features interactive obstacle editing, distance field and flowfield visualization, and supports loading mazes from CSV files.
- WebGPU-powered grid rendering and compute shaders (see
src/shaders/) - Interactive obstacle and goal placement
- Distance and flowfield visualization (see
src/js/renderers/) - Hilbert curve maze generation and noise-based maze creation (see
src/python/hilbert.ipynb) - CSV import/export for grid data (see
public/maze.csvandsrc/assets/maze.csv) - Python scripts for LUT analysis and maze generation (
src/python/) - Modular JavaScript code for simulation, rendering, and WebGPU setup (
src/js/)
This project supports two BFS variants for distance field computation:
- BFS without relaxation: Classic BFS. Each cell is filled once and never updated again. This is optimal and fast when all terrain costs are equal (e.g., every cell costs 1 to enter).
- BFS with relaxation: Each cell can be updated if a shorter path is found later ("relaxation step"). This is necessary when terrain costs vary (e.g., difficult terrain or shortcuts), ensuring the true lowest-cost path is found. This approach is similar to Dijkstra's or Bellman-Ford algorithms.
Summary:
- If all terrain costs are the same: both BFS variants produce the same result.
- If terrain costs vary: use relaxation to get correct shortest paths.
See src/shaders/BFS.wgsl (with relaxation) and src/shaders/BFSNoRelaxation.wgsl (without relaxation) for implementation details.
For a more in-depth explanation, see BFS Relaxation Explanation.
src/js/— Main JavaScript source codePathfindingSimulation.js— Core simulation logicinitWebGPU.js,importShaders.js,buffers.js,bindGroup.js,pipelines.js— WebGPU setup and managementrenderers/— Canvas renderers for obstacles, distance field, and flowfieldutil.js,setupCanvases.js— Utility and setup helpers
assets/— Images and CSV files for mazes and texturesshaders/— WGSL compute shaders for BFS, flowfield, and grid operationsstyle.css— Main stylesheetpython/— Python scripts and Jupyter notebook for maze/noise generation and LUT analysis
public/— Static files (e.g.,maze.csv)server.js— Optional Node.js server for local hostingvite.config.js— Vite configurationpackage.json— Project dependencies and scriptsdist/— Production build output (ignored by git)
-
Install dependencies:
npm install
-
Run the development server:
npm run dev
-
Build for production:
npm run build
-
Preview production build:
npm run preview
- Maze and noise generation:
src/python/hilbert.ipynb - LUT analysis and creation:
src/python/LUTAnalyzer.py,src/python/LUTMaker.py - Output loading:
src/python/loadOutput.py
- BFS and distance field:
src/shaders/BFS.wgsl,src/shaders/BFSNoRelaxation.wgsl,src/shaders/distanceGrid.wgsl - Flowfield and gradient:
src/shaders/flowfield.wgsl,src/shaders/gradient.wgsl - Obstacle grid:
src/shaders/obstacleGrid.wgsl
See LICENSE.