sdfCone

a signed distance field for a cone.

110 total functionsUpdated: Invalid Date

sdfCone

a signed distance field for a cone.

Parameters

NameTypeDescription
positionvec3<f32>3D position to evaluate.
radiusf32Base radius of the cone.
heightf32Height of the cone.

Returns

f32distance to the cone surface.

WGSL Code

fn sdfCone(position: vec3<f32>, radius: f32, height: f32) -> f32 {
let q = vec2<f32>(length(position.xz), position.y);
let h = height;
let r = radius;
// Calculate distance
let d1 = -q.y - h;
let d2 = max(q.x * h - q.y * r, q.y * h + q.x * r);
return length(max(vec2<f32>(d1, d2), vec2<f32>(0.0))) + min(max(d1, d2), 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 { sdfCone, getFns } from 'wgsl-fns'
Usage:getFns(['sdfCone'])