Morphiq

Components / Prism Glass

Prism Glass

A GPU refractive lens — spectral dispersion, uniform frost and a directional rim light, from an SDF-defined shape with no 3D model involved. It refracts the texture you hand it, not the DOM behind it.

Usage

import PrismGlass from '@/components/prism-glass'

<PrismGlass
  image={photo}
  shape="circle"
  mode="cursor"
  size={20}
  refraction={100}
  depth={60}
  dispersion={60}
/>

Installation

npx shadcn@latest add https://morphiq.prathampatel.design/r/prism-glass.json

Model

n₁·sin θ₁ = n₂·sin θ₂,   n = n(λ)

refraction through an SDF-shaped lens, with the index varying by wavelength

Props

PropertyTypeDefaultDescription
imagestring'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=='Image URL rendered full-bleed behind (and refracted by) the glass.
texture{ readonly isTexture: true }—A three.js texture to refract instead of image — a render target's texture, for scene glass. Its sampler settings are left as you set them.
transparentbooleanfalseLet the page show through where the lens is not, instead of drawing image full-bleed behind it.
maskstring—Silhouette (SVG or PNG) used as the lens outline. Overrides shape. Converted to a signed-distance field on load, so curves work.
shape'circle' | 'rect' | 'pill' | 'cursor''circle'Lens outline. pill is a rounded rect with fully-rounded ends.
mode'cursor' | 'static''cursor'cursor follows the pointer; static sits at position.
sizenumber | [number, number]20circle/cursor: radius i.e. half-height (0-100). rect/pill: [width, height].
radiusnumber7Corner radius (0-100) for shape="rect". Ignored otherwise.
position[number, number][0.5, 0.5]Position in static mode, normalised [x, y] from 0 to 1.
follownumber0.09Follow easing. 0 snaps instantly; higher trails more.
refractionnumber100Master strength (0-100). At 0 the glass is invisible.
depthnumber60Reach of the refraction band and the warp magnitude (0-100).
dispersionnumber0Spectral colour separation (0-100).
frostnumber0Uniform frosting across the lens (0-100).
splaynumber0Tangential stretch along the edge (0-100).
lightAnglenumber45Direction of the rim light, in degrees.
lightIntensitynumber100Rim light brightness (0-100).
dprnumber | [number, number][1, 2]Device pixel ratio passed to the renderer.