sdfRoundedCylinder

a signed distance field for a rounded cylinder.

110 total functionsUpdated: Invalid Date

sdfRoundedCylinder

a signed distance field for a rounded cylinder.

Parameters

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

Returns

f32distance to the rounded cylinder surface.

WGSL Code

fn sdfRoundedCylinder(position: vec3<f32>, radius: f32, height: f32, roundness: f32) -> f32 {
// Calculate distances
let radiusOffset = radius - roundness;
let heightOffset = height * 0.5 - roundness;
// Generate rounded cylinder
let d = vec2<f32>(length(position.xz) - radiusOffset, abs(position.y) - heightOffset);
return min(max(d.x, d.y), 0.0) + length(max(d, vec2<f32>(0.0))) - roundness;
}

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