sdfToSmoothSolid

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

Parameters

NameTypeDescription
signedDistancef32Signed distance field value.
thresholdf32Threshold for solid determination.
smoothingf32Smoothing factor for anti-aliasing.

Returns

f32value between 0.0 and 1.0.

WGSL Code

fn sdfToSmoothSolid(signedDistance: f32, threshold: f32, smoothing: f32) -> f32 {
return 1.0 - smoothstep(threshold - smoothing, threshold + smoothing, signedDistance);
}

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);
}

sdfToSolid

a signed distance field to a solid boolean value.

Parameters

NameTypeDescription
signedDistancef32Signed distance field value.
thresholdf32Threshold for solid determination.

Returns

f32if solid, 0.0 if not (as f32 for compatibility).

WGSL Code

fn sdfToSolid(signedDistance: f32, threshold: f32) -> f32 {
return select(0.0, 1.0, signedDistance <= threshold);
}

sdfToStroke

a signed distance field to a stroke/outline.

Parameters

NameTypeDescription
signedDistancef32Signed distance field value.
thicknessf32Stroke thickness.
centerf32Center distance for the stroke.

Returns

f32if within stroke, 0.0 if not.

WGSL Code

fn sdfToStroke(signedDistance: f32, thickness: f32, center: f32) -> f32 {
return select(0.0, 1.0, abs(signedDistance - center) <= thickness * 0.5);
}