Skip to main content

Glass

Struct Glass 

Source
pub struct Glass { /* private fields */ }

Implementations§

Source§

impl Glass

Source

pub const fn new() -> Self

Source

pub const fn frosted(blur: f32) -> Self

Source

pub const fn blur(self, radius: f32) -> Self

Source

pub const fn tint(self, tint: Color) -> Self

Source

pub const fn refraction(self, amount: f32) -> Self

Source

pub const fn dispersion(self, amount: f32) -> Self

Source

pub const fn highlight(self, amount: f32) -> Self

Source

pub const fn edge_width(self, width: f32) -> Self

Source

pub const fn shadow(self, amount: f32) -> Self

Source

pub const fn saturation(self, amount: f32) -> Self

Source

pub const fn light(self, at: Point, strength: f32, reach: f32) -> Self

Source

pub const fn rim_light(self, angle: f32, fill: f32) -> Self

Aims the light that catches the rim: angle is where it shines from, in radians clockwise from straight up, and fill is how much of it bounces onto the opposite edge.

Trait Implementations§

Source§

impl Clone for Glass

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Glass

Source§

impl Debug for Glass

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Glass

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Glass

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl ShaderEffect for Glass

Source§

const WGSL: &'static str = const RIM_WIDTH: f32 = 1.5; const SHADOW_REACH: f32 = 22.0; const SHADOW_DROP: f32 = 6.0; const CONTACT_REACH: f32 = 5.0; const CONTACT_DROP: f32 = 1.5; const LUMA: vec3<f32> = vec3<f32>(0.2126, 0.7152, 0.0722); fn effect(in: EffectInput) -> vec4<f32> { let tint = param(0); let optics = param(1); let finish = param(2); let pointer = param(3); let shadow_amount = finish.x; let texel = 1.0 / scale_factor(); var shadow = 0.0; if (shadow_amount > 0.0) { let dropped = shape_sdf(in.local - vec2<f32>(0.0, SHADOW_DROP)); let soft = clamp(1.0 - dropped / SHADOW_REACH, 0.0, 1.0); let grounded = shape_sdf(in.local - vec2<f32>(0.0, CONTACT_DROP)); let contact = clamp(1.0 - grounded / CONTACT_REACH, 0.0, 1.0); shadow = shadow_amount * (0.75 * soft * soft * soft + 0.25 * contact * contact) * (1.0 - in.coverage); } if (in.coverage <= 0.0 && shadow <= 0.0) { discard; } let e = vec2<f32>(texel, 0.0); let gradient = vec2<f32>( shape_sdf(in.local + e.xy) - shape_sdf(in.local - e.xy), shape_sdf(in.local + e.yx) - shape_sdf(in.local - e.yx), ); let normal = gradient / max(length(gradient), 1e-4 * texel); let edge = max(optics.w, texel); let depth = max(-in.distance, 0.0); let rim = clamp(1.0 - depth / edge, 0.0, 1.0); let bend = 1.0 - sqrt(1.0 - rim * rim); let offset = -normal * bend * optics.x * edge * 2.0; let spread = offset * optics.y; let r = sample_backdrop(in.local + offset + spread).r; let g = sample_backdrop(in.local + offset).g; let b = sample_backdrop(in.local + offset - spread).b; var color = vec3<f32>(r, g, b); color = mix(vec3<f32>(dot(color, LUMA)), color, finish.y); color = mix(color, tint.rgb, tint.a); let light = vec2<f32>(sin(pointer.z), -cos(pointer.z)); let facing = dot(normal, light); let key = max(facing, 0.0); let fill = max(-facing, 0.0); let glint = 0.15 + 0.85 * key * key + pointer.w * fill * fill; let line = clamp(1.0 - depth / RIM_WIDTH, 0.0, 1.0); let bloom = rim * rim * rim; let sheen = line * glint + bloom * glint * 0.22 + bend * 0.12; let away = (in.local - finish.zw) / max(pointer.y, 1.0); let spot = exp(-dot(away, away)) * pointer.x; let caught = spot * (line * 0.8 + bloom * 0.3 + 0.05); color += vec3<f32>(sheen * optics.z + caught); let glass = clamp(color, vec3<f32>(0.0), vec3<f32>(1.0)) * in.coverage; return vec4<f32>(glass, in.coverage + shadow); }

Source§

const INPUTS: Inputs = Inputs::BACKDROP

Source§

fn uniforms(&self, uniforms: &mut [f32; 16])

Source§

fn margin(&self) -> f32

Source§

fn backdrop_blur(&self) -> f32

Source§

fn backdrop_reach(&self) -> Option<f32>

Source§

const CLOCK: Option<usize> = None

Source§

fn content_blur(&self) -> f32

Source§

impl StructuralPartialEq for Glass

Auto Trait Implementations§

§

impl Forget for Glass

§

impl Freeze for Glass

§

impl Move for Glass

§

impl RefUnwindSafe for Glass

§

impl Send for Glass

§

impl Sync for Glass

§

impl Unpin for Glass

§

impl UnsafeUnpin for Glass

§

impl UnwindSafe for Glass

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,