Hidden-text dust

I wanted to know if the shimmering dust Telegram puts over hidden words can come from the glyphs of live text. One ElementGL fragment shader reads the texture alpha only inside the rectangles Range.getClientRects() gives for each hidden span, so dust is born where there is ink and nowhere else, and a tap blows it outwards from your finger. The words stay native text that you can select and a screen reader can read. Tap a dusty range, or type a message with ||words|| to hide.

3 of 3 ranges hidden
Film club ยท 4 people 3 hidden

MayaFinished it last night. The killer was the lighthouse keeper all along.

No way. I guessed the twin sister from the first scene.

TheoAnd the last shot is the empty boat drifting home, which I never saw coming.

Starting the ElementGL dust shader...

Show the code range rectangles, glyph dust shader, tap reveal, composer
  1. A real chat inside the drawable canvas. Three <p> messages in an <article> with <span data-hidden> ranges, a <textarea> and two buttons, on a card with no backgrounds behind the text.
  2. Line boxes from Range.getClientRects(). Each hidden span gives one rectangle per line, measured against the card's client box and divided by its scale, so they land in card pixels.
  3. Dust from glyph alpha. For every pixel near a hidden rectangle the shader walks back through the radial scatter to a home position, looks at a 3 by 3 block of hashed particle cells there, and keeps a particle only if uTex.a at its home is ink.
  4. Tap to reveal. The click point becomes the centre of the scatter and of a reveal wave, on a clock-timed tween.
  5. The composer. Words between || marks become a new hidden span, built with text nodes.
  6. Size and hit sync. Copies the canvas box into --card-w and --card-h, then calls updateElementGeometry() only when the unit or buffer size changes.

How it works

The idea comes from Telegram's hidden text (Telegram blog) and from Artem Novichkov's write-up of rebuilding it on iOS with CAEmitterLayer. Web copies I've seen paint noise over a box, because CSS can't read text pixels. Here the chat is drawn into one ElementGL WebGL 2 canvas, and the message bubbles have no CSS background: the shader paints them from offsetLeft and offsetTop. That leaves the texture alpha inside a hidden range as the glyph coverage and nothing else.

Each frame the page asks Range.getClientRects() for every [data-hidden] span and hands up to 16 line rectangles to the shader, each with its reveal progress and tap point. Inside those rectangles the shader drops the text from the texture and draws particles instead. The particles live on a hashed grid of 2.4 px cells in three layers, and a particle exists only where uTex.a at its home is above 0.3, so spaces and the blank ends of a line stay empty. At rest they wobble less than a pixel and twinkle.

A tap sets the scatter centre. Each layer moves its particles away from that point by a push and a stretch that grow with progress, at three speeds. The fragment shader can't loop over particles, so it inverts that move: from the pixel it works out where a particle there would have started, checks the cells around that home, and maps each candidate forwards to get a round dot. A reveal wave spreads from the same point and lets the text back in behind it.

The backlog suggested instanced particles through transform feedback. ElementGL is the one WebGL context a page may hold and it has one fragment program, so I kept to a hashed field in that program instead of adding a second pass.

Live checks

These checks wait for a tap so the page keeps one WebGL context until asked. The shader checks run on their own small fixtures and give their canvases back afterwards. The tap, composer and hit checks run on the chat on this page and put it back.

Findings