sdfCylinder

a signed distance field for a cylinder.

110 total functionsUpdated: Invalid Date

sdfCylinder

a signed distance field for a cylinder.

Parameters

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

Returns

f32distance to the cylinder surface.

WGSL Code

fn sdfCylinder(position: vec3<f32>, radius: f32, height: f32) -> f32 {
let d = vec2<f32>(length(position.xz), abs(position.y)) - vec2<f32>(radius, height * 0.5);
return min(max(d.x, d.y), 0.0) + length(max(d, vec2<f32>(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 { sdfCylinder, getFns } from 'wgsl-fns'
Usage:getFns(['sdfCylinder'])