Avenra
Liquid GlassAPI Reference
Liquid GlassAPI Reference

Low-Level Functions

Core primitives for physics, SVG, and image data processing.

Low-Level Functions

These functions provide direct access to the underlying logic of Liquid Glass. Use them to build custom glass effects or integrate the refraction engine into other libraries.

Physics & Map Generation

compute1D

Calculates lateral displacement values based on Snell's Law.

  • Signature: compute1D(glassThickness, bezelWidth, profile, refractiveIndex, samples?)
  • Returns: number[] (default 128 samples).

compute2D

Wraps 1D displacement samples into a 2D map.

  • Signature: compute2D(w, h, radius, bezelWidth, md, map1D)
  • Returns: ImageData.

computeSpecular

Generates a physically-based rim-light specular highlight.

  • Signature: computeSpecular(w, h, radius, bezelWidth?)
  • Returns: ImageData.

buildMaps

A convenience wrapper that runs the full map generation pipeline.

  • Signature: buildMaps(cfg)
  • Returns: { dispUrl: string, specUrl: string, maxDisplacement: number }.

SVG & Rendering

createFilterSVG

Builds a new <filter> element with the Liquid Glass pipeline.

  • Signature: createFilterSVG(cfg)
  • Returns: { svg: SVGSVGElement, refs: FilterRefs }.

injectImages

Updates the displacement and specular image sources in an existing filter.

  • Signature: injectImages(refs, dispUrl, specUrl)

setScale

Updates the feDisplacementMap scale at runtime.

  • Signature: setScale(refs, scale)

Utilities

imageDataToURL

Converts ImageData to a base64 Data URL.

  • Signature: imageDataToURL(imageData)
  • Returns: string.

nextFilterId

Generates a unique filter ID string (e.g., lg-1).

  • Signature: nextFilterId(prefix?)

supportsBackdropFilter

Feature-detects support for SVG backdrop-filter with url().

  • Signature: supportsBackdropFilter()
  • Returns: boolean.

maxDisp

Returns the maximum absolute value in a 1D displacement map.

  • Signature: maxDisp(map1D)
  • Returns: number.

On this page