Pinch-density photo grid under a glass lens

I wanted to know if one ElementGL shader can swell a lens over live photo tiles and blur their neighbours by pinch density while every tile and control still takes a tap.

Contact sheet · 36 frames Dunes 06
0 picked
4 columns · lens on

Starting the ElementGL lens shader...

Show the code lens shader, the tap that follows the picture, and hit sync
  1. Live tiles inside the canvas. One drawable <section> holds the grid of <article> tiles with heart buttons, the density range and the lens button. It is sized with explicit left, top, width and height, not inset: 0.
  2. Spherical lens and radial neighbour blur. Inside the lens each pixel samples nearer the centre by 1 / (1 + (mag - 1) * z), with z the height of a unit sphere. Outside it, 18 taps along and across the radius blur the neighbours more the denser the grid is.
  3. A tap goes to the tile you see. The same lens maths runs in JavaScript on a click inside the lens, finds the element drawn there with elementsFromPoint() and clicks that instead.
  4. Card size and hit geometry. Copies the canvas box into --card-w and --card-h, then calls updateElementGeometry() only when the unit or the buffer size changes.

How it works

Move or tap over the grid, pinch it, or drag the density slider. The idea comes from Atlas's pinch-density grid (via memorabl.es), where pinching a photo grid changes how many columns it has and a lens swells over the photo under your finger. Here the grid is ordinary HTML: 36 <article> tiles painted with CSS gradients, each with a heart <button>, laid out by CSS grid with repeat(var(--cols), 1fr). The whole card is uploaded to one texture with texElementSubImage2D() when it repaints, and drawn on one quad.

The fragment shader only touches pixels inside the grid's box, so the header, the slider and the lens button stay sharp. Inside the lens radius it bends the sample point towards the centre like a glass sphere, splits red and blue a little near the rim and adds a highlight. Outside it, the neighbours are blurred along and across the line to the lens centre, dimmed and desaturated a little, and the blur radius grows with the density: 2 px at 3 columns, 8 px at 7. A two-finger pinch on the grid, or a trackpad pinch (a wheel event with ctrlKey), changes the density continuously, and the column count snaps to the nearest whole number.

The hit boxes come from layout, not from the picture, so a tile under the glass is drawn bigger than the box that takes the tap. updateElementGeometry() only takes an affine matrix, which cannot describe a lens. So a click inside the lens is caught in the capture phase, the lens mapping is run on the tap point in JavaScript, and if a different tile or heart is drawn there, that element gets the click instead.

Live checks

These wait for a tap, because they make WebGL fixtures and read pixels back. Each one builds its own canvas on the test stage and retires it afterwards. The hit check reads the visible card's layout but does not change it.

Findings