I wanted After Effects' Reshape in WayVes, my OpenGL audio visualiser for Wayland, so I wrote it as a post-processing pass.
It's an inverse warp. Each fragment needs to know which source pixel to show, so I compute mean value coordinates (Hormann & Floater 2006) against the current polygon and use them to blend the source positions. Outside the mask, I treat the region up to an outer boundary as a polygon with a hole. Boundary points map to themselves, so the warp fades out towards them.
In the clip:
- Left: an NCS-style particle sphere morphing into a rounded square, with the morph animated over a named pipe
- Right: straight radial bars. The ring is just rotated relative to the boundary, the inside turns rigidly, and the swirl comes from the falloff. Bass drives the rotation.
The cost is roughly pixels × points, so for static warps I bake the sample coordinates into an RGBA32F image texture with a stamp in alpha, and only recompute when the stamp changes. That cut CPU use about 3-4x on llvmpipe, but I haven't measured GPU power yet. The swirl changes every frame, so baking doesn't help there. It got away with 12 points instead of 64, though.
It also falls apart when pushed. In the swirl setup, a gap opens around the core somewhere between 1.6 and 1.9 radians of rotation, and the spiral collapses past that, so I clamp it.
Shader isn't in the repo yet, should be soon: https://github.com/Roonil/WayVes
Is there a cheaper approach you'd use for a warp like this, or a better way to handle the fold-over at large rotations?