---
title: "Glass Field · Playground · Drew Minns"
description: "A live heat map behind glass that bends where you look."
url: https://reallygood.work/playground/glass-field/
---

Playground · 01

# Glass Field

A live heat map behind glass that bends where you look.

Live piece: A live heat-map field behind glass; move over it.

Palette

ThermalAcidNeon

Strips

10

Strips start

0.40

Edge glass

0.70

Lens

0.80

Speed

1.00

How it works

Plate G's slit-scan heat map, rebuilt as one fragment shader. The echo strips stay fixed; only the gradient behind them bends, at the frame edge and under your pointer.

The lens has no edge at all. It fades in from nothing, magnifies a little and frosts a little.

```js
// the lens has no edge: a gaussian falloff, magnifying toward the middle and frosting a little
float w = exp(-(r * r) / (R * R * .42)) * hover;
disp += (-dm * w * .42 * lens) / vec2(aspect, 1.);   // bend the gradient, never the strips
frost = w * lens;                                    // average a ring of samples where it's thickest
```

Make it yourself

A smaller version of the same shader in one file, with no libraries: the palette, the slit-scan strips, the edge glass and the lens. Save it as an .html file and open it. The settings at the top follow the controls above.

glass-field.html

```html
<!doctype html>
<meta charset="utf-8">
<title>Glass Field</title>
<style>
  body { margin: 0; min-height: 100vh; display: grid; place-items: center; background: #f4f1ea; }
  canvas { width: min(92vw, 960px); aspect-ratio: 16 / 9; border-radius: 16px; cursor: crosshair; }
</style>
<canvas id="field"></canvas>
<script>
const settings = {
  pal: 'thermal',          // colour ramp: 'thermal', 'acid' or 'neon'
  strips: 10,    // how many slit-scan strips the frame is cut into
  start: 0.4,      // where the echoes begin, 0 (left edge) to 1 (right edge)
  edge: 0.7,        // how hard the glass bends at the frame edge
  lens: 0.8,        // how much the soft lens under the pointer magnifies and frosts
  speed: 1,      // how fast the heat moves
};

// each palette: two background colours, then the heat ramp from cool to hot
const PAL = {
  thermal: ['#7CC8B2', '#7A4ED8', '#F4A3BD', '#FF8A3D', '#E8321E', '#2A0E14', '#2C3FB0', '#4A72E8'],
  acid:    ['#24130F', '#C9241F', '#7A1A14', '#F5FFB0', '#B8F23C', '#3FBFA8', '#22379A', '#22379A'],
  neon:    ['#1E1D10', '#2B1726', '#2A1F4A', '#4B48FF', '#D24CFF', '#FF5FA8', '#FF7A55', '#FF7A55'],
};
const rgb = h => [1, 3, 5].map(i => parseInt(h.slice(i, i + 2), 16) / 255);

const FRAG = `
precision highp float;
uniform vec2 res; uniform float time, strips, start, edge, lens; uniform vec3 mouse; uniform vec3 cols[8];

// a slow tilt across the whole frame, plus three soft blobs wandering over it: the heat is never flat anywhere
float heat(vec2 uv, float t){
  float asp = res.x/res.y, f = .25 + .35*(uv.x*.7 + (1. - uv.y)*.3) + .12*sin(uv.x*3. + t*.4);
  for (int i = 0; i < 3; i++){
    float k = float(i);
    vec2 b = vec2(.5 + .38*sin(t*.23 + k*2.1), .5 + .32*cos(t*.17 + k*1.7));
    float r = .26 - k*.05;
    vec2 d = (uv - b)*vec2(asp, 1.);
    f += .9*exp(-dot(d, d)/(r*r));
  }
  return clamp(f*.62, 0., 1.);
}

// the ramp: background first, then six stops spread evenly
vec3 ramp(float h, vec2 uv){
  vec3 bg = mix(cols[0], cols[1], uv.y), c = mix(bg, cols[2], clamp(h*6., 0., 1.));
  for (int i = 1; i < 6; i++) c = mix(c, cols[i + 2], clamp(h*6. - float(i), 0., 1.));
  return c;
}

void main(){
  vec2 uv = vec2(gl_FragCoord.x/res.x, 1. - gl_FragCoord.y/res.y);
  float asp = res.x/res.y;

  // slit-scan: each strip to the right of the start shows the field a little later and a little larger
  float j = max(0., floor(uv.x*strips) - floor(start*strips));
  float t = time - j*.5, grow = pow(1. + 2.6/max(4., strips), j);

  // glass at the edge: push the sample inward, hardest right at the border
  vec2 toEdge = min(uv, 1. - uv);
  float bevel = pow(1. - clamp(min(toEdge.x*asp, toEdge.y)/.12, 0., 1.), 2.);
  vec2 disp = (uv - .5)*-bevel*edge*.2;

  // the lens: a gaussian with no edge, pulling the picture toward its middle
  vec2 dm = (uv - mouse.xy)*vec2(asp, 1.);
  float w = exp(-dot(dm, dm)/(.3*.3*.42))*mouse.z;
  disp -= dm*w*.42*lens/vec2(asp, 1.);

  vec2 q = uv + disp, c = vec2(.5);
  q = c + (q - c)/grow;
  vec3 col = ramp(heat(q, t)*(1. - j/max(1., strips)*.45), uv);

  // each strip is its own pane: a shadow along its left edge and a thin bright line where it meets the last one
  if (j > 0.){
    float sx = fract(uv.x*strips)*res.x/strips;              // pixels into this strip
    col *= .86 + .14*smoothstep(0., res.x/strips*.35, sx);
    col += .18*(1. - smoothstep(0., 1.5, sx));
  }

  // frost: a little lift where the lens is thickest
  col = mix(col, col*1.04 + .04, w*lens*.5);
  gl_FragColor = vec4(col, 1.);
}`;

const canvas = document.getElementById('field'), gl = canvas.getContext('webgl');
const shader = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw gl.getShaderInfoLog(s); return s; };
const prog = gl.createProgram();
gl.attachShader(prog, shader(gl.VERTEX_SHADER, 'attribute vec2 a; void main(){ gl_Position = vec4(a, 0., 1.); }'));
gl.attachShader(prog, shader(gl.FRAGMENT_SHADER, FRAG));
gl.linkProgram(prog); gl.useProgram(prog);

// one rectangle covering the canvas; the shader colours every pixel
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
const a = gl.getAttribLocation(prog, 'a'); gl.enableVertexAttribArray(a); gl.vertexAttribPointer(a, 2, gl.FLOAT, false, 0, 0);

const u = n => gl.getUniformLocation(prog, n);
gl.uniform3fv(u('cols'), (PAL[settings.pal] || PAL.thermal).flatMap(rgb));
gl.uniform1f(u('strips'), settings.strips); gl.uniform1f(u('start'), settings.start);
gl.uniform1f(u('edge'), settings.edge); gl.uniform1f(u('lens'), settings.lens);

// the lens springs toward the pointer and fades in and out
const m = { x: .5, y: .5, tx: .5, ty: .5, h: 0, on: 0 };
canvas.addEventListener('pointermove', e => { const r = canvas.getBoundingClientRect(); m.tx = (e.clientX - r.left) / r.width; m.ty = (e.clientY - r.top) / r.height; m.on = 1; });
canvas.addEventListener('pointerleave', () => { m.on = 0; });

let t = 4, last = performance.now();
(function loop(now) {
  const dt = Math.min(.05, (now - last) / 1000); last = now;
  t += dt * settings.speed;
  m.x += (m.tx - m.x) * Math.min(1, dt * 14); m.y += (m.ty - m.y) * Math.min(1, dt * 14); m.h += (m.on - m.h) * Math.min(1, dt * 8);
  const dpr = Math.min(2, devicePixelRatio || 1), w = Math.round(canvas.clientWidth * dpr), h = Math.round(canvas.clientHeight * dpr);
  if (canvas.width !== w || canvas.height !== h) { canvas.width = w; canvas.height = h; gl.viewport(0, 0, w, h); }
  gl.uniform2f(u('res'), w, h); gl.uniform1f(u('time'), t); gl.uniform3f(u('mouse'), m.x, m.y, m.h);
  gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
  requestAnimationFrame(loop);
})(last);
</script>
```

-   [Everything — All pieces](https://reallygood.work/playground/)
-   [Next piece — Two-Ink Dither](https://reallygood.work/playground/two-ink-dither/)
