---
name: creating-photographic-prisms
description: Builds photographic prism rings with rotated background sampling and RGB separation; use for refracting photo annuli, chromatic glass effects, or reproducing the Cameron.stream homepage ring.
---

# Creating photographic prisms

You create the glass effect by resampling the photograph beneath a ring. Keep recognizable image features inside the band, displace them slightly, and separate the red, green, and blue samples. Treat the result as a graphic approximation of refraction rather than a physical optics simulation.

## Start from the visible image

1. Use an image you have permission to display. The package includes no photograph.
2. Wait for the image to decode and the layout's fonts to load.
3. Draw the image onto a scratch canvas using the same scale, crop, and position as its CSS background. For `cover`, use `max(viewportWidth/imageWidth, viewportHeight/imageHeight)`. For a percentage position, multiply the leftover space by that percentage. Handle an explicit background width separately.
4. Read the scratch canvas's RGBA pixels. Keep source pixels, ring geometry, channel offsets, and output in one coordinate system.

Do not place a rainbow gradient over the photograph and call that refraction. The displaced image detail supplies the effect. Resolve the source crop before adjusting color.

## Draw the annulus

Use `assets/photographic-prism.mjs` for the pure pixel renderer. Import `renderPrism` and pass a `Uint8ClampedArray` of RGBA source pixels, `width`, `height`, `centerX`, `centerY`, `radius`, and `bandWidth`. Write the returned bytes with `putImageData(new ImageData(output, width, height), 0, 0)` onto a transparent canvas above the photograph and below the text.

The renderer defaults to a desktop channel shift of 4 pixels. To reproduce the responsive homepage, obtain the geometry with `ringGeometry(width, height, headingCenterY)` and pass it as `renderPrism({ pixels, width, height, ...geometry })`. The returned object includes the phone's 2.4-pixel `channelShift`. Set that property explicitly when constructing phone geometry yourself.

The function keeps only pixels satisfying `abs(distanceFromCenter - radius) < bandWidth/2`. It rotates source coordinates by 5 degrees, offsets the red and blue sample positions in opposite horizontal directions, and interpolates between the four neighboring pixels for each sample. Green uses the unshifted coordinate. A 1.5-pixel alpha feather softens the inner and outer edges. Keep the band narrower than the diameter to retain a hollow center.

The starting parameters match the public homepage implementation:

| Parameter | Desktop | Phone |
| --- | --- | --- |
| Full band width | 96 px | 48 px |
| Source rotation | 5 degrees | 5 degrees |
| Red/blue offset magnitude | 4 px | 2.4 px |
| Channel brightness multiplier | 1.18 | 1.18 |

These values assume CSS-pixel-sized buffers. If you use a higher-density backing buffer, scale all geometry and pixel distances together. The offsets are the horizontal shifts before rotation, not a radial dispersion model. The brightness multiplier operates on encoded channel values and clips at 255; it is an art-direction control, not a radiometric calculation.

`ringGeometry(width, height, headingCenterY)` supplies the homepage's responsive sizing recipe. Its phone radius is constrained by both width and height, and its vertical clamp includes the full band. Use your own layout's text and navigation clearances when adapting it; the helper's offsets are specific to this composition. If a container is too small to hold the diameter plus the band, reduce the geometry or omit the decorative effect.

## Integrate without adding motion

- Position the canvas in the same fixed viewport coordinate space as the photograph. Set `pointer-events: none` and `aria-hidden="true"`.
- Draw after decoding and font readiness, then redraw on coalesced resize events. Do not run an idle animation loop or link the ring to scrolling unless the design explicitly requires motion.
- Establish the canvas's hidden state before starting its entrance fade. Match the photograph's entrance and exit timings, and disable the transition for reduced-motion users.
- Leave the photograph and text usable if image decoding or the canvas context fails.
- Handle same-origin images or a correctly configured cross-origin image response. A tainted canvas cannot return pixel data.
- Keep controls outside the shader. Apply a quiet, static treatment to navigation when strong refraction would impair its labels.

## Verify the rendered effect

Run the package's offline controls with `node scripts/test-prism.mjs`. They assert the transparent center/exterior, opaque mid-band, antialias feather, unchanged sampling at zero rotation/offset, RGB displacement, rotation, invalid input rejection, and portrait/landscape geometry. The controls use synthetic pixels and make no network calls.

Run `node scripts/render-example.mjs > example.ppm` to generate a source/output comparison from a synthetic grid. The script writes a PPM image to stdout and needs only Node. Convert that file to a web image with your existing image tool if needed. Both scripts were executed against the bundled renderer; the synthetic comparison also supplies the public case study's illustration.

Then inspect the actual page at desktop, portrait-phone, and short landscape-phone sizes. Confirm the image crop aligns, the full band stays where intended, text remains readable, links are clickable, theme changes preserve the composition, and reduced motion suppresses fades. Compare the deployed asset and rendered page with the source you tested before reporting completion.

The pure renderer expects an opaque photographic source; it writes its own annulus alpha. Test transparent imagery separately before adapting it. It allocates a full-size output buffer and assumes sRGB-like 8-bit channel values. Do not claim device-pixel-ratio coverage or measured rendering performance from the offline controls.

## Public reference

Read the [case study](https://cameron.stream/knowledge/photographic-prism-ring) for the composition and sampling equations. Compare the [homepage renderer](https://cameron.stream/public/home-prism.js) for its CSS-background alignment and fade integration. The bundled pure renderer extracts that algorithm; it does not replace the homepage's existing script.
