> ## Documentation Index
> Fetch the complete documentation index at: https://glassen.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Shape glass with paths and masks

> Build reusable glass outlines from SVG paths or canvas alpha, including concave shapes and holes, while retaining the same spring and hit testing.

Glassen accepts a filled SVG path or a canvas alpha mask. Rust builds a signed distance field once; the field supplies both shading and hit testing during stretch.

```js theme={null}
import { createPathShape } from 'glassen'

const heart = await createPathShape(
  'M50 90 C10 65 0 35 20 20 C35 10 45 20 50 30 C55 20 65 10 80 20 C100 35 90 65 50 90 Z',
  { viewBox: [0, 0, 100, 100], padding: 0.12, resolution: 512 },
)
const lens = surface.add(element, { shape: heart })
// Remove all consumers before freeing the shape.
// lens.destroy()
// heart.destroy()
```

`createPathShape(path, options)` accepts path data, not an SVG document. Defaults are `viewBox: [0,0,100,100]`, `padding: 0.12`, `resolution: 512` and `fillRule: 'nonzero'`. Use `fillRule: 'evenodd'` for a path with holes.

## Canvas masks

```js theme={null}
import { createMaskShape } from 'glassen'

const ring = await createMaskShape({
  resolution: 512,
  draw(pen, size) {
    pen.beginPath()
    pen.arc(size / 2, size / 2, size * 0.38, 0, Math.PI * 2)
    pen.arc(size / 2, size / 2, size * 0.22, 0, Math.PI * 2, true)
    pen.fill('evenodd')
  },
})
```

The callback receives a cleared canvas with white fill. Alpha defines the filled area, so you can draw paths or text with native canvas APIs. Wait for fonts before drawing text. The mask must have a filled area and a transparent outer border.

Resolution must be an integer from 16 to 1024. Share one shape object across lenses and retain it through context restoration. `lens.update({ shape: null })` restores the default orb.

Filtered shading normals reduce raster spikes, but a finite-resolution mask cannot reproduce arbitrarily thin features. Inspect corners, holes, minification and stretched silhouettes at the sizes you ship. Custom shapes use the same screen-space optical approximation; they are not solid meshes with modeled wall thickness.

The web adapter supports these masks. The preserved Metal host does not yet bind custom fields; see [porting](https://glassen.mintlify.site/porting.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.