Parameters
Name | Type | Description |
---|---|---|
position | vec3<f32> | 3D position to transform. |
angleRepeat | f32 | Angular repetition count. |
heightRepeat | f32 | Height repetition interval. |
axis | vec3<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 heightlet h = dot(position, n);let radial = position - h * n;// Repeat in heightlet newH = h - heightRepeat * round(h / heightRepeat);// Repeat in anglelet 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 vectorsreturn newH * n + vec3<f32>(newRadial.x, newRadial.y, 0.0);}