sdfSphere

a signed distance field for a sphere.

110 total functionsUpdated: Invalid Date

sdfSphere

a signed distance field for a sphere.

Parameters

NameTypeDescription
positionvec3<f32>3D position to evaluate.
radiusf32Radius of the sphere.

Returns

f32distance to the sphere surface.

WGSL Code

fn sdfSphere(position: vec3<f32>, radius: f32) -> f32 {
return length(position) - 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 { sdfSphere, getFns } from 'wgsl-fns'
Usage:getFns(['sdfSphere'])