UNPKG

@playcanvas/splat-transform

Version:

Library and CLI tool for 3D Gaussian splat format conversion and transformation

22 lines (21 loc) 1.59 kB
/** * Equirect near-radius cull + spherical (atan2/asin) screen mapping + * pole-clamp setup used by the equirect Jacobian. * * Reads: cx, cy, cz, uniforms.near, uniforms.imageWidth, uniforms.imageHeight, * POLE_EPS (from constants chunk) * Defines: r2, r, rxz2, rxz, rxzClamped, invTwoPi, invPi, imgWf, imgHf, * lon, sinLat, lat, screenX, screenY * * Splats inside the near sphere (r <= near) are written invalid and the * shader returns. The longitude atan2 is undefined at the camera origin * and degenerates near the poles where rxz → 0; rxzClamped (>= POLE_EPS·r) * keeps every denominator in the Jacobian chunk finite for splats * arbitrarily close to the zenith / nadir. * * Convention: cy is the camera-down axis, so cy > 0 = below horizon → * lat > 0 → screenY in the bottom half. screenY = 0 maps to the zenith * (above the camera). */ declare const projectionEquirect = "\n let r2 = cx * cx + cy * cy + cz * cz;\n if (r2 <= uniforms.near * uniforms.near) { writeInvalid(i); return; }\n let r = sqrt(r2);\n let rxz2 = cx * cx + cz * cz;\n let rxz = sqrt(rxz2);\n let rxzClamped = max(rxz, POLE_EPS * r);\n\n let invTwoPi: f32 = 0.15915494309189535;\n let invPi: f32 = 0.3183098861837907;\n let imgWf = f32(uniforms.imageWidth);\n let imgHf = f32(uniforms.imageHeight);\n let lon = atan2(cx, cz);\n let sinLat = clamp(cy / r, -1.0, 1.0);\n let lat = asin(sinLat);\n let screenX = (lon * invTwoPi + 0.5) * imgWf;\n let screenY = (lat * invPi + 0.5) * imgHf;\n"; export { projectionEquirect };