sdfBoxFrame

a signed distance field for a 3D box frame (hollow box).

110 total functionsUpdated: Invalid Date

sdfBoxFrame

a signed distance field for a 3D box frame (hollow box).

Parameters

NameTypeDescription
positionvec3<f32>3D position to evaluate.
sizevec3<f32>Half-extents of the box.
thicknessf32Wall thickness of the frame.

Returns

f32distance to the box frame surface.

WGSL Code

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

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