sdfToSmoothStroke

a signed distance field to a smooth stroke with anti-aliasing.

110 total functionsUpdated: Invalid Date

sdfToSmoothStroke

a signed distance field to a smooth stroke with anti-aliasing.

Parameters

NameTypeDescription
signedDistancef32Signed distance field value.
thicknessf32Stroke thickness.
centerf32Center distance for the stroke.
smoothingf32Smoothing factor for anti-aliasing.

Returns

f32stroke value between 0.0 and 1.0.

WGSL Code

fn sdfToSmoothStroke(signedDistance: f32, thickness: f32, center: f32, smoothing: f32) -> f32 {
let distance = abs(signedDistance - center);
return 1.0 - smoothstep(thickness * 0.5 - smoothing, thickness * 0.5 + smoothing, distance);
}

About wgsl-fns

A JavaScript library providing WGSL utility functions as strings for WebGPU shader development. Includes mathematical utilities, noise generation, signed distance fields, and color manipulation functions.

Install:npm install wgsl-fns
Import:import { sdfToSmoothStroke, getFns } from 'wgsl-fns'
Usage:getFns(['sdfToSmoothStroke'])