Crystal Cave WebGL — 3D Raymarched Simulation

← Back to Visuals

About This Simulation

The Crystal Cave is rendered entirely in real time on your GPU using a GLSL fragment shader and SDF raymarching. A ray is cast for each pixel and stepped through space until it strikes one of the crystal spires — mathematical shapes defined as elongated octahedra (bipyramids). The surface normal is estimated by central differences, then used to compute Fresnel-based spectral dispersion: at grazing edges, the crystal scatters its light into a rainbow fringe, just as real quartz and calcite do. Three coloured point lights — switchable between cool (blue-cyan-violet), warm (amber-rose-gold) and animated rainbow — illuminate the cluster from different angles. A slow orbital camera circles the formation, gently rising and falling, giving the scene an almost breathing, meditative quality.

Technique

SDF Raymarching

Geometry

Elongated Octahedra

Optics

Fresnel Dispersion

Camera

Orbital Path

Frequently Asked Questions

What is raymarching?

Raymarching is a rendering technique where a ray is cast from the camera for each pixel and stepped forward until it hits a surface. The distance to the surface is evaluated by a mathematical function called an SDF, making it possible to render complex 3D shapes entirely in a GLSL shader with no 3D mesh data at all.

How do signed-distance functions (SDFs) work?

A signed-distance function takes a 3D point and returns the shortest distance to the nearest surface. Positive values mean outside; negative means inside; zero means on the surface. At each march step the ray advances by exactly the SDF value — safe because that distance is guaranteed obstacle-free — converging on the surface in far fewer steps than a fixed-increment approach.

What is spectral dispersion?

Spectral dispersion is the splitting of light into its component colours — the rainbow you see through a prism or crystal. In this shader it is approximated at crystal edges where the Fresnel term is high: a cosine colour palette keyed to the surface normal angle produces rainbow fringes that shift subtly as the camera orbits.

What is the Fresnel effect?

The Fresnel effect describes how a surface reflects more light at grazing angles. Looking at a crystal edge nearly parallel to the surface you see far more reflection and colour dispersion than looking straight on. In the shader the Fresnel term — pow(1.0 - dot(normal, viewDir), 3.5) — drives both the strength of the specular highlights and the rainbow dispersion intensity.

What are the three light modes?

Cool uses blue, cyan and violet point lights for an icy, ethereal atmosphere. Warm uses amber, rose and gold for a fire-lit cave. Rainbow slowly rotates through all hue combinations over time using animated cosine palettes, making the crystals shift colour continuously — ideal for deeper hypnotic relaxation.

What sound pairs best with the Crystal Cave?

Crystal Singing Bowl (432 Hz) is a natural companion — its pure harmonic resonance mirrors the prismatic light of the crystal spires. Tibetan Bowl or Gentle Rain from the Sound Mixer also create a deeply relaxing atmosphere alongside the slowly orbiting scene.

Does the Crystal Cave work offline?

Yes. ASMR Sanctuary is a Progressive Web App. After your first visit the Service Worker caches the page and all assets, so the crystal cave simulation runs fully offline with no internet connection required.

How does the camera orbit work?

The camera position is computed each frame using trigonometric functions: X and Z coordinates follow a circle (cos/sin of a slowly increasing angle) while the Y height bobs gently with a secondary sine wave at a different frequency. The camera always looks toward the centre of the crystal cluster, keeping it framed as the orbit completes.

My device is struggling — any performance tips?

Reduce the browser window size or zoom in to lower the canvas resolution. On mobile, portrait orientation renders fewer pixels. Cool or Warm light mode is marginally lighter than Rainbow. Reducing the Speed slider does not significantly change GPU load, but pausing the simulation stops rendering entirely if you need to save battery.

What does smooth union do in the shader?

Smooth union (opSmoothUnion) blends two SDF surfaces together with a soft chamfer, controlled by a radius parameter k. Where crystal spires are close together they merge organically rather than intersecting with a hard edge, creating the natural crystal-growing-from-rock appearance of real mineral formations instead of sharp separate shapes.