Capillary ink-bleed scene dissolve
I wanted to know if one ElementGL WebGL 2 canvas could pour dark ink across a cream paper notebook from wherever you tap, letting pigment race along paper fibres and DOM luminance edges before revealing a live midnight obsidian studio underneath. Tap open paper or slate to pour from that point, edit either field, or drag Scrub % to inspect the wet rim.
Starting canvas…
Show the code two drawable scenes, capillary FBM shader, tMs envelope, geometry sync and 2D fallback
- Two contrasting live scenes in one canvas. Both
#ib-scene-aand#ib-scene-bsit inside one<canvas content="drawable" layoutsubtree>, withinertdisabling the inactive layer. - Capillary ink-bleed fragment shader. Combines radial distance from
uOriginwith domain-warped FBM paper permeability, DOM luminance edges, a damp moisture fringe and a dark wet pigment rim. - Explicit
tMstransition envelope. AdvanceslaunchBleed()andstepBleed()from explicit timestamps and snaps immediately when reduced motion is active. - Gated
ElementGLupload path. Waits forhasPaintedinsidepaintand callsstage.begin()beforestage.upload()withUNPACK_PREMULTIPLY_ALPHA_WEBGLenabled. - Hit-box sync with
geometryUnit(). Flipsinertandpointer-eventscleanly, calibrates transforms viaupdateElementGeometry()and togglesdata-hit-tick. - Five-argument 2D radial mask and plain-HTML fallbacks. Clips an organic ink pool in 2D using five-argument
drawElementImage()or moves both scenes into#plain-hoston context loss.
How it works
Both #ib-scene-a and #ib-scene-b sit inside a single <canvas content="drawable" layoutsubtree> backed by one ElementGL WebGL 2 context. At creation and inside onRestored, the context sets gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true) so crisp serif ink, input carets and cyan borders upload cleanly via gl.texElementSubImage2D(). Uploads are gated on hasPainted inside the paint handler, calling stage.begin() before stage.upload().
When you tap open paper or slate (or press Pour ink), launchBleed() records the normalised tap origin (ox, oy) and advances the bleed front over 1,350 ms using stepBleed(bleed, tMs). In the fragment shader, Euclidean radial distance from uOrigin is warped by four-octave domain-warped FBM paper fibres plus perpendicular weave channels. A five-tap sample of the outgoing DOM texture adds luminance and edge magnitude so ink spreads slightly faster across bright open margins and wicks along printed borders.
Along the advancing boundary, an outer moisture band dampens the outgoing paper, followed by a dark sumi-indigo wet pigment crest (rgb(2, 3, 5)) that reads darker than both cream rag paper and the midnight obsidian slate before revealing crisp Scene B controls inside. While mid-transition, both scenes are marked inert so partial controls don't steal taps. Once settled at 0% or 100%, syncSceneGeometry() calibrates transforms with geometryUnit(), calls canvas.updateElementGeometry() and toggles data-hit-tick to clear Chromium's hit-test cache.
Scrolling vertically over the stage works by touch via touch-action: pan-y, while selectstart is cancelled outside <input> elements so taps don't select page labels. Animation pauses off screen via IntersectionObserver and when document.hidden is true. Under prefers-reduced-motion: reduce (or the Reduced motion checkbox), pours snap straight to the destination view. Without WebGL 2, a 2D context clips an organic radial mask using five-argument drawElementImage(), and context loss moves both scenes into #plain-host.
Live checks
Checks wait for a tap so the demo opens with one WebGL context. Each check builds an isolated fixture on testStage() and retires its canvas afterwards.
Findings
- Measured in HeadlessChrome 160 (2026-11-27, 412 px wide, 2.625 DPR): all six live checks pass with
0errors,scrollWidth === 412,1.16 MPcanvas backing store,9.29 MBmemory,0open snapshots and0wrong-size 2D draws. Not verified yet:npm run check:jank -- /ink-bleed/in Chromium 157 and real touch hardware on Chrome 159 for Android. - Using
uInvertinside the shader to swap source and destination textures keeps0%mapped to Scene A and100%mapped to Scene B while letting reverse pours (B -> A) still spread outward from the tapped point instead of collapsing inward like an iris. - Making the wet pigment rim nearly black sumi-indigo (
vec3(0.008, 0.012, 0.020)) against a deep navy-obsidian studio base (#111b2b) keeps the advancing capillary contour visibly darker than both scenes (measured minimum rim luminance9.9vs242.2on paper and35.0on obsidian).