Skip to guide
Rainbow Lab/Documentation

Glass Foundry

Scripting reference

csharp
using GlassFoundry;
using UnityEngine;

public sealed class GlassExample : MonoBehaviour
{
    public GlassSource source;
    public GlassImage panel;

    public void UseFrost()
    {
        source.BlurSteps = 3;
        source.Downsample = GlassSource.Resolution.Quarter;
        source.UpdatesPerSecond = 30;
        source.Frozen = false;

        // Appearance returns a copy. Assigning it makes this panel local.
        var appearance = panel.Appearance;
        appearance.opacity = 0.35f;
        appearance.cornerRadius = 24;
        panel.Appearance = appearance;
    }
}

Assign panel.Style to follow a saved GlassStyle. Call panel.DetachStyle() to retain its appearance while removing the link. Call panel.RefreshAppearance() after changing a linked style's values through code.

source.RequestRefresh() requests one capture at the next render with a visible consumer. Frozen = true keeps the current output. Texture exposes that output for diagnostics; do not destroy it. CaptureCount, LastPassCount and ConsumerCount are simple counters, not CPU or GPU timings.

Set source.IncludeBackgroundUI = true to include Screen Space - Overlay graphics drawn before the first visible Glass Image using that source. Glass and its children are excluded. All panels on the source share that one background layer. Setting this property requests a refresh; switching it off also releases the cached UI geometry and materials. LastUIDrawCount reports the preceding capture's UI draws, including stencil cleanup draws. It is zero for a world-only capture. The option adds two render passes when that count is nonzero. Frozen captures retain their preceding counters until refreshed.

Source can be assigned at runtime. Panels sharing a source use the same background texture and base material. Set the Graphic's colour to white for the unmodified style; its alpha controls whole-panel fade and continues to respect CanvasGroup alpha.

Use GlassAppearance.Default for frosted glass or GlassAppearance.Clear for a clear starting point. Use the liquid preset for a broader lens:

csharp
panel.Appearance = GlassAppearance.Liquid;
var lens = panel.Appearance;
lens.clarity = 0.85f;
lens.lensWidth = 100; // Percentage: curve the whole image, regardless of size.
lens.refraction = 40;
lens.magnification = 0.15f;
lens.dispersion = 0.3f;
lens.sheen = 0.5f;
panel.Appearance = lens;

To colour the glass and soften detail behind its labels:

csharp
var appearance = panel.Appearance;
appearance.gradientTint = true;
appearance.tintMode = GlassTintMode.Filter;
appearance.secondaryTint = new Color(0.2f, 0.3f, 0.7f, 1);
appearance.gradientAngle = 45;
appearance.contrast = -0.2f;
appearance.lightRotation = 90;
panel.Appearance = appearance;

Gradient tint uses vertex colours. Contrast and light rotation use the existing vertex data. They keep the same four-vertex panel, shared material and background captures, and do not add texture lookups or blur passes. Setting gradientTint to false and the two adjustments to zero disables them.

Appearances with no lens settings keep the frosted rendering path. SharpTexture exposes the clear capture (or the available fallback); SharpOutput is null when no separate clear output is allocated. These textures belong to Glass Source. Three blur steps report six passes normally, or seven while a clear capture is requested. Background UI adds two more passes when it contains participating graphics. Panels use the same source material regardless of their optical settings.