public final class GlassLensBlend

  1. Object
  2. 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 brightness inside;
  • darkens by up to endShade in a band endShadeWidth wide along the rim, weighted by how horizontal the rim’s normal is (the rounded ends);
  • is multiplied by 1 - outline on a ring outlineWidth wide just inside the rim;
  • gains a highlight of rimLight + rimLightVertical * |ny| right inside that ring, decaying as exp(-d / rimWidth) with the depth d past it;
  • casts a soft shadow of depth shadow around its lower half, a band that peaks shadowWidth outside 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

public static final int BEVEL = 0
public static final int MAX_SHIFT = 1
public static final int DISPERSION = 2
public static final int OUTLINE = 3
public static final int OUTLINE_WIDTH = 4
public static final int RIM_LIGHT = 5
public static final int RIM_LIGHT_VERTICAL = 6
public static final int RIM_WIDTH = 7
public static final int END_SHADE = 8
public static final int END_SHADE_WIDTH = 9
public static final int BRIGHTNESS = 10
public static final int SHADOW = 11
public static final int SHADOW_WIDTH = 12
public static final int COUNT = 13Number of optics parameters.

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 = 0

MAX_SHIFT

public static final int MAX_SHIFT = 1

DISPERSION

public static final int DISPERSION = 2

OUTLINE

public static final int OUTLINE = 3

OUTLINE_WIDTH

public static final int OUTLINE_WIDTH = 4

RIM_LIGHT

public static final int RIM_LIGHT = 5

RIM_LIGHT_VERTICAL

public static final int RIM_LIGHT_VERTICAL = 6

RIM_WIDTH

public static final int RIM_WIDTH = 7

END_SHADE

public static final int END_SHADE = 8

END_SHADE_WIDTH

public static final int END_SHADE_WIDTH = 9

BRIGHTNESS

public static final int BRIGHTNESS = 10

SHADOW

public static final int SHADOW = 11

SHADOW_WIDTH

public static final int SHADOW_WIDTH = 12

COUNT

public static final int COUNT = 13
Number of optics parameters.

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 point 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)
Applies the lens.

Parameters

src int[]
the surface, sw * sh ARGB pixels, read only
sw int
source width
sh int
source height
dst int[]
receives the result for the output area, ow * oh pixels
ox int
the output area’s left edge inside src
oy int
the output area’s top edge inside src
ow int
output width
oh int
output height
lx float
the lens rectangle’s left edge inside src (may be fractional)
ly float
the lens rectangle’s top edge inside src
lw float
lens width
lh float
lens height
cornerRadius float
corner radius in pixels, negative for a capsule
optics float[]
COUNT parameters, see the constants
amount float
overall strength 0..1