sdfCylindricalRepeat

cylindrical coordinate repetition.

110 total functionsUpdated: Invalid Date

sdfCylindricalRepeat

cylindrical coordinate repetition.

Parameters

NameTypeDescription
positionvec3<f32>3D position to transform.
angleRepeatf32Angular repetition count.
heightRepeatf32Height repetition interval.
axisvec3<f32>Cylindrical axis (should be normalized).

Returns

vec3<f32>repeated position.

WGSL Code

fn sdfCylindricalRepeat(position: vec3<f32>, angleRepeat: f32, heightRepeat: f32, axis: vec3<f32>) -> vec3<f32> {
let n = normalize(axis);
// Project onto axis for height
let h = dot(position, n);
let radial = position - h * n;
// Repeat in height
let newH = h - heightRepeat * round(h / heightRepeat);
// Repeat in angle
let radius = length(radial);
if (radius < 0.001) {
return newH * n;
}
let angle = atan2(radial.y, radial.x);
let sectorAngle = 6.28318530718 / angleRepeat;
let newAngle = angle - sectorAngle * round(angle / sectorAngle);
let newRadial = radius * vec2<f32>(cos(newAngle), sin(newAngle));
// This assumes axis is along Z - for general axis, need proper basis vectors
return newH * n + vec3<f32>(newRadial.x, newRadial.y, 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 { sdfCylindricalRepeat, getFns } from 'wgsl-fns'
Usage:getFns(['sdfCylindricalRepeat'])