Thanh Ngo
Writing

Design · Tech20 min read

Gravitationally Lensed UI

Apple’s Liquid Glass relies on classical optics: light hits a boundary, refracts, and passes through. What if interface physics operated on General Relativity instead?

Thanh Ngo

Give a UI widget virtual mass, and it warps the space around it. Background pixels pull into arcs, and the page appears to bend along an active gravitational field.

Interacting with a widget adds mass, so the page bends around what you use.

Here for the demos? Skip the physics and jump straight to the live Music, Chat, and Weather prototypes.

Before you try it: This only works in Chromium browsers (Chrome, Edge, Arc). Safari, Firefox, and all iOS browsers don't yet support SVG filters inside backdrop-filter.

The physics: from starlight to pixels

Mass curves spacetime, and curved spacetime bends light.

We see this in deep space all the time: light from a distant galaxy bends around a heavy foreground cluster, stretching into an arc — or a full circle called an Einstein ring.

Drag the nearby galaxy. Off-centre, the far one stretches into an arc. Lined up, it becomes a ring.

Why it matters: Bending light changes where things appear to be and stretches their shape. Every active widget does the same thing to the elements behind it.

Starlight grazing the Sun's edge bends by 1.75 arcseconds — about 1/2000 of a degree — first measured during the 1919 solar eclipse. Across cosmic distances, even a tiny angle shifts where a star appears in the sky.

The lens equation

The gravitational lens equation connects where a background star appears to be (θ) to where it actually is (β):

β=θ−(θE)2θ
  • θ (theta): Where the star appears to be, measured as an angle from the lens centre.
  • β (beta): Where the star actually is.
  • θE (theta-E): The Einstein radius, which grows with the square root of the lens's mass.

In other words: Gravity pulls passing light inward, which makes the background image look pushed outward. Objects behind the mass appear magnified and stretched into curved arcs around it.

starseengalaxyβθθEyou
What you see
Where the star is
Galaxy's mass
β = θ − (θE)² / θ=44.3 − 36.4² / 44.3=14.4
Slide the star and the galaxy's mass. Left: how the light bends. Right: what you see.

The ring: When a star sits directly behind the mass (β = 0), its light bends equally around every side and meets at θ = θE, forming an Einstein ring. In our UI model, every active widget calculates its own θE in screen pixels.

What carries over to UI:

  • Stronger pull up close: In space, the bend weakens with distance from the mass's centre (1/θ). On screen, it weakens with distance from the widget's edge, so elements nearest the widget get pushed outward the most.
  • No blur: Gravity bends light without scattering it, so background content stays crisp instead of frosted.
  • No colour splitting: Glass bends blue light more than red, causing rainbow fringes. Because gravity curves spacetime itself, all colours follow the exact same path.

From light to pixels

1. Side on: light bends past the widget on its way to you.

Play or pick a step to see the bend from the side, then from the front.

On screen, the widget is the foreground galaxy and the scrolling page is the starfield behind it.

In the lens equation above, the amount light bends is (θE)² / θ. To turn that into a screen-space pull vector, a, around a widget, we make two adjustments:

  1. Pixels (E² / d): Measure the distance d and the Einstein radius E in pixels instead of sky angles.
  2. Shape (n̂): Measure d from the widget's nearest edge, and point the pull outward along n̂, so gravity wraps evenly around rounded rectangles, pills, and circles.

Two optimizations then keep the pull finite and cheap to draw:

  1. Soften (+ c): Add a small constant c, a trick from astrophysics simulations called gravitational softening, so d = 0 at the border no longer divides by zero.
  2. Fade (· f): Taper the pull smoothly to zero at d = 4E, so the browser bends only a small patch around the widget.
1. A point mass pulls equally in every direction, and less with distance: E² / d.
da0d, from the pointE² / d
Step through how a point mass's pull adapts to a widget's shape.

Put those together, and you get the pull vector for every pixel around the widget:

a→=E2d+c·f·n^
  • E: Einstein radius in pixels (virtual mass grows as E²).
  • d: Distance in pixels to the nearest widget edge (0 at the border).
  • c: Softening constant, set per widget, that caps the bend at the edge.
  • f: Inverted cubic smoothstep that fades the pull from 1 at the edge to 0 at d = 4E: f = 1 − 3t² + 2t³, with t = min(d / 4E, 1).
  • n̂: Unit vector pointing straight outward from the nearest edge or corner.

The sampling rule

Split the deflection a into horizontal and vertical screen shifts (a_x, a_y), and you get the rule for every visible pixel:

out(x,y)=in(x−ax,y−ay)
  • in: Where the page actually sits in the DOM.
  • out: Where you see it on screen.

Because gravity pushes apparent positions outward by a, the renderer looks backward to draw each pixel. To paint (x, y), it samples the page from (x − a_x, y − a_y) — one step closer to the widget.

Running it in the browser

Real-time canvas or WebGL shaders can't easily read and bend a live, scrolling DOM tree, for security and performance reasons.

The browser-native workaround is CSS backdrop-filter paired with an SVG feDisplacementMap.

feDisplacementMap shifts pixels using the red and green channels of a second image — the displacement map:

  • Red channel (X axis): Shifts pixels left or right. 128 means no movement; above 128 shifts right, below 128 shifts left.
  • Green channel (Y axis): Shifts pixels up or down. 128 means no movement; above 128 shifts down, below 128 shifts up.
  • Blue and alpha: Ignored (B = 128, A = 255).
R200
G80
Moves 23 px right, 15 px up
Drag R and G. Dark moves left or up, bright moves right or down, and 128 stays put. The arrow blends both colours.

Given byte values R and G (0 to 255) and a filter scale factor −s, feDisplacementMap calculates:

out(x,y)=in(x−s(R255−12),y−s(G255−12))

Match that to the gravitational deflection rule, and you get the channel values:

R(x,y)=255·(12+ax(x,y)s)G(x,y)=255·(12+ay(x,y)s)

Behind the scenes, an offscreen <canvas> draws this map by calculating the distance and outward direction for every pixel around the widget.

Displacement map
Actual displacement
x displacement
y displacement
Displacement magnitude
Weight, E
20 px
Width
44 px
Height
44 px
Corner
22 px
a = 20² / (d + 28)
reach 80 px · strongest 14.3 px
Pick a point or drag a surface. Red is sideways, green is vertical, brown is both.

Why the pull stops at 4E

Each widget has an invisible field around it, extending 4E past its edges. That field uses backdrop-filter: url(#lens) to bend whatever is behind it — text, images, lists — in real time.

In real space, gravity never hits zero — it just gets weaker with distance.

On screen, rendering that long tail isn't worth the cost, so we smoothly taper the pull to zero at 4E:

  • Smaller filter area: A 4E reach keeps the filter patch tight around the widget.
  • Cheaper frames: Smaller filter patches mean faster re-renders when content scrolls underneath.
  • A calm page: Beyond 4E, pixels stay completely untouched.
  • No visible seam: Fading the formula smoothly to zero across the 4E reach prevents any sharp jump at the boundary.

When widgets get heavy

If every control had gravity all the time, the UI would feel unstable. Constant warping tires your eyes, and clicks would miss — because where you see something isn't where the browser thinks it is.

  • At rest, most controls are flat: Buttons, sliders, and switches stay at E = 0. Text stays readable, and what you click is what you get. Floating surfaces are the exception.
  • Attention adds a little mass: Hover or focus gives an element mild gravity. Pressing down adds more.
  • Actions send a ripple: Clicks, toggles, and opening a modal create a short mass pulse — a “gravitational wave” — that fades back to normal.
  • Floating bars stay heavy: Navigation bars keep their mass, so content visibly warps as it scrolls underneath.
  • Holding and dragging make things heavier: The longer you hold, or the farther you swipe, the stronger the pull.
  • Values can set the mass: A continuous control can map its state to gravity — for example, volume scaling E from 4 to 24.

Accessibility note: Respect prefers-reduced-motion. If a user asks for less motion, keep the lens off, or cap it at the lightest mass. The effect should never be the only way to tell what's interactive.

Mass tokens

TokenE (px)Application
feather6Micro-controls under pointer focus
light10Primary buttons on hover; pressed micro-targets; active toasts
medium14Primary button presses; transition pulses; open menus; floating bars
heavy20Pulsing actions; dragged rows; Music's player bar; Chat's input dock
massive28Active typing state on input bars

Working prototypes

Music

A music player. Its bar stays heavy, so track rows bend as they scroll under it. Dragging the seek thumb adds mass, and the volume slider pulls harder the louder it goes.

Welcome back
Jump back in
Made for you
Popular songs
1Slow LightMira Tanaka4,182,9063:42
2Small and HeavyMira Tanaka3,051,5594:17
3Paper MoonsMira Tanaka, Ode2,760,1142:58
4Einstein RingMira Tanaka2,201,7763:55
5Lamp StreetMira Tanaka1,904,3373:26
Your playlists
Slow Light
Mira Tanaka
0:00
3:42
Welcome back
Jump back in
Made for you
Popular songs
1Slow LightMira Tanaka4,182,9063:42
2Small and HeavyMira Tanaka3,051,5594:17
3Paper MoonsMira Tanaka, Ode2,760,1142:58
4Einstein RingMira Tanaka2,201,7763:55
5Lamp StreetMira Tanaka1,904,3373:26
Your playlists
Slow Light
Mira Tanaka
0:00
3:42
Slow LightMira Tanaka
Tap the song in the bar for Now Playing.

Chat

A messaging app. Press and hold a message, and it gains mass until its menu opens. The bend around it shows how close the menu is.

Monday 19:04
Yesterday 21:12
Today 09:02
Mira Tanaka
online

Weather

A weather app over rain, clouds, and stars, which bend under its bottom bar as the forecast scrolls. Dragging along the temperature curve bends it around the cursor. Lensing needs detail like this: a flat background gives it nothing to bend.

Lisbon09:4118°SunnyH:21° L:14°
Hourly forecastSunny all morning. Clouds build after 16:00, with a chance of showers tonight.
Temperature
10-day forecast
Feels like18°Close to the real temperature.
Humidity64%Comfortable.
Wind
UV index4Moderate
Sunset17:28Sunrise 07:16
Visibility16 kmA perfectly clear view.
London09:4111°RainH:12° L:8°
Hourly forecastRain all day, heaviest this evening. Drier by tomorrow afternoon.
Temperature
10-day forecast
Feels like8°The wind makes it feel colder.
Humidity92%The air is damp.
Wind
UV index1Low
Sunset16:20Sunrise 07:05
Visibility6 kmRain or snow is closing in.
Yellow warning: rainHeavy rain from 18:00 to midnight. Some roads may flood.
Reykjavík09:41-2°SnowH:0° L:-4°
Hourly forecastLight snow until noon. Clearing tonight, with a good chance of auroras.
Temperature
10-day forecast
Feels like-7°The wind makes it feel colder.
Humidity81%Comfortable.
Wind
UV index0Low
Sunset16:23Sunrise 09:58
Visibility4 kmRain or snow is closing in.
Tokyo18:4115°ClearH:19° L:11°
Hourly forecastClear and calm tonight. Sunny tomorrow, with a light breeze.
Temperature
10-day forecast
Feels like14°The wind makes it feel colder.
Humidity55%Comfortable.
Wind
UV index0Low
Sunset16:39Sunrise 06:05
Visibility20 kmA perfectly clear view.
Swipe between cities. Drag the temperature curve: warmer hours weigh more.

Technical constraints

  • Chromium-only for now: Only Chromium engines (Chrome, Edge, Arc) allow backdrop-filter to reference an SVG filter. Safari, Firefox, and all iOS browsers ignore it.
  • 8-bit colour limit: Each channel in feDisplacementMap only has 256 steps (0–255). On very wide bends, stretching those 256 steps across a large pixel range can cause subtle stair-stepping along sharp edges.

What this proves — and what it doesn't

It proves you can build a coherent, physics-grounded interaction model out of a single idea — mass — and run it in a real browser with native filters, no WebGL required.

It doesn't prove lensing is better than refraction for everyday UI. It's heavier, it only works in Chromium, and it has to be used sparingly or it gets in the way.

That's the point, though. Liquid Glass asks: “What if UI were glass?” This asks: “What if UI had gravity?” The answer isn't a new default. It's a new material to reach for when weight, attention, and motion are the point.

Tech15 min read

Texting my Mac Studio

Did you know that you can text my Mac Studio when visiting my site?

Read Texting my Mac Studio
Tech5 min read

Tool Islets

Working with Google's internal tools taught me the joy of small, focused applications. I am now recreating that world.

Read Tool Islets