xyz2equirect: Cartesian to Equirectangular Conversion
Spherical coordinate projection
The xyz2equirect function converts 3D Cartesian coordinates on the unit sphere to equirectangular UV coordinates. This is the inverse operation of equirect2xyz, mapping 3D directions back to panoramic image coordinates:
Where represents azimuth and represents elevation angle from the north pole.
Direction Mapping
3D Direction | UV Output | Description |
---|---|---|
East (right) | ||
West (left) | ||
North pole (top) | ||
South pole (bottom) | ||
Forward (front) |
Live Editor
const fragment = () => { const center = vec2(0.5) const radius = length(uv.sub(center)) const dir = normalize(vec3(uv.sub(center), sqrt(max(0, float(0.25).sub(radius.mul(radius)))))) const equiUV = xyz2equirect(dir) const pattern = sin(equiUV.x.mul(20)).mul(sin(equiUV.y.mul(15))) const color = vec3(pattern.mul(0.5).add(0.5)) return vec4(color, 1) }