sdfRoundBox

a signed distance field for a rounded box.

110 total functionsUpdated: Invalid Date

sdfRoundBox

a signed distance field for a rounded box.

Parameters

NameTypeDescription
positionvec3<f32>3D position to evaluate.
sizevec3<f32>Half-extents of the box.
radiusf32Rounding radius for the edges.

Returns

f32distance to the rounded box surface.

WGSL Code

fn sdfRoundBox(position: vec3<f32>, size: vec3<f32>, radius: f32) -> f32 {
let q = abs(position) - size;
return length(max(q, vec3<f32>(0.0))) +
min(max(q.x, max(q.y, q.z)), 0.0) -
radius;
}

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