Class 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intNumber of optics parameters.static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final int -
Method Summary
Modifier and TypeMethodDescriptionstatic voidapply(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.static floatdisplacement(float s, float h, float max) Outward displacement of a pointspixels inside a rim of bevel heighth.static intmargin(float[] optics) How far outside the lens rectangle the effect reaches (the shadow and the outline ring), in pixels.static intreach(float[] optics) How far outside the painted area the refraction may sample, in pixels.
-
Field Details
-
BEVEL
public static final int BEVEL- See Also:
-
MAX_SHIFT
public static final int MAX_SHIFT- See Also:
-
DISPERSION
public static final int DISPERSION- See Also:
-
OUTLINE
public static final int OUTLINE- See Also:
-
OUTLINE_WIDTH
public static final int OUTLINE_WIDTH- See Also:
-
RIM_LIGHT
public static final int RIM_LIGHT- See Also:
-
RIM_LIGHT_VERTICAL
public static final int RIM_LIGHT_VERTICAL- See Also:
-
RIM_WIDTH
public static final int RIM_WIDTH- See Also:
-
END_SHADE
public static final int END_SHADE- See Also:
-
END_SHADE_WIDTH
public static final int END_SHADE_WIDTH- See Also:
-
BRIGHTNESS
public static final int BRIGHTNESS- See Also:
-
SHADOW
public static final int SHADOW- See Also:
-
SHADOW_WIDTH
public static final int SHADOW_WIDTH- See Also:
-
COUNT
public static final int COUNTNumber of optics parameters.- See Also:
-
-
Method Details
-
margin
public static int margin(float[] optics) How far outside the lens rectangle the effect reaches (the shadow and the outline ring), in pixels. -
reach
public static int reach(float[] optics) How far outside the painted area the refraction may sample, in pixels. -
displacement
public static float displacement(float s, float h, float max) Outward displacement of a pointspixels inside a rim of bevel heighth. -
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) Applies the lens.
Parameters
-
src: the surface,sw * shARGB pixels, read only -
sw: source width -
sh: source height -
dst: receives the result for the output area,ow * ohpixels -
ox: the output area's left edge insidesrc -
oy: the output area's top edge insidesrc -
ow: output width -
oh: output height -
lx: the lens rectangle's left edge insidesrc(may be fractional) -
ly: the lens rectangle's top edge insidesrc -
lw: lens width -
lh: lens height -
cornerRadius: corner radius in pixels, negative for a capsule -
optics:COUNTparameters, see the constants -
amount: overall strength 0..1
-
-