Skip to content
All articles Optics and performance

How SVG Displacement Makes Liquid Glass Refract

Follow a rounded lens from geometry to a two-channel displacement image and an SVG filter.

An SVG displacement map is an image of offsets. Each map pixel tells the filter how far to sample the underlying picture along each axis. In QuickLiquid, the offsets follow the curved geometry of a glass rim.

From a rounded rectangle to a map

The renderer first measures the host and computes a signed distance for its rounded rectangle. Distance from the boundary determines where a pixel falls across the bezel. A precomputed refraction profile provides the displacement magnitude for that position, and the local direction supplies the horizontal and vertical components. The rasterizer focuses work on the curved band and mirrors symmetric pixels. Interior magnification can add a separate offset through the center.

From the map to bent pixels

QuickLiquid encodes the horizontal and vertical offsets as color-channel values in an image. The SVG graph loads that image with feImage and gives it to feDisplacementMap. Values near the middle of a channel represent a small or neutral offset. Values toward the ends sample farther away in either direction, with the filter scale controlling the strength. Tint and reflected light are layered separately from the offset field.

Move a vertical stripe across a glass panel in the playground and watch where it crosses the bezel. At default magnification the bend is concentrated near the rim. Increase magnification and compare the interior. The project's optics notes derive the profile and explain the 8-bit encoding. MDN's feDisplacementMap reference documents the SVG sampling operation.