Mirror-cylinder anamorphosis

I wanted to know if I could smear a live HTML form into an unreadable 17th-century polar catoptric print on a tabletop, un-warp it optically inside a movable 3D chrome cylinder, and keep its input and buttons clickable right inside the curved reflection with updateElementGeometry(). Type inside the mirror, tap the colour buttons or +1 Stamp, drag the cylinder cap off the brass focal ring to watch the reflection break apart, or lift the mirror away to inspect the smeared polar print on the table.

NICERON 1638 Catoptric reflection · cobalt
#00
12 chars · 0 stamps 5px test grid

Click or tap inside the chrome reflection · drag cylinder cap to slide · drag table to orbit

View
Mirror
Interact on
Starting WebGL 2 catoptric stage...
Show the code live HTML card, Alhazen catoptric solver, 3D cylinder raytracer, mipmaps and hit reprojection
  1. The live HTML form card. One 320 by 200 px drawable element inside the canvas holds the text input, three colour buttons, the +1 Stamp counter, an optical ruler strip and a 5 px calibration grid.
  2. Inverting the catoptric print with Alhazen's solver. Solves the circular mirror reflection angle on the tabletop plane in six Newton steps and computes the closed-form 2 by 2 Jacobian d(uv)/dQ so every reflected ray maps cleanly back to card UV space.
  3. Raytracing the movable 3D chrome cylinder and tabletop. Intersects the camera ray with the movable cylinder cap, curved mirror wall and tabletop plane, propagates curved-surface ray differentials for textureGrad() and shades the mirror with Fresnel rim lighting and studio softboxes.
  4. Uploading with texElementSubImage2D(), mipmaps and anisotropy. Uploads the card through ElementGL.upload(), calls gl.generateMipmap(gl.TEXTURE_2D) and enables max EXT_texture_filter_anisotropic so both the oblique tabletop smear and the reflection stay sharp.
  5. Local-Jacobian hit reprojection onto the curved reflection. Traces the pointer ray on the CPU off the chrome cylinder or onto the polar tabletop, inverts the analytic 2 by 2 Jacobian dq/dp into a tangent DOMMatrix scaled by geometryUnit(), and calls canvas.updateElementGeometry() plus card.dataset.hitTick.

How it works

In 1638 Jean-Francois Niceron published drawings of cylindrical catoptric anamorphoses: distorted polar prints that look unreadable flat on a table until you place a polished metal cylinder on the marked circle and view the reflection from the right angle. I built this experiment to test that optical inversion on a live HTML form rendered with texElementSubImage2D(), and to check whether dynamic local-Jacobian updateElementGeometry() reprojection keeps inputs and buttons clickable inside a raytraced curved mirror.

One ElementGL instance from /lib/element-gl.js owns the page's single WebGL 2 context. When #catoptric-card paints, stage.upload(card) copies its current picture into an RGBA8 texture with gl.texElementSubImage2D(), then calls gl.generateMipmap(gl.TEXTURE_2D) and sets LINEAR_MIPMAP_LINEAR plus max EXT_texture_filter_anisotropic when the driver exposes it. A full-stage fragment shader raytraces the gallery tabletop (y = 0), an inlaid brass focal circle of radius 0.94 at the origin, and the movable chrome cylinder (radius 0.94, height 1.62) standing at (cylX, cylLift, cylZ).

To paint the polar anamorphic print on the tabletop, the shader takes any table point Q = (qx, qz) outside the focal circle and solves Alhazen's circular mirror problem relative to the gallery reference viewpoint (elevation 41 deg, distance 8.4): it finds the unique angle theta on the focal circle where the incidence and reflection angles match, in six Newton steps. From theta, the horizontal path lengths give the virtual reflection height y = Y0 * d2 / (d1 + d2), and mapping (sin(theta), y) onto [0, 1] x [0, 1] produces a 201-degree polar horseshoe print around the cylinder base. When a camera ray strikes the chrome cylinder standing on the focal circle, the shader reflects the ray downward onto y = 0 and calls the same tabletop function. The polar smear cancels out to floating-point precision, so the live HTML card snaps upright and readable on the curved metal face. Slide the cylinder off the brass circle and the reflected rays hit the wrong part of the print, tearing the reflection apart until you slide it back.

Rather than relying on screen-space dFdx() across the cylinder silhouette (where 2 by 2 pixel quads mix cylinder and tabletop hits), the shader propagates analytic ray differentials off the curved cylinder normal and multiplies by the closed-form 2 by 2 Jacobian d(uv)/dQ to call textureGrad() with one Alhazen solve per pixel. The CPU hit-tester runs the same 3D raytrace and analytic Jacobian under your pointer, inverts dq/dp into a local card-to-canvas tangent DOMMatrix, scales it with geometryUnit() from /lib/surface.js, and updates canvas.updateElementGeometry(card, { canvasTransform }) and card.dataset.hitTick. On the cylinder reflection, the Jacobian determinant is positive (upright, right-reading); on the flat polar tabletop, it's negative (top-to-bottom mirrored), and the affine matrix handles both. Tick "Show hit-box projection" to watch the cyan tangent quad hug the curved mirror or swing around the polar ring as you move across the canvas. An IntersectionObserver pauses any cylinder-lift or camera transition when the stage scrolls out of view. Without WebGL 2, a 2D fallback draws the card inside a painted cylinder using five-argument drawElementImage(); without HTML-in-canvas or after a lost WebGL context, #catoptric-card moves out into the page as plain HTML.

Live checks

These checks wait for a tap so the demo opens with one GPU context. Each check builds its own isolated fixture on the test stage and retires its canvas when finished.

Findings