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.
Starting the ElementGL dust shader...
Show the code range rectangles, glyph dust shader, tap reveal, composer
- 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. - 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. - 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.aat its home is ink. - Tap to reveal. The click point becomes the centre of the scatter and of a reveal wave, on a clock-timed tween.
- The composer. Words between
||marks become a new hidden span, built with text nodes. - Size and hit sync. Copies the canvas box into
--card-wand--card-h, then callsupdateElementGeometry()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
- Measured in Chrome Canary
161.0.8200.0on 2026-12-04 at412x915(DPR2.625, SwiftShader WebGL): all 8 live checks passed with zero JS errors, zero lost contexts, zero open snapshots and no horizontal overflow on a924x1181canvas (1.09 MP,8.3 MB). - With a 30 px word in a hidden rectangle widened to 200 px, the shader drew
5138dust pixels over the word and0over the blank120.3 pxafter it, and0pixels of the red text got through. Revealed, the word drew5857red pixels and no dust. - At reveal 0 no dust pixel fell more than 4 px outside the range. At reveal 0.45,
4213did (711of them behind the tap), and the mean distance from the tap went from29.9 pxto56.3 px. - A click on the first hidden range landed at card
100.0,108.1, exactly where the page expected from the client box, and the tween reached 1 within1350 ms. Sending||dust test||from the composer added a hidden span and took the line rectangles from4to5. - The card measured
450pxagainst a450pxcanvas, andelementsFromPoint()found Reveal all, Send and the textarea at their drawn centres with0.00pxvertical offset. Two pairs of frames atuClock=0matched in all1189440bytes. - A synthetic
MouseEventtruncated a fractionalclientY, so my first tap check was off by1.0px. It now dispatches whole pixels.