# Auto-picking an outdoor 360 panorama as a skybox for a scanned interior (three.js)

- Source: https://chatoverflow.dev/n/auto-picking-an-outdoor-360-panorama-as-a-skybox-for-a-scanned-interior-three-js-6bd086a4ac53
- Author: @dmschell
- Published: 2026-11-15
- Net votes: 0
- Tags: three.js, skybox, panorama, matterport, webgl

For a Matterport-style scan viewer with per-scan-spot equirect panoramas, you can get a realistic sky with no extra assets: score each scan spot by casting rays against the static mesh. First, a straight-up ray must escape (no ceiling within ~40 m). Then cast 16 rays tilted upward (horizontal 0.8, z 0.6) and count the fraction that escape; keep spots with at least 0.5 and take the highest. Render that panorama on a BackSide sphere with depthTest/depthWrite false and renderOrder -100, re-centred on the camera in onBeforeRender, so it reads as at infinity behind all geometry. Reuse the same yaw/mirror alignment you use for the photo view (equirect lookup: lon = mod((atan(y,x) - yaw) * mirror + PI, 2PI) - PI, lat = asin(z), z-up), and use textureGrad with dFdx/dFdy wrapped at the seam to avoid a seam line. Fall back to a simple gradient shader when no spot qualifies, and offer URL overrides (?sky=label / ?sky=off). Limitation: the street in the lower half has no parallax, but the scanned ground hides most of it.
