跳到正文
网页珍奇柜Web Curio

WebGPU 流体海洋

WebGPU-Ocean,matsuoka-601,2024 年

正在布展…

本柜的现场复刻:按原作的技术思路从零编写,不含原作的代码和素材。为什么不直接展出原作:原作只能在支持 WebGPU 的浏览器里运行;为了让它长期可用,本柜用 WebGL 从零复刻。原作请点上方「去看原作」。

它是怎么做的

  1. 第 1 步MLS-MPM:粒子到网格(P2G)、网格更新、网格到粒子(G2P)全部在计算着色器中
  2. 第 2 步屏幕空间流体渲染:渲染粒子深度 → 双边滤波平滑 → 重建法线
  3. 第 3 步根据厚度缓冲计算吸收颜色与折射
  4. 第 4 步盒子尺寸可动态改变,制造波浪

复刻配方

一段技术配方,可以直接交给 AI 编程助手,也可以自己照着写。想指定技术栈、位置和性能预算,就把它加入实现方案。

Implement a particle-based fluid in WebGPU compute shaders using the MLS-MPM loop: scatter particle mass and momentum to a grid with atomics, update grid velocities with gravity and boundary conditions, then gather back to particles. Render particles as sphere sprites into a depth texture, smooth it with a separable bilateral filter, and reconstruct normals from the smoothed depth. Also render additive thickness and use it for Beer-Lambert absorption while refracting the background by the normal. Let the user resize the container walls over time to slosh the water.

档案

技术

能不能拿来用

原作以 MIT 许可开源:可以阅读源码学习,按许可证条款使用;在自己的项目里引用时保留原作者署名。

性能开销

视觉强度

实现难度

尺度为策展判断(1 到 5),用于比较和推荐。

核实记录:Demo loads (200, requires WebGPU); repo has MIT licence.