Skip to content

Add opt-in telegramDust particle preset with tap-attractor reveal - #61

Open
zhukeev wants to merge 19 commits into
release/1.1.2from
feat/telegram-dust
Open

zhukeev wants to merge 19 commits into
release/1.1.2from
feat/telegram-dust

Conversation

@zhukeev

@zhukeev zhukeev commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Summary

Opt-in ParticlePreset.telegramDust replicating Telegram iOS InvisibleInkDustNode physics and visuals across all four render backends (atlas, vector, vertices, shader):

  • Physics: ballistic drift at ~0.35 specks/px² steady state, fixed heading, uniform speed in [0, 20] px/s, 1.0s lifetime with the CAEmitterCell alpha pulse [0,0,1,0,-1] — no diffusive random walk
  • Sprites: new SpeckleImageFactory grainy noise texture (atlas + shader uParticleTex), ParticlePathPreset.speckle for vector, jittered ring for vertices
  • Tap reveal: ParticleAttractor spring (stiffness 4, radius = maxDim, mass-scaled) plumbed through update(dt); expanding spotlight reveals tap-first with a soft radial-gradient edge via two-pass child paint in RenderSpoiler
  • Reveal choreography: spotRadius = fadeMaxRadius − fade.radius grows from the tap during the reverse sweep; position-dependent duration (~550ms base, ×2 tall aspect); FadeConfig.duration override; waves suppressed for dust
  • Shader: new dust.frag / dust_nosprite.frag — stateless hashed grid, ballistic drift confined to the ±1-cell window via triangle fold, life pulse, spot feather matching mask stops [0, 0.7, 0.95, 1.0], uAttractor vec4 patched per-frame by ShaderSpoilerDrawer (positional pull approximation — a stateless shader cannot integrate spring velocity)
  • API: ParticleConfig.telegramDust() factory + dustDensity/dustMaxSpeed/dustLifetime fields; density/speed/shapePreset/enableWaves ignored under dust; all signature changes are package-private (non-breaking)

Test plan

  • flutter analyze — clean (only pre-existing deprecated_member_use infos)
  • flutter test — 112 tests pass, including 8 new dust tests (ballistic determinism, attractor spring, spawn count, spotlight reveal) and dust cases in shader_uniforms_test
  • Manual: benchmark page preset selector (Custom / TG Dust) across all 4 backends

Base: release/1.1.2 — this branch is exactly one commit ahead of it; targeting main would pull in the three unreleased 1.1.2 commits.

Replicates Telegram iOS InvisibleInkDustNode physics/visuals behind
ParticlePreset.telegramDust: ballistic drift at ~0.35 specks/px²,
1s life alpha pulse, grainy speckle sprite, tap simpleAttractor spring,
and an expanding radial spotlight that reveals tap-first with a soft
edge across all four render backends (atlas, vector, vertices, shader).
Showcases the telegramDust preset on a text spoiler and a widget
spoiler with a backend selector (atlas/mesh/vector/shader) so all four
render paths can be compared interactively.
…low drift

Re-reading InvisibleInkDustNode revealed three wrong assumptions:

- valueOverLife uses additive=true on base alpha 1.0: specks are born
  bright, hold brightness for 75% of life, and fade out in the final
  quarter — they do not blink in and out.
- velocityRange=20 with base velocity 0 yields speeds of 0-10pt/s, half
  the previous drift.
- Effective visible density in the media-spoiler reference is far below
  the text birthRate: default dustDensity drops 0.35 -> 0.05, matching
  the measured 0.0235 bright specks/pt2 in the reference recording.
Numerical crop comparison against the Telegram reference (same device,
same scale) showed specks reading at half the reference size: the
speckle texture's solid core was only 45% of the quad and the alphaRange
jitter bottomed at 0.55. Solid core is now 62% with a short feather,
nominal size is 1.6pt, and jitter floor is 0.7 — bright-blob median now
measures 9px2 against the reference's 8px2 (was 4px2).
Bright-pixel coverage measured 14.9% against the reference's 2.2% on
the shader backend. Two causes: the disc was solid out to the full
speck radius (bright area ~19px2 vs the CPU backends' ~9px2, and
kEmitterBoost still assumed the old blinking alpha model — with
persistent brightness ~90% of specks are visible, so emission density
must run below nominal. Disc is now a 62%-core feathered profile
matching the speckle texture, boost is 0.55. Coverage now measures
2.7% versus the reference's 2.2%.
EOF
)
The wave-exclusion guard pre-dated the 1s dust lifetime: wave
displacements now self-heal within one life cycle as specks respawn,
so the ambient ripple system is compatible with ballistic dust (CPU
backends). The demos text spoiler uses dustDensity 0.3 - Telegram
emits text dust at 0.35/px2 of word-rect area, producing dense
glyph-hugging noise, while media spoilers stay sparse at 0.05.
Ripples are (center, age) state evaluated statelessly by every
backend — ring expands at 320pt/s for 1.4s. CPU backends apply a
radial velocity kick in moveBallistic plus a small brightness flash;
the shader uses small positional displacement only. The flash/swell
variants were dropped on shader: amplifying every speck in the band
at once blends overlaps into a continuous white band, destroying the
dust texture. Ambient ripples fire per-controller with staggered
random countdowns so multiple spoilers never synchronize.
Up to 3 ripples now run concurrently — the shader gets one vec4
uniform slot per ripple plus static speed/width/strength uniforms,
while CPU backends iterate the list in moveBallistic and the visual
flash. New ParticleConfig knobs: dustRippleSpeed, dustRippleWidth,
dustRippleStrength, dustRippleInterval (0 disables ambient ripples;
tap ripples always fire). Also reverts example/macos build artifacts
that leaked into the branch.
- Rename ParticlePreset.telegramDust/ParticleConfig.telegramDust() to
  dust/dust() and scrub reference mentions from code comments
- Raise CPU-backend spawn density 0.05 -> 0.07 per pt2 (media surfaces
  read too sparse on atlas/mesh/vector); compensate shader emission
  boost 0.55 -> 0.4 so the shader keeps its approved density
- Correct shader text dilution: emission is uniform across the spoiler
  bounds, but CPU backends spawn inside glyph word-rects. Scale the
  density uniform by inverse path coverage (clamped 0.15..1) so text
  matches the CPU backends instead of diluting into whitespace
The edge treatment scaled speck radius by distance to the spoiler
bounds. Thin regions like single-line text are all-edge: every speck
shrank to a pinprick, making shader text read far sparser than the CPU
backends even at equal density.

- speck radius is now constant regardless of edge proximity
- edge fade is alpha-only, and its span caps at a quarter of the
  smallest dimension so thin regions keep most of their area bright
Every speck used to fade along the same uniform curtain line, reading
as a hard edge. Now each speck gets a jittered zero line and fade width:
high-jitter specks survive almost to the boundary while low-jitter ones
dissolve deeper inside, so the edge reads as a soft organic falloff.
Zero lines stay inside the rect so the hard clip never cuts mid-fade.
Pure random placement clusters: adjacent specks merge into lumps, most
visible on large media surfaces (p90 blob measured ~39px2 vs ~12px2
reference). The spawn pool is now one jittered sample per grid cell,
shuffled and consumed in order so spawns do not re-cluster positions.
Drop the legacy random-walk particle system entirely: the ballistic
speck model is now the only particle behavior.

- ParticleConfig rewritten: density (specks/pt2), maxDriftSpeed,
  lifetime, ripple* — no preset enum, no legacy speed/shape/waves
- ParticlePreset, wave system, SpoilerSpotsController,
  mergeLegacyParticleConfig and all deprecated scalar shims deleted
- legacy particles.frag/particles_nosprite.frag content replaced by
  the dust shaders (renamed); ShaderConfig.dust() folded into
  ShaderConfig.particles()
- ripples, attractor and spotlight reveal are now unconditional
- text config defaults to dense glyph-hugging particles (0.3, white70)
- controller tests: speckle debug hook, fadeConfig: null for instant-toggle cases
- configs/utils/dust tests rewritten for the unified config
- 102/108 passing; remaining 6 text_field_wrapper failures are
  two-pass reveal paint crashes in the test harness under investigation
- isRevealed no longer gates on particle presence: on the first enable
  the drawer is still empty when the cover sweep starts, so masked spans
  went transparent instantly and stayed hidden through the whole sweep —
  text vanished before the cover circle reached it. Transitions and the
  revealed state now control visibility directly.
- SpoilerController defaults to enabled (fail closed) so a seeded mask
  still can't flash secret text before the first initializeParticles.
- Rewrote _paintChildWithRevealSpot with compositing primitives
  (pushClipPath + ShaderMaskLayer): the child paint pushes its own
  filter layer, which finalizes and replaces the context canvas — the
  cached canvas's restore hit a dead native peer (crashed in tests) and
  canvas clips never propagated into the pushed layers at all.
- Test migration: logic tests opt out of the default fade again
  (fadeConfig: null — the pre-refactor enableFadeAnimation: false
  semantics), fade tests pump past the full 550ms sweep.
- A tap consumed by spoiler toggle also reaches the field, whose
  tap-on-focused-field behavior pops the selection toolbar (Select All
  on a collapsed selection). The wrapper interposes every toolbar build
  via contextMenuBuilder, so the menu is suppressed for 500ms after a
  consumed tap — reveal toggles no longer surface editing UI.
- Position-dependent reveal duration floored at 220ms instead of 80ms:
  off-center taps on tall regions compressed the whole sweep into ~5
  frames, reading as an instant disappearance even when correct.
pushClipPath shifts both the bounds rect and the clip path by the
offset internally (framework contract — RenderClipPath passes
Offset.zero & size). Passing paintBounds.shift(offset) double-shifted
the bounds; in non-compositing paints the bounds becomes a real clip
rect, so content at large offsets (text fields deep in a scrolled
page) was culled entirely — rendering black outside the spoiler rect.
Ballistic drift and ripple velocity injections are unconfined, so specks free-streamed out of the spoiler region — on the overlay pipeline, which has no particle clip, they rendered across the whole screen. Emitter semantics self-heal: a speck leaving its region dies and respawns inside it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant