Skip to main content
Rust owns lens geometry, motion and appearance. Hosts supply input, pixels and a clock, and draw with the shared shader. Preserve the existing geometry and optics when changing packaging or adapters.

Web sources

GlassSource offers sample(frame) for images/canvases or createRenderer(gl) for a GPU producer. A GPU renderer returns {target, version}; the target has texture, framebuffer, width, height, bytes and dispose(). It belongs to the supplied WebGL 2 context. The host disposes the renderer, which disposes its own targets; shared resources stay with their actual owner. A source can be mounted on multiple surfaces, so every createRenderer call must allocate independent context-local resources. setActive(active, owner) distinguishes those consumers. GPU textures use bottom-left texture coordinates and premultiplied, display-encoded RGBA. Sampled DOM/canvas images use the browser’s top-left convention; the upload adapter handles it. Do not feed tone-mapped linear Three/pmndrs buffers directly; encode through the appropriate host adapter first. Versions identify pixel changes, including resize and configuration. Image sources should provide a new version for changed pixels; GPU renderers must return a version whenever their result changes. subscribe(notify) wakes a suspended surface after invalidation. No extra animation clock belongs inside a source adapter. GPU producers must establish their own draw state; the surface establishes its own state before drawing the scene and lenses. A source should not change framebuffer orientation. Context loss releases source renderers; restoration creates them again. Constructors must clean up partial allocations if they fail. Dispose is idempotent.

Custom renderers

glassen/glsl exports the generated shader body, not a complete drop-in material. It expects seven geometry float4 slots, four appearance slots, tap, baseTap and the binding macros used by www/goo/orb/glass.js. These reference sources, the Rust layout in crates/glass-core/src/ and crates/glass-core/shaders/orb.h are included in the package. They document the host bindings; they are not a standalone native SDK. Do not hand-edit the generated bindings or duplicate core motion in JavaScript/Swift. The default field is a smooth union of circles. Custom outlines use Rust’s DistanceField from square alpha coverage. Each texel contains distance in core canvas units, outward normal X/Y, and 1. Distances are negative inside; rows run downwards. Normals use a filtered derivative to avoid magnifying raster slope noise into refraction spikes. Coverage and CPU hit testing retain the unfiltered distance. Generation uses sdf_glyph_renderer without its FreeType feature. The WebGL host uploads RGBA16F with linear filtering and no mipmaps. shapeField(p) converts core coordinates to p / canvas + 0.5; ORB_SHAPE_SCALE selects and scales the custom field. Geometry slot 3.w carries that scale before the instanced vertex stage reuses the circle padding for the inverse transform. Zero retains the original orb. Hosts preserve the shape until all consumers are removed, including across context restoration. Metal hosts need equivalent texture bindings; the preserved Goop Metal adapter has not been extended or verified with custom masks. For scene-backed overlap, draw from back to front and snapshot completed layers before a dependent lens samples them. Do not sample the texture currently attached as the draw destination. The web surface batches independent paint bounds, and reuses one GPU snapshot for overlap. Explicit source lenses retain their own source. The Three.js study uses two alternating render targets, with one instanced draw per generation. Its mesh adapter maps local refraction offsets into screen space through UV derivatives; sibling cubes share their generation’s backdrop. Before calling a host supported, execute its shaders and compare matched-time frames with the existing renderer, including light/dark, stretching, tiny/large lenses, source alpha, corners and resource disposal. Shader compilation alone does not validate the appearance. Native integration sources still depend on Goop; WebGPU and standalone iOS builds are not supplied here.