Vertex Shader Domain Warping with Automatic Differentiation
Dave Pagurek van Mossel
TL;DR
Problem: 3D domain warping in WebGL is hindered by baked vertex normals that cease to align after warping, and normal updates via finite differences require tuning. Approach: derive an exact normal-update using the warp Jacobian $J$ and a local tangent frame to obtain $n' = \text{normalize}((u+Ju) \times (v+Jv))$, with $f$ differentiable, and generate GLSL that computes $f$ and $J$ at compile time via forward-mode AD. Contributions: a shader-generation pipeline (p5.warp) that outputs $f$ and $J$ in GLSL without requiring GLSL coding from artists, and validation on multiple meshes with correct lighting. Significance: enables robust, parameter-free 3D domain warping in web environments and sets the stage for WebGPU-based pipelines and future enhancements like adaptive subdivision and more intuitive warp-function control.
Abstract
Domain warping is a technique commonly used in creative coding to distort graphics and add visual interest to a work. The approach has the potential to be used in 3D art as mesh vertices can be efficiently warped using a vertex shader in a WebGL pipeline. However, 3D models packaged for the web typically come with baked-in normal vectors, and these need to be updated when vertex positions change for lighting calculations to work. This is typically done via finite differences, which requires parameter tuning to achieve optimal visual fidelity. We present a method for 3D domain warping that works with automatic differentiation, allowing exact normals to be used without any tuning while still benefiting from hardware acceleration.
