sdfRhombus

a signed distance field for a rhombus.

110 total functionsUpdated: 30/07/2026

sdfRhombus

a signed distance field for a rhombus.

Parameters

NameTypeDescription
positionvec3<f32>3D position to evaluate.
dimensionsvec3<f32>Dimensions of the rhombus.
sharpnessf32Sharpness factor for the edges.

Returns

f32distance to the rhombus surface.

WGSL Code

fn sdfRhombus(position: vec3<f32>, dimensions: vec3<f32>, sharpness: f32) -> f32 {
  var p = abs(position);
  let b = dimensions;
  let e = sharpness;
  
  // Calculate distance to rhombus
  p = p - b;
  let q = abs(p.x + p.y + p.z) + e;
  let h = max(vec3<f32>(q) - vec3<f32>(e), vec3<f32>(0.0));
  
  return min(max(p.x, max(p.y, p.z)), 0.0) + length(h);
}

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