sdfSmoothSubtract

one SDF from another with smooth blending.

110 total functionsUpdated: Invalid Date

sdfSmoothSubtract

one SDF from another with smooth blending.

Parameters

NameTypeDescription
distanceAf32First signed distance field.
distanceBf32Second signed distance field to subtract.
smoothingf32Smoothing factor for the blend.

Returns

f32subtracted signed distance field.

WGSL Code

fn sdfSmoothSubtract(distanceA: f32, distanceB: f32, smoothing: f32) -> f32 {
let h = clamp(0.5 - 0.5 * (distanceB + distanceA) / smoothing, 0.0, 1.0);
return mix(distanceA, -distanceB, h) + smoothing * h * (1.0 - h);
}

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 { sdfSmoothSubtract, getFns } from 'wgsl-fns'
Usage:getFns(['sdfSmoothSubtract'])