Pepper's Ghost pyramid
I wanted to find out if one live interactive HTML telemetry card could drive both an orbitable 3D virtual glass pyramid chamber and a pitch-black 4-way smartphone Pepper's Ghost acrylic projector while staying clickable and editable in both modes. Drag the glass chamber to orbit 360 degrees around the floating hologram, click its buttons or type straight into its text field, then switch to Phone pyramid projector if you want to set a clear plastic pyramid on your phone screen.
Drag glass to orbit 360 deg · click or type inside the floating hologram
Show the code glowing transparent card, 3D Fresnel glass and hologram shaders, 4-quadrant projector layout, projective hit sync and render loop
- The glowing transparent source card. A high-contrast telemetry panel sits on a transparent background inside
<canvas content="drawable" layoutsubtree>, carrying a live<input>, phosphor colour buttons, a 1 Hz waveform readout and a+1 Signaltrigger. - The 3D Fresnel acrylic pyramid and translucent hologram shaders. Draws the dark museum pedestal, bevelled 45-degree acrylic frustum faces with Fresnel specular edge light-piping, optional optical beams and the floating translucent hologram with soft halo glow.
- The 4-way smartphone Pepper's Ghost projector layout. Computes four non-overlapping radial affine matrices (0, 90, 180 and 270 degrees) around the adjustable central apex void with optional mirror flip, feeding both
ElementGL.quad()and hit-testing from the same transforms. - Projective 3D and 4-face hit reprojection. Projects the active floating hologram plane through
M_ndcToCss * VP * M_elemToWorldin 3D chamber mode (or switches to the hovered quadrant matrix in Phone Pyramid mode), scales bygeometryUnit(), callscanvas.updateElementGeometry()and togglescard.dataset.hitTick. - One ElementGL WebGL 2 context, mipmap upload and recovery. Uploads
#ghost-cardviagl.texElementSubImage2D(), builds mipmaps, sorts back and front glass faces around the hologram, pauses off screen withIntersectionObserverand moves the card into plain HTML ifwebglcontextlostfires.
How it works
John Henry Pepper demonstrated Henry Dircks's stage illusion in 1862 by angling a sheet of clear glass at 45 degrees so a bright subject lit below the stage reflected as a translucent figure floating in mid-air.
The DIY smartphone version repeats that geometry on all four sides: an inverted truncated acrylic pyramid rests tip-down on a pitch-black screen surrounded by four mirrored copies of the subject at 0, 90, 180 and 270 degrees.
I wanted to test whether one live HTML card drawn by texElementSubImage2D() could serve both as the glowing 4-way screen source for a physical plastic pyramid and as the interactive floating virtual image inside a 3D glass chamber.
One ElementGL instance from /lib/element-gl.js owns the page's single WebGL 2 context (keeping GPU memory well below the 4 megapixel and 96 MB mobile canvas limits).
The source card (#ghost-card) uses background: transparent with high-contrast luminous borders and monospace text so unlit pixels stay pure black on an OLED phone screen and don't wash out a real acrylic reflection.
Whenever you type in the input, switch phosphor colour, tap +1 Signal or wait for the 1 Hz telemetry tick, Chromium fires a paint event on the canvas and stage.upload(card) copies the updated picture via gl.texElementSubImage2D() followed by gl.generateMipmap(gl.TEXTURE_2D).
In 3D virtual glass pyramid mode, companion WebGL 2 shaders on stage.gl draw the dark museum pedestal and recessed screen well, paint the four mirrored live HTML projections flat on the display floor, draw the rear 45-degree acrylic faces behind the centre, draw the floating translucent live HTML hologram in mid-air inside the frustum, and then draw the front acrylic faces on top with Schlick Fresnel reflections and bevelled edge light-piping.
As you orbit 360 degrees around the pyramid, the floating hologram sits on the true vertical virtual-image plane of whichever 45-degree wall faces you, crossfading smoothly to the neighbouring face near each 45-degree corner rib.
Because the floor quadrant coordinates match the exact 45-degree optical projection of the floating hologram height, every keystroke or phosphor switch updates the four base projections and the suspended hologram together in one frame.
In Phone pyramid projector mode, the canvas clears to pure rgb(0, 0, 0) and draws the four copies with stage.quad() around a centred pitch-black apex cutout (adjustable from 20 to 80 CSS px).
Because one reflection off a 45-degree glass pane reverses left and right, Mirror flip defaults to on so text reads left-to-right when viewed through a physical acrylic pyramid; unchecking it flips the four quadrants back to direct screen-readable orientation.
Calibration crosshairs draw thin alignment lines along the 45-degree diagonals and around the perimeter of the apex cutout without painting inside the central black void.
Fullscreen centres a square pitch-black projection canvas so a physical pyramid sits cleanly in the middle of the screen without bloating the backing store on large monitors.
WebGL draws don't move Chromium's DOM hit-test box on their own.
In 3D chamber mode, the script builds the exact 4 by 4 projective DOMMatrix M_ndcToCss * VP * M_elemToWorld for the active floating hologram plane, scales it by geometryUnit() from /lib/surface.js so high-DPI screens stay aligned, calls canvas.updateElementGeometry(card, { canvasTransform }) and bumps card.dataset.hitTick to clear Chromium's hit-test cache.
In Phone pyramid mode, moving or tapping the pointer over any of the four rotated, mirrored faces moves updateElementGeometry() onto that exact face's affine matrix so you can click buttons or focus the text input on any quadrant.
An IntersectionObserver stops the 1 Hz telemetry timer and any auto-orbit loop when the stage leaves the viewport.
If WebGL 2 isn't available, a 2D canvas fallback draws both views with five-argument drawElementImage() calls; if HTML-in-canvas is missing or webglcontextlost fires, #ghost-card moves out of the canvas into plain HTML until the browser restores the context.
Live checks
These checks wait for a tap so the demo opens with one WebGL 2 context. Each check creates its own isolated fixture on the test stage and retires its canvas when done.
Findings
- Not verified in a live browser yet: none of the live checks, visual modes or physical acrylic pyramid reflections have been run in Chromium 157 or Chrome 159 for Android. Open this page with HTML-in-canvas enabled and tap Run above to record results on your device.
- Placing the four floor projections radially from
r_in = r0 + (y_bot - y0)tor_out = r0 + (y_top - y0)makes the floating hologram width clear the 45-degree glass walls at its bottom corners while keeping all four floor quadrants non-overlapping with 1:1 reflection geometry. - Each real 45-degree mirror reflection flips handedness once, so mirroring each quadrant horizontally in its radial frame makes text such as
GHOST 1862read left-to-right inside an inverted acrylic pyramid while still allowing 2D affineupdateElementGeometry()hit-testing on all four quadrants. - Sorting the four acrylic frustum walls into back faces (drawn before the floating hologram) and front faces (drawn after it) prevents depth-buffer clipping of the glass enclosing the hologram from every 360-degree orbit angle on a single
ElementGLcontext. - Hiding the on-canvas hint pill in Phone pyramid projector mode and drawing calibration crosshairs only outside the apex cutout square keeps stray UI chrome from reflecting as double-vision ghosts inside a real acrylic pyramid.