Skip to content
1        10        20        30        40        50        60        701import * as THREE from 'three';23// Dusk palette: a cool sky overhead, warm haze at the horizon, and dark4// street-level murk below it. The fog uses the horizon colour so distant5// blocks melt into the same light.6export const HORIZON = 0xc8b59a;7const ZENITH = new THREE.Color(0x4f6a86);8const HORIZON_C = new THREE.Color(HORIZON);9const MURK = new THREE.Color(0x5e5a50);1011const DOME_R = 850;1213function buildSky() {14  const geo = new THREE.SphereGeometry(DOME_R, 32, 18);15  const pos = geo.attributes.position;16  const colors = new Float32Array(pos.count * 3);17  const c = new THREE.Color();18  for (let i = 0; i < pos.count; i++) {19    const y = pos.getY(i) / DOME_R;20    if (y >= 0) {21      c.copy(HORIZON_C).lerp(ZENITH, Math.pow(y, 0.55));22    } else {23      c.copy(HORIZON_C).lerp(MURK, Math.min(1, -y * 5));24    }25    colors.set([c.r, c.g, c.b], i * 3);26  }27  geo.setAttribute('color', new THREE.BufferAttribute(colors, 3));28  const mat = new THREE.MeshBasicMaterial({29    vertexColors: true,30    side: THREE.BackSide,31    fog: false,32    depthWrite: false,33    toneMapped: false,34  });35  const sky = new THREE.Mesh(geo, mat);36  sky.renderOrder = -1;37  return sky;38}3940export function createAtmosphere(scene) {41  const sky = buildSky();42  scene.add(sky);4344  return {45    update(dt, player) {46      sky.position.set(player.x, 0, player.z);47    },48  };49}