sdfPolarRepeat

polar repetition around an axis.

110 total functionsUpdated: Invalid Date

sdfPolarRepeat

polar repetition around an axis.

Parameters

NameTypeDescription
positionvec3<f32>3D position to transform.
countf32Number of repetitions around the circle.
axisvec3<f32>Axis to repeat around (should be normalized).

Returns

vec3<f32>repeated position.

WGSL Code

fn sdfPolarRepeat(position: vec3<f32>, count: f32, axis: vec3<f32>) -> vec3<f32> {
let n = normalize(axis);
// Project position onto axis
let axisProj = dot(position, n) * n;
let radial = position - axisProj;
// Get angle in the plane perpendicular to axis
let radius = length(radial);
if (radius < 0.001) {
return position;
}
let angle = atan2(radial.y, radial.x);
let sectorAngle = 6.28318530718 / count;
let snappedAngle = round(angle / sectorAngle) * sectorAngle;
// Reconstruct position with snapped angle
let newRadial = radius * vec2<f32>(cos(snappedAngle), sin(snappedAngle));
// This assumes axis is along Z - for general axis, need proper basis vectors
return axisProj + 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 { sdfPolarRepeat, getFns } from 'wgsl-fns'
Usage:getFns(['sdfPolarRepeat'])