sdfIcosahedron

a signed distance field for an icosahedron.

110 total functionsUpdated: Invalid Date

sdfIcosahedron

a signed distance field for an icosahedron.

Parameters

NameTypeDescription
positionvec3<f32>3D position to evaluate.
sizef32Size of the icosahedron.

Returns

f32distance to the icosahedron surface.

WGSL Code

fn sdfIcosahedron(position: vec3<f32>, size: f32) -> f32 {
var p = position;
let s = size;
// Constants for icosahedron
let phi = 1.618033988749895;
let a = s;
let b = s * phi;
// Compute distance to icosahedron
p = abs(p / s);
let d = p.x * p.y * p.z;
let m = max(max(p.x, p.y), p.z);
let n = min(min(p.x, p.y), p.z);
let mid = p.x + p.y + p.z - m - n;
// Calculate the signed distance
let q = select(mid, d, m < phi * n);
return (length(p) - phi) * s;
}

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