跳到正文
网页珍奇柜Web Curio

实时编程光线步进

marching.js,Charlie Roberts,2018 年

正在布展…

原作直展:这是 Charlie Roberts 的原始作品,按 MIT(本地打包 gif.js 为 MIT、p5.js 为 LGPL-2.1、hydra-synth 为 AGPL-3.0,均为原版文件) 许可证收录(版本 6e09f02)。收录线上同款 playground,把运行时从 CDN 加载的 gif.js、p5、hydra 换成本地同版本文件,并去掉了内联 source map。选中代码按 Ctrl+Enter 运行,右上角菜单有几十个示例;dwitter 贴图与 GIF 下载在沙箱里不可用。 许可证全文 · 收录说明

它是怎么做的

  1. 第 1 步JS 对象树描述 SDF 图元与布尔/平滑并集操作
  2. 第 2 步库把对象树编译为 GLSL 距离函数并插入光线步进模板
  3. 第 3 步支持 FFT 输入,把音频能量绑定到参数
  4. 第 4 步Playground 内置编辑器,Ctrl+Enter 即时重编译

复刻配方

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

Define a tiny JS DSL where each primitive (sphere, box, torus) and operator (union, smooth union, repeat, twist) is an object that can emit a GLSL expression string. Walk the object tree to generate a map(p) distance function and insert it into a standard sphere-tracing fragment shader with normal estimation and soft shadows. Expose uniforms for any numeric parameter so they can be animated from JS or driven by WebAudio analyser bands without recompiling. Put a code editor beside the canvas and re-evaluate on a keyboard shortcut.

档案

能不能拿来用

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

性能开销

视觉强度

实现难度

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

核实记录:Playground loads (200); repo has MIT licence.