A generalised superformula, traced with light that refracts in and bounces around inside.
How it works
The superformula (Johan Gielis, 2003) gives a radius for every angle φ:
r(φ) = ( |cos(m1φ/4) / a|n2 + |sin(m2φ/4) / b|n3 )−1/n1 · (1 + A sin kφ)
The classic formula uses a single m. Here the cosine and sine terms each get their own symmetry (m1, m2), with a phase and a ripple on top. Each formula is normalised so its largest radius is 1.
2D: the curve is A, B or a mix of them, swept over several turns with optional spiral growth. The glass is the even-odd interior, so self-crossing curves work too. Light rays are traced against the curve (about 4096 segments per turn, smoothed normals). At each crossing the unpolarised Fresnel equations decide between reflection and refraction, and beyond the critical angle the light is totally reflected. That is how light gets trapped inside.
3D: the spherical product of A (around the vertical axis) and B (from pole to pole), or a supertorus. Twist, taper, bend, stretch, noise, a hollow shell and a cut plane come on top. The surface has no exact distance function. It is ray-marched with the radial field |q| − R divided by its analytic gradient, and the hit is then refined by bisection. A path tracer follows each camera ray through as many glass bounces as you allow. The floor uses next-event estimation of the sun with multiple importance sampling, so light focused by the glass shows as caustics.
Glass: the index follows Cauchy's law fitted to nd and the Abbe number V, so every wavelength bends differently. A path picks one wavelength the first time it meets the glass, and the colours average out over the samples. Dispersion ×1 is the real material, and higher values exaggerate it. The tint absorbs light along the path inside (Beer–Lambert).
Not modelled: polarisation (Fresnel is averaged over both polarisations), rough or frosted surfaces, and the birefringence of rutile and sapphire. In 3D a fractional m leaves a seam where the angle wraps.
Drag the 3D view to orbit and scroll to zoom. In 2D, drag to move the light, shift-drag to aim it, and scroll to zoom. Double-click a slider's name to reset it.