Parameters
| Name | Type | Description |
|---|---|---|
| position | vec3<f32> | 3D position to transform. |
| phiRepeat | f32 | Azimuthal angle repetition count. |
| thetaRepeat | f32 | Polar angle repetition count. |
Returns
vec3<f32>repeated position.
WGSL Code
fn sdfSphericalRepeat(position: vec3<f32>, phiRepeat: f32, thetaRepeat: f32) -> vec3<f32> { let radius = length(position); if (radius < 0.001) { return position; } // Convert to spherical coordinates let theta = acos(clamp(position.z / radius, -1.0, 1.0)); let phi = atan2(position.y, position.x); // Repeat in spherical coordinates let phiSector = 6.28318530718 / phiRepeat; let thetaSector = 3.14159265359 / thetaRepeat; let newPhi = phi - phiSector * round(phi / phiSector); let newTheta = theta - thetaSector * round(theta / thetaSector); // Convert back to Cartesian let sinTheta = sin(newTheta); return radius * vec3<f32>( sinTheta * cos(newPhi), sinTheta * sin(newPhi), cos(newTheta) ); }