The Science of an LSD Shader
A psychedelic trip is not a vague swirl of colour — it is a phenomenon you can derive from the wiring of the visual system. This report walks through fluent_scene’s new lsd filter and shows which neural mechanism each stage of the computation stands for.
What fluent_scene is
A homegrown engine for drawing pictures and effects on live video, in real time. A screen is a few lines of config, an effect is one line, and it runs on the GPU, so it's fast. The same code runs on robots and in browsers — this article's LSD effect is one of its filters. It's also built so an AI can author screens without breaking anything. Open source (MIT) on GitHub. The technical details come later in the article.
1. What people actually see
Decades of subjective reports have been sorted into a surprisingly precise taxonomy (the fullest catalogue is PsychonautWiki’s Visual effects). The main classes:
- Drifting — textures and contours ripple, melt, and flow. “The wall is breathing”
- Colour enhancement — saturation and brightness rise; reds get redder
- Tracers and after-images (palinopsia) — moving objects leave trails, and crucially they read as a row of frozen frames rather than a continuous blur
- Geometric hallucinations — tunnels, spirals, rays, lattices; strongest with eyes closed, in the dark, or over flat surfaces
- Diffraction — rainbow fringes around bright edges
- Sharpened acuity — edges look unusually crisp
2. Why it looks that way — from molecule to cortex
2-0. Why LSD works at all — a key, a lock, and a lid
It starts with the shape of a molecule. At the core of LSD sits an indole ring — a benzene ring fused to a pyrrole ring — which is precisely the skeleton of serotonin, the brain’s own transmitter. LSD is, in effect, serotonin’s shape carried inside a larger, more rigid molecule, and it slots into the serotonin receptor’s binding pocket like a key.
In 2017, Wacker and colleagues solved the crystal structure of an LSD-bound serotonin receptor [13]. The decisive finding: the receptor’s extracellular loop 2 (EL2) folds over the entrance like a lid, trapping the molecule inside. That lid makes LSD extraordinarily slow to dissociate — it sits there for hours — which is why a trip lasts eight to twelve of them. Mutating the lid to make it more mobile speeds dissociation up and selectively removes the biased (β-arrestin) signalling.
In short: the indole ring fits the 5-HT2A receptor, the EL2 lid locks it in for hours, and cortical excitation stays off balance the whole time — the molecular origin of everything that follows.
2-1. The 5-HT2A receptor — cortical gain up, gating down
LSD’s main action is agonism at the serotonin 5-HT2A receptor. That raises the excitability of cortical pyramidal cells while damping the visual cortex’s alpha rhythm — the gate that normally thins incoming signal [4][6]. fMRI adds that thalamo-cortical connectivity increases, and that the loosening of thalamic sensory filtering correlates with how strong the visual hallucinations feel [5]. The upshot: the gain goes up and the filtering goes slack — colours deepen, edges sharpen, and faint patterns start to look meaningful.
2-2. Where the geometry comes from — V1, a logarithm, and a fractal
Klüver sorted geometric hallucinations into four classes in 1926 — the form constants: tunnels and funnels, spirals, lattices, cobwebs [1]. Why does everyone see the same handful of shapes? Ermentrout and Cowan gave a beautiful answer in 1979 [2].
Neurons in V1 excite their near neighbours and inhibit those a little further out. Push excitation up with a drug and that balance tips, so activity patterns arise spontaneously across the cortical sheet — the same bifurcation that gives Turing patterns in chemistry. What makes them visible is anatomy: the retina-to-V1 projection is approximately a complex logarithm, (x,y) → (log r, θ). Map plain cortical stripes back through it and you get:
- stripes perpendicular to
log r→ concentric rings = tunnels - stripes perpendicular to
θ→ radial rays = funnels - oblique stripes → logarithmic spirals
- two stripe directions at once → lattices and chequerboards
A single plane wave — one tidy set of stripes — will not give you what people actually describe: masses of every size, nested fractally, streaming toward you. Two findings say why.
- Lattice planforms — Bressloff and colleagues [3] showed that once V1’s orientation-tuned, anisotropic lateral wiring (shift-twist symmetry) is included, the stable solutions are not lone stripes but rhombic and hexagonal lattices: honeycombs, cobwebs, filigrees. Klüver’s lattice and cobweb classes fall out of this.
- A rise in fractal dimension — Varley et al. [10] measured, under both LSD and psilocybin, an increase in the fractal dimension of cortical activity in space and in time. A system near criticality is scale-free: no single dominant wavelength survives, and structure stands at every scale at once.
Drawing the theory’s lattice solutions straight out of a trigonometric function, though, comes out far too regular to be true. Two things recur in every report: there are no straight lines, right angles, or perfect circles, and you are flying through a 3D space where everything expands forever. So the shader’s geometry field uses no periodic function at all:
- Eternal zoom — depth shells an octave apart crossfade under a Hann window. As the flight advances the nearest shell expands past the window and fades, while a fresh far shell fades in with new content seeded by an integer flight index, so the expansion never ends and never repeats
- Detail the way nature has detail — each shell is domain-warped value noise weighted toward its high octaves, so finer tufts keep hanging off the edges of coarser flows: the statistics of coastlines, clouds, and lichen
- Depth cues — nearer shells are brighter and combine by maximum, so near masses occlude far ones, and each shell owns a hue a golden angle from its neighbours, which separates depth by colour as well as by motion
Klüver’s classes survive not as drawn figures but as statistics: multi-scale, flowing, biased toward the centre. Combined with the feedback zoom described below, the whole frame reads as something welling up out of the distance and rushing past you.
The demo below shows the principle. On the left, a pattern on the cortical sheet; on the right, the same pattern mapped back into retinal coordinates. “Nested lattice” is the multi-octave construction the shader uses:
cortical stripes ── inverse map r = e^u, θ = v ──> what is perceived
geometry stage lays this multi-octave version over the darker parts of the image as masses.2-3. Trails and after-images — a broken suppressor, and recursion
Normally the brain actively erases the smear a moving object leaves on the retina — motion streak suppression. LSD appears to push that circuit outside its working range, so frames that should have been erased persist [7]. The texture of the reports matters: the tail is not a smooth blur but a row of discrete frozen images, strobe-like.
Computationally that is feedback: the output re-entering the input. A single-pass shader has no memory of the previous frame, so the demo takes the rendered result each frame, scales and rotates it slightly, decays it, and composites it back into the next input. That recursion gives the trails — and also the endlessly proliferating fractal depth of the tunnel, the same dynamics as pointing a camera at its own monitor.
wasm/lsd.html. The purple path is the recursion; trails, palinopsia, and the recursive tunnel all come from it. The decay coefficient — the Persistence slider — stands for how well the suppressing circuit is still working.2-4. Why the same image never comes twice — non-stationarity
The other signature of the experience is non-stationarity. It is never a static “effect”; it transforms continuously and never returns to a state it has been in. The transitions are not uniform either: some you only notice afterwards, some bleed slowly, some snap. Measurements agree:
- Under psilocybin the brain wanders a wider repertoire of dynamical states than usual (Tagliazucchi et al. [11]); under LSD the use of connectome harmonics — the eigenmodes of brain activity — expands, and the trajectory stops repeating (Atasoy et al. [12]).
- Varley et al. [10] measured a rise in the fractal dimension of the time course, meaning the fluctuations have no characteristic timescale. In power-law fluctuation, slow drifts and sudden jumps are the body and the tail of one distribution — that both happen is not a coincidence.
The demo implements this as a trip conductor. Every parameter wanders around its slider value: a slow incommensurate jitter you never quite catch, plus metastable jumps arriving as a Poisson process (about one every twenty seconds). Each jump’s transition time is drawn log-uniformly from 0.25 to 20 seconds — a heavy tail — so some changes snap and others take the better part of a minute. And because the feedback loop is a nonlinear recursion, it is sensitive to its own history: no frame is ever produced twice.
3. Phenomenon → mechanism → implementation
| Phenomenon | Neural mechanism | In the shader | Parameter |
|---|---|---|---|
| Drifting, breathing | Higher gain and dominant priors destabilise where a contour is judged to be [4][6] | Sampling coordinates warped by a slow radial swell plus two incommensurate travelling fields | drift |
| Colour enhancement | Unfiltered input through a loosened thalamic gate [5] | Saturation and contrast lifted, hue rotating slowly | trip |
| Sharpened acuity | The same amplification, acting on edge responses | Four-tap unsharp mask | trip |
| Rainbow fringes | Diffraction through dilated pupils | Radial RGB separation, widening toward the periphery | chroma |
| Geometry (flying in 3D) | V1 self-organisation [1][2][3] plus a raised fractal dimension [10]. It has a centre, it is finely detailed, and it expands forever | Three depth shells in an eternal zoom (Hann crossfade, content re-seeded by flight index). Masses are domain-warped value noise over four high-weighted octaves; nearer shells are brighter and combine by maximum; each shell owns a hue so depth separates in colour | geometry |
| Trails, after-images | Motion streak suppression breaking down [7] | Output fed back into input, decayed and slightly zoomed and turned; max blending reproduces the discrete frozen frames | Persistence / Zoom / Swirl |
| Ceaseless transformation | An expanded dynamical repertoire [11][12] and scale-free fluctuation [10] | The trip conductor: micro-jitter plus Poisson-arriving metastable jumps, transition times log-uniform over 0.25–20 s | Auto-flux / Depth |
4. Playing with the parameters
The demo lives at takatronix.github.io/fluent_scene/lsd.html. The picture fills the screen; the controls hide behind the ⚙ in the corner. ⛶ or a double-tap goes fullscreen, and on a phone the first tap does it for you. The pharmacology group drives the filter itself, recursion drives the feedback, and flux drives the trip conductor.
- Trip — master gain. Zero passes the image through untouched, 1.5 runs every stage at full. This is the dose
- Drift — how far things ripple and breathe. At 3 the walls melt
- Geometry — how strongly the hallucinated structure is laid over the image. It favours dark and flat regions, exactly as the reports do
- Chroma — the width of the rainbow fringing
- Persistence — feedback decay. Past 0.9 the past stops fading
- Zoom — the recursion’s scale step. Positive pulls you in, negative pushes outward
- Swirl — the recursion’s rotation. With persistence it grows logarithmic spirals on its own
- Auto-flux / Depth — the trip conductor and how far it swings. While it runs, every parameter wanders around its slider and the image never repeats; the status line shows whether it is holding or shifting, and whether the shift snaps or crawls
Recipes worth trying
- Eyes closed: cover the camera, Geometry 1.2, Trip 1.0 — with the input gone only the endogenous pattern remains, which is why the geometry shows up in the dark
- Strobe trails: Trail set to glow, Persistence 0.85, then wave your hand — the discrete trailing of [7]
- Infinite tunnel: Persistence 0.9, Zoom 0.3, Swirl 0.2 — video-feedback dynamics
- Threshold dose: Trip 0.3, Geometry 0 — colours a little deeper, contours barely moving
5. Implementation notes
The filter is one function — fs_lsd() in include/fluent_scene/shared/filters_shared.h, written once in the GLSL∩C++ subset and run identically by the CPU reference, Vulkan, and WebGPU (whose WGSL is machine-translated through naga). Time arrives through the time parameter slot, driven per frame by the host in the same pattern fx::Ripple uses, so at time=0 the filter is static and golden-testable. The feedback loop is closed outside the filter pipeline, in the demo, leaving the core renderers untouched.
// the heart of the geometry stage (from fs_lsd): depth shells expanding forever
float zp = t * 0.3; // flight speed, octaves per second
float zf = zp - floor(zp);
for (int i = 0; i < 3; ++i) {
float e = float(i) - zf; // depth exponent; smaller is nearer
float sc = exp2(e); // shrinks in domain → expands on screen
float m = float(i) + floor(zp); // this shell’s flight index
vec2 off = hash(m); // fresh content per shell
float w = 0.5 - 0.5*cos(2.094*(e+1)); // Hann window: born, grown, gone
vec2 pl = pc * 3.0 * sc + warp * 2.2 * sc + off;
float nv = vnoise(pl) * 0.38 + vnoise(pl * 2.1) * 0.27 // weighted toward
+ vnoise(pl * 4.4) * 0.2 + vnoise(pl * 8.9) * 0.15; // the fine octaves
float near_f = smoothstep(2.0, -1.0, e);
float clv = smoothstep(0.52, 0.72, nv) * w * (0.5 + 0.5*near_f);
mass_ph = clv > mass ? m*2.39996 + ... : mass_ph; // the shell’s own hue
mass = max(mass, clv); // near occludes far = depth
}
References
- Klüver, H. (1966). Mescal and Mechanisms of Hallucinations. University of Chicago Press. (the origin of the form constants; first published 1926)
- Ermentrout, G. B. & Cowan, J. D. (1979). A mathematical theory of visual hallucination patterns. Biological Cybernetics, 34, 137–150.
- Bressloff, P. C., Cowan, J. D., Golubitsky, M., et al. (2001). What geometric visual hallucinations tell us about the visual cortex. Neural Computation, 14(3), 473–491.
- Carhart-Harris, R. L., et al. (2016). Neural correlates of the LSD experience revealed by multimodal neuroimaging. PNAS, 113(17), 4853–4858.
- Müller, F., et al. (2017). Increased thalamic resting-state connectivity as a core driver of LSD-induced hallucinations. Acta Psychiatrica Scandinavica, 136(6), 648–657.
- Kometer, M. & Vollenweider, F. X. (2016). Serotonergic hallucinogen-induced visual perceptual alterations. Current Topics in Behavioral Neurosciences, 36, 257–282.
- Dubois, J. & VanRullen, R. (2011). Visual trails: do the doors of perception open periodically? PLOS Biology, 9(5), e1001056.
- Kwan, A. C., et al. (2024). Neural mechanisms of psychedelic visual imagery. Molecular Psychiatry, 30, 809–818.
- General audience: A Math Theory for Why People Hallucinate (Quanta Magazine, 2018) / phenomenology catalogue: PsychonautWiki
- Varley, T. F., Carhart-Harris, R., Roseman, L., Menon, D. K. & Stamatakis, E. A. (2020). Serotonergic psychedelics LSD & psilocybin increase the fractal dimension of cortical brain activity in spatial and temporal domains. NeuroImage, 220, 117049.
- Tagliazucchi, E., Carhart-Harris, R., Leech, R., Nutt, D. & Chialvo, D. R. (2014). Enhanced repertoire of brain dynamical states during the psychedelic experience. Human Brain Mapping, 35(11), 5442–5456.
- Atasoy, S., et al. (2017). Connectome-harmonic decomposition of human brain activity reveals dynamical repertoire re-organization under LSD. Scientific Reports, 7, 17661.
- Wacker, D., Wang, S., McCorvy, J. D., et al. (2017). Crystal structure of an LSD-bound human serotonin receptor. Cell, 168(3), 377–389. (the EL2 lid and ultra-slow dissociation — the structural basis of the long duration)