public final class GlassLensBlend
- Object
- GlassLensBlend
Reference implementation of Graphics.glassLensRegion: the optics of a raised Liquid Glass lens (the lifted iOS 27 tab selection) laid over what is already painted. Ports without a native path run this; the Metal shader cn1_fs_glass_lens mirrors it.
The lens is a rounded rectangle (a capsule for a negative corner radius) whose
rim is a circular bevel of height bevel: a pixel s inside the rim shows the
surface displaced OUTWARDS along the rim’s normal by
D(s) = (h - s) / sqrt(1 - ((h - s) / h)^2) (h = bevel, zero beyond it) – the
refraction of a glass edge, which pulls whatever lies just outside the lens
(the edge of the bar it floats over, the backdrop) into its rim. The three
channels are displaced by D * (1 - dispersion), D and D * (1 + dispersion),
which fringes the rim. On top of that the surface:
- brightens by
brightnessinside; - darkens by up to
endShadein a bandendShadeWidthwide along the rim, weighted by how horizontal the rim’s normal is (the rounded ends); - is multiplied by
1 - outlineon a ringoutlineWidthwide just inside the rim; - gains a highlight of
rimLight + rimLightVertical * |ny|right inside that ring, decaying asexp(-d / rimWidth)with the depthdpast it; - casts a soft shadow of depth
shadowaround its lower half, a band that peaksshadowWidthoutside the rim and has the same width.
Lengths are in pixels, brightness levels in 0..1 units. Everything is mixed
with the untouched surface by amount.
Fields
Methods
public static int margin(float[] optics) | How far outside the lens rectangle the effect reaches (the shadow and the outline ring), in pixels. |
public static int reach(float[] optics) | How far outside the painted area the refraction may sample, in pixels. |
public static float displacement(float s, float h, float max) | Outward displacement of a point s pixels inside a rim of bevel height h. |
public static void apply(int[] src, int sw, int sh, int[] dst, int ox, int oy, int ow, int oh, float lx, float ly, float lw, float lh, float cornerRadius, float[] optics, float amount) | Applies the lens. |
Inherited methods
Field details
BEVEL
public static final int BEVEL = 0MAX_SHIFT
public static final int MAX_SHIFT = 1DISPERSION
public static final int DISPERSION = 2OUTLINE
public static final int OUTLINE = 3OUTLINE_WIDTH
public static final int OUTLINE_WIDTH = 4RIM_LIGHT
public static final int RIM_LIGHT = 5RIM_LIGHT_VERTICAL
public static final int RIM_LIGHT_VERTICAL = 6RIM_WIDTH
public static final int RIM_WIDTH = 7END_SHADE
public static final int END_SHADE = 8END_SHADE_WIDTH
public static final int END_SHADE_WIDTH = 9BRIGHTNESS
public static final int BRIGHTNESS = 10SHADOW
public static final int SHADOW = 11SHADOW_WIDTH
public static final int SHADOW_WIDTH = 12COUNT
public static final int COUNT = 13Method details
margin
public static int margin(float[] optics)reach
public static int reach(float[] optics)displacement
public static float displacement(float s, float h, float max)s pixels inside a rim of bevel height h.apply
public static void apply(int[] src, int sw, int sh, int[] dst, int ox, int oy, int ow, int oh, float lx, float ly, float lw, float lh, float cornerRadius, float[] optics, float amount)Parameters
srcint[]- the surface,
sw * shARGB pixels, read only swint- source width
shint- source height
dstint[]- receives the result for the output area,
ow * ohpixels oxint- the output area’s left edge inside
src oyint- the output area’s top edge inside
src owint- output width
ohint- output height
lxfloat- the lens rectangle’s left edge inside
src(may be fractional) lyfloat- the lens rectangle’s top edge inside
src lwfloat- lens width
lhfloat- lens height
cornerRadiusfloat- corner radius in pixels, negative for a capsule
opticsfloat[]COUNTparameters, see the constantsamountfloat- overall strength 0..1