Submerged page

I wanted to know if a live HTML form stays readable and clickable beneath a 2D wave-equation water surface with Snell refraction, optical caustics and a movable shoreline meniscus, without reading pixels back from the GPU or breaking touch scroll. Tap or drag on the water, type in the log box, slide the waterline from dry to submerged, and try the buttons underwater.

North Sea Gauge ยท Live HTML Form Tide Station 04
+2.44 m
Station online

 

Show the code shallow-water PDE, Snell refraction and Jacobian caustics shader, ElementGL paint and hit-test offset
  1. One drawable form in one canvas. The live tide-station form sits inside a single <canvas content="drawable" layoutsubtree>.
  2. 2D shallow-water heightfield PDE. A 128 by 128 typed-array wave grid steps on the CPU with aspect-corrected Laplacian weights and packs height and gradients into an RGBA8 texture.
  3. Snell refraction, Jacobian caustics and meniscus. The WebGL 2 fragment shader bends R, G and B through the water normal map, computes 1 / det(J) caustics across the live HTML texture and splits dry from wet at the undulating shoreline.
  4. Single-context paint and geometry sync. ElementGL uploads the DOM texture only when the form changes, uploads the 64 KB water texture each frame and keeps hit boxes synced with updateElementGeometry().

How it works

The entire tide-station form sits as one drawable child inside one WebGL 2 canvas managed by ElementGL from /lib/element-gl.js. Inside the paint handler, stage.upload() calls gl.texElementSubImage2D() only when the form changes (typing, toggling a checkbox, moving a slider, focus or resize). While ripples animate across calm DOM, the element texture stays on the GPU with zero re-uploads and zero readback.

The water surface is a 128 by 128 2D damped wave equation in WaterField. I ran the PDE on Float32Array buffers on the CPU and packed height, dh/dx, dh/dy and curvature into one 64 KB RGBA8 texture uploaded with gl.texSubImage2D() each frame. That avoids floating-point framebuffer extensions that can fail on mobile GPUs, gives hardware bilinear filtering everywhere, and lets JavaScript read the exact surface gradient under the pointer with zero GPU readback.

In the fragment shader, the shoreline height undulates with the live wave field. Above the waterline the form renders unrefracted. Below it, the shader computes a surface normal from the heightfield gradient plus subtle capillary ripples, refracts the view ray with Snell's law (n = 1.333) and slight RGB dispersion, and takes finite differences of the refracted UV map to form its 2 by 2 Jacobian determinant det(J). Where wave crests converge rays (det(J) < 1), light scales up as 1 / det(J) to project bright optical caustics straight over the live HTML text and controls.

Standard updateElementGeometry() leaves the form's hit box at its unrefracted CSS coordinates. Turning on Refraction hit-test offset evaluates the local Snell displacement at the pointer from the CPU heightfield and translates the element's canvasTransform matrix (toggling dataset.hitTick to clear Chromium's hit-test cache) so the control under the pointer tracks its refracted image. The stage keeps touch-action: pan-y and uses passive pointer listeners so vertical swipes on a phone scroll the page normally while taps reach the underwater controls. An IntersectionObserver pauses the simulation loop when the stage scrolls off screen.

Live checks

These run on their own small fixtures in the corner of the window and leave the demo above untouched.

Findings