Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

feat(city): add time-of-day system with sun arc, moon, and daylight-reactive lighting

Adam Eivy1b2e6450ca3c
diff --git a/.changelog/v0.12.x.md b/.changelog/v0.12.x.md
index 2941ee6a50..8debfe4e88 100644
--- a/.changelog/v0.12.x.md
+++ b/.changelog/v0.12.x.md
@@ -235,23 +235,26 @@ This release adds branch management and automated release workflow capabilities
- `client/src/components/digital-twin/constants.js` — Added Genome tab with Dna icon
- `client/src/services/api.js` — Added 8 genome API functions
-### CyberCity — Lighting Controls, Sky Sun & Depth Fog
-- **Fixed ambient brightness slider**: Slider now visibly changes scene brightness in real-time — all lights (ambient, point, animated, searchlight, sun directional) use refs + `useFrame` to read brightness every frame, ensuring immediate response to slider changes
-- **Replaced FogExp2 with depth fog post-processing**: Three.js `FogExp2` made distant buildings transparent instead of foggy. Replaced with a custom GLSL depth fog shader that reads the depth buffer and blends distant pixels toward a dark blue fog color (`#06101a`), producing correct volumetric-style fog. Fog density slider controls near/far fog range; setting to 0 disables fog entirely
-- **Cyberpunk sunset sky dome**: New `CitySky.jsx` component with a large inverted sphere using a custom gradient shader — deep indigo zenith, purple mid-sky, warm magenta/orange horizon — with animated noise ripple for living atmosphere
-- **Glowing sun on horizon**: Emissive amber sphere with additive-blended glow halo ring, sitting low on the horizon for a perpetual cyberpunk sunset look
-- **Sun directional light**: Real directional light emanating from the sun's position illuminates building faces with warm tone, intensity scaled by ambient brightness slider
-- **Fog slider label**: Renamed "FOG DENSITY" to "FOG" for clarity
+### CyberCity — Dynamic Sky & Time-of-Day System
+- **Time-of-day presets**: New "Time of Day" setting with 4 presets — Sunrise, Noon, Sunset, Midnight — each with unique sky colors, sun/moon position, and scene lighting intensity
+- **Overhead sun arc**: Sun traces a proper arc from east horizon (sunrise) through zenith (noon) to west horizon (sunset) and below (midnight), computed from hour-based sinusoidal elevation + azimuth sweep
+- **Cyberpunk sky dome**: Custom GLSL gradient shader on an inverted sphere — deep indigo zenith, purple mid-sky, warm magenta/orange horizon at sunset; brighter blue tones at noon; near-black at midnight — with animated noise ripple for living atmosphere
+- **Moon at midnight**: Smaller, dimmer celestial body with cool silver/blue glow replaces the warm sun, with matching blue-tinted sky dome colors
+- **Smooth preset transitions**: Switching time-of-day smoothly lerps sky colors, celestial body position/scale/colors, and directional light along the shortest path on the 24h clock
+- **Daylight-reactive scene lighting**: All scene lights (ambient, point, animated, searchlight) multiply by the preset's `daylightFactor` — noon is bright (1.8x), sunset/sunrise are moderate (0.6x), midnight is dim (0.3x)
+- **Fixed ambient brightness slider**: Slider now visibly changes scene brightness in real-time — all lights use refs + `useFrame` to read brightness every frame, combined with daylight factor for immediate response
+- **Removed fog**: Fog feature removed entirely — Three.js fog approaches didn't produce the desired visual effect
**New files**:
-- `client/src/components/city/CitySky.jsx` — Sky dome gradient shader + sun mesh + directional light
+- `client/src/components/city/CitySky.jsx` — Sky dome gradient shader + celestial body mesh + directional light with hour-based arc
**Modified files**:
-- `client/src/components/city/CityLights.jsx` — Rewritten with refs + useFrame for reactive brightness
-- `client/src/components/city/CityEffects.jsx` — Added DepthFogShader pass with depth texture render target
-- `client/src/components/city/CityScene.jsx` — Removed fogExp2, added CitySky
-- `client/src/components/city/cityConstants.js` — Added sky/sun color constants
-- `client/src/components/city/CitySettingsPanel.jsx` — Renamed fog slider label
+- `client/src/components/city/CityLights.jsx` — Rewritten with refs + useFrame, daylight factor from timeOfDay presets
+- `client/src/components/city/CityEffects.jsx` — Removed depth fog shader, simplified pipeline
+- `client/src/components/city/CityScene.jsx` — Removed fog, added CitySky
+- `client/src/components/city/cityConstants.js` — Added timeOfDay presets with sky colors, hours, daylight factors
+- `client/src/components/city/CitySettingsPanel.jsx` — Replaced fog slider with time-of-day preset buttons
+- `client/src/hooks/useCitySettings.js` — Removed fogDensity, added timeOfDay setting
## Fixes
diff --git a/client/src/components/city/CityEffects.jsx b/client/src/components/city/CityEffects.jsx
index acec6bf1f9..2eae749072 100644
--- a/client/src/components/city/CityEffects.jsx
+++ b/client/src/components/city/CityEffects.jsx
@@ -106,58 +106,9 @@ const ColorGradingShader = {
`,
};
-// Depth-based fog shader -- blends distant pixels toward fog color
-const DepthFogShader = {
- uniforms: {
- tDiffuse: { value: null },
- tDepth: { value: null },
- uFogColor: { value: new THREE.Color(0x06101a) },
- uFogNear: { value: 20.0 },
- uFogFar: { value: 120.0 },
- uCameraNear: { value: 0.1 },
- uCameraFar: { value: 2000.0 },
- },
- vertexShader: `
- varying vec2 vUv;
- void main() {
- vUv = uv;
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
- }
- `,
- fragmentShader: `
- uniform sampler2D tDiffuse;
- uniform sampler2D tDepth;
- uniform vec3 uFogColor;
- uniform float uFogNear;
- uniform float uFogFar;
- uniform float uCameraNear;
- uniform float uCameraFar;
- varying vec2 vUv;
-
- float toLinearDepth(float ndcDepth, float near, float far) {
- float viewZ = (near * far) / ((far - near) * ndcDepth - far);
- return -viewZ;
- }
-
- void main() {
- vec4 color = texture2D(tDiffuse, vUv);
- float rawDepth = texture2D(tDepth, vUv).x;
-
- float linearDepth = toLinearDepth(rawDepth, uCameraNear, uCameraFar);
-
- // Fog factor: 0 = no fog, capped at 0.85 so sky/distant objects stay visible
- float fogFactor = smoothstep(uFogNear, uFogFar, linearDepth) * 0.85;
-
- color.rgb = mix(color.rgb, uFogColor, fogFactor);
- gl_FragColor = color;
- }
- `,
-};
-
export default function CityEffects({ settings }) {
const composerRef = useRef();
const grainPassRef = useRef();
- const fogPassRef = useRef();
const { gl, scene, camera, size } = useThree();
const bloomEnabled = settings?.bloomEnabled ?? true;
@@ -165,23 +116,9 @@ export default function CityEffects({ settings }) {
const chromaticAberration = settings?.chromaticAberration ?? true;
const filmGrain = settings?.filmGrain ?? true;
const colorGrading = settings?.colorGrading ?? true;
- const fogDensity = settings?.fogDensity ?? 0.008;
-
- // Enable depth texture on the renderer's render target
- useEffect(() => {
- gl.getContext();
- }, [gl]);
useEffect(() => {
- // Create render target with depth texture for fog shader
- const renderTarget = new THREE.WebGLRenderTarget(size.width, size.height, {
- depthTexture: new THREE.DepthTexture(),
- depthBuffer: true,
- });
- renderTarget.depthTexture.format = THREE.DepthFormat;
- renderTarget.depthTexture.type = THREE.UnsignedShortType;
-
- const composer = new EffectComposer(gl, renderTarget);
+ const composer = new EffectComposer(gl);
composer.setSize(size.width, size.height);
composer.setPixelRatio(Math.min(window.devicePixelRatio, 1.5));
@@ -198,24 +135,6 @@ export default function CityEffects({ settings }) {
composer.addPass(bloomPass);
}
- // Depth fog pass (after bloom, before color grading)
- if (fogDensity > 0) {
- const dfPass = new ShaderPass(DepthFogShader);
- dfPass.uniforms.tDepth.value = renderTarget.depthTexture;
- dfPass.uniforms.uCameraNear.value = camera.near;
- dfPass.uniforms.uCameraFar.value = camera.far;
- // Map fogDensity (0-0.03) to fog range: higher density = closer fog
- // At default 0.008: near=80, far=300. At max 0.03: near=30, far=150
- const fogNear = Math.max(20, 100 - fogDensity * 2500);
- const fogFar = Math.max(100, 400 - fogDensity * 8000);
- dfPass.uniforms.uFogNear.value = fogNear;
- dfPass.uniforms.uFogFar.value = fogFar;
- fogPassRef.current = dfPass;
- composer.addPass(dfPass);
- } else {
- fogPassRef.current = null;
- }
-
if (colorGrading) {
const cgPass = new ShaderPass(ColorGradingShader);
composer.addPass(cgPass);
@@ -239,10 +158,8 @@ export default function CityEffects({ settings }) {
return () => {
composer.dispose();
- renderTarget.dispose();
- renderTarget.depthTexture.dispose();
};
- }, [gl, scene, camera, size.width, size.height, bloomEnabled, bloomStrength, chromaticAberration, filmGrain, colorGrading, fogDensity]);
+ }, [gl, scene, camera, size.width, size.height, bloomEnabled, bloomStrength, chromaticAberration, filmGrain, colorGrading]);
useFrame(({ clock }) => {
if (grainPassRef.current) {
diff --git a/client/src/components/city/CityLights.jsx b/client/src/components/city/CityLights.jsx
index fb51f75ec3..87ae73c90a 100644
--- a/client/src/components/city/CityLights.jsx
+++ b/client/src/components/city/CityLights.jsx
@@ -1,5 +1,6 @@
import { useRef } from 'react';
import { useFrame } from '@react-three/fiber';
+import { CITY_COLORS } from './cityConstants';
// Animated accent light that slowly shifts color, with reactive brightness
function AnimatedLight({ position, baseColor, baseIntensity, distance, shiftRange = 0.1, speed = 0.5, brightnessRef }) {
@@ -75,9 +76,11 @@ function ReactivePointLight({ position, baseIntensity, color, distance, brightne
}
export default function CityLights({ settings }) {
- // Store brightness in a ref so useFrame callbacks always see current value
- const brightnessRef = useRef(settings?.ambientBrightness ?? 1.2);
- brightnessRef.current = settings?.ambientBrightness ?? 1.2;
+ // Combine ambient brightness slider with time-of-day daylight factor
+ const timeOfDay = settings?.timeOfDay ?? 'sunset';
+ const daylightFactor = CITY_COLORS.timeOfDay[timeOfDay]?.daylightFactor ?? 0.6;
+ const brightnessRef = useRef((settings?.ambientBrightness ?? 1.2) * daylightFactor);
+ brightnessRef.current = (settings?.ambientBrightness ?? 1.2) * daylightFactor;
const ambientRef = useRef();
useFrame(() => {
diff --git a/client/src/components/city/CityScene.jsx b/client/src/components/city/CityScene.jsx
index 941da65ce2..201261625a 100644
--- a/client/src/components/city/CityScene.jsx
+++ b/client/src/components/city/CityScene.jsx
@@ -39,7 +39,7 @@ export default function CityScene({ apps, agentMap, onBuildingClick, cosStatus,
dpr={dpr}
shadows={false}
style={{ background: '#030308' }}
- gl={{ antialias: true, logarithmicDepthBuffer: false }}
+ gl={{ antialias: true }}
>
<CitySky settings={settings} />
<CityLights settings={settings} />
diff --git a/client/src/components/city/CitySettingsPanel.jsx b/client/src/components/city/CitySettingsPanel.jsx
index 98900fc576..dec2d18cad 100644
--- a/client/src/components/city/CitySettingsPanel.jsx
+++ b/client/src/components/city/CitySettingsPanel.jsx
@@ -212,15 +212,24 @@ export default function CitySettingsPanel() {
step={0.1}
format={(v) => `${v.toFixed(1)}x`}
/>
- <SettingSlider
- label="FOG"
- value={settings.fogDensity}
- onChange={(v) => updateSetting('fogDensity', v)}
- min={0}
- max={0.03}
- step={0.001}
- format={(v) => v === 0 ? 'OFF' : v.toFixed(3)}
- />
+ <div className="py-1">
+ <div className="font-pixel text-[10px] text-gray-400 tracking-wide mb-1.5">TIME OF DAY</div>
+ <div className="grid grid-cols-4 gap-1">
+ {['sunrise', 'noon', 'sunset', 'midnight'].map(tod => (
+ <button
+ key={tod}
+ onClick={() => updateSetting('timeOfDay', tod)}
+ className={`font-pixel text-[8px] py-1.5 rounded border transition-all tracking-wide ${
+ settings.timeOfDay === tod
+ ? 'bg-cyan-500/20 border-cyan-500/50 text-cyan-400 shadow-[0_0_8px_rgba(6,182,212,0.2)]'
+ : 'bg-gray-800/40 border-gray-700/40 text-gray-500 hover:border-gray-600'
+ }`}
+ >
+ {tod.toUpperCase()}
+ </button>
+ ))}
+ </div>
+ </div>
</div>
{/* Reset */}
diff --git a/client/src/components/city/CitySky.jsx b/client/src/components/city/CitySky.jsx
index 867aaeb8d3..2026052b29 100644
--- a/client/src/components/city/CitySky.jsx
+++ b/client/src/components/city/CitySky.jsx
@@ -3,9 +3,23 @@ import { useFrame } from '@react-three/fiber';
import * as THREE from 'three';
import { CITY_COLORS } from './cityConstants';
-// Sun position: low on horizon, slightly off-center for drama
-const SUN_POSITION = [-60, 8, -80];
-const SUN_DIRECTION = new THREE.Vector3(...SUN_POSITION).normalize().negate();
+const SUN_RADIUS = 100;
+
+// Compute sun/moon position from hour (0-24) along a proper overhead arc
+// 6h = east horizon, 12h = high overhead, 18h = west horizon, 0h = below (north)
+const getArcPosition = (hour) => {
+ // Normalize hour to 0-2PI, where 6h=0 (sunrise east), 12h=PI/2 (overhead), 18h=PI (sunset west)
+ const t = ((hour - 6) / 24) * Math.PI * 2;
+ // Elevation: sin curve, peaks at noon (t=PI/2), dips below at midnight
+ const elevation = Math.sin(t);
+ // Azimuth: sweeps from east(0) through south(PI/2) to west(PI) to north
+ const azimuth = t;
+ const y = elevation * SUN_RADIUS;
+ const horizontalR = Math.cos(Math.asin(Math.min(1, Math.max(-1, elevation)))) * SUN_RADIUS;
+ const x = Math.cos(azimuth) * horizontalR;
+ const z = -Math.sin(azimuth) * horizontalR;
+ return [x, y, z];
+};
// Sky dome gradient shader (inverted sphere)
const SkyDomeShader = {
@@ -23,10 +37,11 @@ const SkyDomeShader = {
uniform vec3 uHorizonHigh;
uniform vec3 uHorizonLow;
uniform vec3 uSunDirection;
+ uniform float uSunIntensity;
+ uniform float uIsMoon;
uniform float uTime;
varying vec3 vWorldPosition;
- // Simple noise for subtle atmosphere ripple
float hash(vec2 p) {
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
}
@@ -43,7 +58,6 @@ const SkyDomeShader = {
void main() {
vec3 dir = normalize(vWorldPosition);
- // Height factor: 0 at horizon, 1 at zenith
float h = max(dir.y, 0.0);
// Base gradient bands
@@ -52,19 +66,28 @@ const SkyDomeShader = {
color = mix(color, uMidSky, smoothstep(0.05, 0.25, h));
color = mix(color, uZenith, smoothstep(0.2, 0.6, h));
- // Sun glow on horizon
- float sunDot = max(dot(dir, uSunDirection), 0.0);
- float sunGlow = pow(sunDot, 8.0) * 0.4;
- color += vec3(1.0, 0.3, 0.15) * sunGlow;
- // Wider warm wash
- float warmWash = pow(sunDot, 3.0) * 0.15;
- color += vec3(0.8, 0.2, 0.3) * warmWash;
+ // Glow around sun/moon
+ float bodyDot = max(dot(dir, normalize(uSunDirection)), 0.0);
- // Subtle noise ripple for living atmosphere
+ if (uIsMoon < 0.5) {
+ // Sun: warm orange/red glow
+ float sunGlow = pow(bodyDot, 8.0) * 0.4 * uSunIntensity;
+ color += vec3(1.0, 0.3, 0.15) * sunGlow;
+ float warmWash = pow(bodyDot, 3.0) * 0.15 * uSunIntensity;
+ color += vec3(0.8, 0.2, 0.3) * warmWash;
+ } else {
+ // Moon: cool silver/blue glow
+ float moonGlow = pow(bodyDot, 12.0) * 0.3 * uSunIntensity;
+ color += vec3(0.6, 0.65, 0.9) * moonGlow;
+ float coolWash = pow(bodyDot, 4.0) * 0.08 * uSunIntensity;
+ color += vec3(0.3, 0.35, 0.6) * coolWash;
+ }
+
+ // Subtle noise ripple
float n = noise(dir.xz * 3.0 + uTime * 0.02) * 0.03;
color += n;
- // Below horizon: fade to black
+ // Below horizon: fade to dark
float belowFade = smoothstep(0.0, -0.05, dir.y);
color = mix(color, vec3(0.01, 0.01, 0.03), belowFade);
@@ -73,39 +96,66 @@ const SkyDomeShader = {
`,
};
-// Glowing sun mesh on the horizon
-function Sun({ brightnessRef }) {
- const sunRef = useRef();
+// Lerp THREE.Color in place
+const lerpColor = (target, a, b, t) => {
+ target.r = a.r + (b.r - a.r) * t;
+ target.g = a.g + (b.g - a.g) * t;
+ target.b = a.b + (b.b - a.b) * t;
+};
+
+// Pre-allocate parsed preset colors
+const presetColors = {};
+const getPresetColors = (name) => {
+ if (!presetColors[name]) {
+ const p = CITY_COLORS.timeOfDay[name];
+ presetColors[name] = {
+ zenith: new THREE.Color(p.zenith),
+ midSky: new THREE.Color(p.midSky),
+ horizonHigh: new THREE.Color(p.horizonHigh),
+ horizonLow: new THREE.Color(p.horizonLow),
+ sunCore: new THREE.Color(p.sunCore),
+ sunGlow: new THREE.Color(p.sunGlow),
+ sunLight: new THREE.Color(p.sunLight),
+ hour: p.hour,
+ sunIntensity: p.sunIntensity,
+ sunScale: p.sunScale,
+ isMoon: p.isMoon,
+ daylightFactor: p.daylightFactor,
+ };
+ }
+ return presetColors[name];
+};
+
+// Sun/Moon mesh
+function CelestialBody({ groupRef }) {
+ const bodyRef = useRef();
const haloRef = useRef();
useFrame(({ clock }) => {
- if (!sunRef.current) return;
+ if (!bodyRef.current) return;
const t = clock.getElapsedTime();
- // Gentle pulse
const pulse = 1.0 + Math.sin(t * 0.5) * 0.1;
- sunRef.current.material.emissiveIntensity = 2.0 * pulse;
+ bodyRef.current.material.emissiveIntensity = 2.0 * pulse;
if (haloRef.current) {
haloRef.current.material.opacity = 0.15 + Math.sin(t * 0.3) * 0.05;
}
});
return (
- <group position={SUN_POSITION}>
- {/* Sun core */}
- <mesh ref={sunRef}>
+ <group ref={groupRef}>
+ <mesh ref={bodyRef}>
<sphereGeometry args={[4, 24, 24]} />
<meshStandardMaterial
- color={CITY_COLORS.sky.sunCore}
- emissive={CITY_COLORS.sky.sunCore}
+ color="#ffaa44"
+ emissive="#ffaa44"
emissiveIntensity={2.0}
toneMapped={false}
/>
</mesh>
- {/* Glow halo ring */}
- <mesh ref={haloRef} rotation={[0, 0, 0]}>
+ <mesh ref={haloRef}>
<ringGeometry args={[5, 14, 32]} />
<meshBasicMaterial
- color={CITY_COLORS.sky.sunGlow}
+ color="#ff6080"
transparent
opacity={0.15}
side={THREE.DoubleSide}
@@ -117,40 +167,35 @@ function Sun({ brightnessRef }) {
);
}
-// Directional light from the sun position
-function SunLight({ brightnessRef }) {
- const ref = useRef();
-
- useFrame(() => {
- if (!ref.current) return;
- ref.current.intensity = 0.6 * brightnessRef.current;
- });
-
- return (
- <directionalLight
- ref={ref}
- position={SUN_POSITION}
- target-position={[0, 0, 0]}
- intensity={0.6}
- color={CITY_COLORS.sky.sunLight}
- />
- );
-}
-
export default function CitySky({ settings }) {
const brightnessRef = useRef(settings?.ambientBrightness ?? 1.2);
brightnessRef.current = settings?.ambientBrightness ?? 1.2;
+ const timeOfDayRef = useRef(settings?.timeOfDay ?? 'sunset');
+ timeOfDayRef.current = settings?.timeOfDay ?? 'sunset';
+
+ const currentPresetRef = useRef(timeOfDayRef.current);
+ const transitionRef = useRef(1.0);
+
+ const bodyGroupRef = useRef();
+ const lightRef = useRef();
+ const currentScaleRef = useRef(1.0);
+ const currentHourRef = useRef(18); // start at sunset
+
const skyMaterial = useMemo(() => {
+ const preset = getPresetColors('sunset');
+ const initPos = getArcPosition(18);
return new THREE.ShaderMaterial({
vertexShader: SkyDomeShader.vertexShader,
fragmentShader: SkyDomeShader.fragmentShader,
uniforms: {
- uZenith: { value: new THREE.Color(CITY_COLORS.sky.zenith) },
- uMidSky: { value: new THREE.Color(CITY_COLORS.sky.midSky) },
- uHorizonHigh: { value: new THREE.Color(CITY_COLORS.sky.horizonHigh) },
- uHorizonLow: { value: new THREE.Color(CITY_COLORS.sky.horizonLow) },
- uSunDirection: { value: SUN_DIRECTION },
+ uZenith: { value: preset.zenith.clone() },
+ uMidSky: { value: preset.midSky.clone() },
+ uHorizonHigh: { value: preset.horizonHigh.clone() },
+ uHorizonLow: { value: preset.horizonLow.clone() },
+ uSunDirection: { value: new THREE.Vector3(...initPos).normalize() },
+ uSunIntensity: { value: preset.sunIntensity },
+ uIsMoon: { value: 0.0 },
uTime: { value: 0 },
},
side: THREE.BackSide,
@@ -158,18 +203,85 @@ export default function CitySky({ settings }) {
});
}, []);
- useFrame(({ clock }) => {
+ useFrame(({ clock }, delta) => {
+ const target = timeOfDayRef.current;
+ const brightness = brightnessRef.current;
+
+ if (currentPresetRef.current !== target) {
+ currentPresetRef.current = target;
+ transitionRef.current = 0;
+ }
+
+ transitionRef.current = Math.min(1.0, transitionRef.current + delta * 1.5);
+ const lerpFactor = transitionRef.current < 1 ? delta * 3 : 1;
+
+ const preset = getPresetColors(target);
+
+ // Lerp hour along shortest path on the 24h clock
+ let hourDiff = preset.hour - currentHourRef.current;
+ if (hourDiff > 12) hourDiff -= 24;
+ if (hourDiff < -12) hourDiff += 24;
+ currentHourRef.current += hourDiff * lerpFactor;
+ // Wrap to 0-24
+ if (currentHourRef.current < 0) currentHourRef.current += 24;
+ if (currentHourRef.current >= 24) currentHourRef.current -= 24;
+
+ // Compute sun position from current hour on the arc
+ const bodyPos = getArcPosition(currentHourRef.current);
+ const bodyDir = new THREE.Vector3(...bodyPos).normalize();
+
+ // Lerp sky dome colors
+ lerpColor(skyMaterial.uniforms.uZenith.value, skyMaterial.uniforms.uZenith.value, preset.zenith, lerpFactor);
+ lerpColor(skyMaterial.uniforms.uMidSky.value, skyMaterial.uniforms.uMidSky.value, preset.midSky, lerpFactor);
+ lerpColor(skyMaterial.uniforms.uHorizonHigh.value, skyMaterial.uniforms.uHorizonHigh.value, preset.horizonHigh, lerpFactor);
+ lerpColor(skyMaterial.uniforms.uHorizonLow.value, skyMaterial.uniforms.uHorizonLow.value, preset.horizonLow, lerpFactor);
+
+ // Update sun direction directly from arc position
+ skyMaterial.uniforms.uSunDirection.value.copy(bodyDir);
+ skyMaterial.uniforms.uSunIntensity.value += (preset.sunIntensity - skyMaterial.uniforms.uSunIntensity.value) * lerpFactor;
+ skyMaterial.uniforms.uIsMoon.value += ((preset.isMoon ? 1.0 : 0.0) - skyMaterial.uniforms.uIsMoon.value) * lerpFactor;
skyMaterial.uniforms.uTime.value = clock.getElapsedTime();
+
+ // Move celestial body mesh
+ if (bodyGroupRef.current) {
+ const sp = bodyGroupRef.current.position;
+ sp.set(bodyPos[0], bodyPos[1], bodyPos[2]);
+
+ currentScaleRef.current += (preset.sunScale - currentScaleRef.current) * lerpFactor;
+ const s = currentScaleRef.current;
+ bodyGroupRef.current.scale.set(s, s, s);
+
+ const bodyMesh = bodyGroupRef.current.children[0];
+ const haloMesh = bodyGroupRef.current.children[1];
+ if (bodyMesh?.material) {
+ bodyMesh.material.color.lerp(preset.sunCore, lerpFactor);
+ bodyMesh.material.emissive.lerp(preset.sunCore, lerpFactor);
+ }
+ if (haloMesh?.material) {
+ haloMesh.material.color.lerp(preset.sunGlow, lerpFactor);
+ }
+ }
+
+ // Directional light follows body
+ if (lightRef.current) {
+ lightRef.current.position.set(bodyPos[0], bodyPos[1], bodyPos[2]);
+ lightRef.current.intensity += (preset.sunIntensity * brightness - lightRef.current.intensity) * lerpFactor;
+ lightRef.current.color.lerp(preset.sunLight, lerpFactor);
+ }
});
return (
<group>
- {/* Sky dome - large inverted sphere */}
<mesh material={skyMaterial}>
<sphereGeometry args={[500, 32, 32]} />
</mesh>
- <Sun brightnessRef={brightnessRef} />
- <SunLight brightnessRef={brightnessRef} />
+ <CelestialBody groupRef={bodyGroupRef} />
+ <directionalLight
+ ref={lightRef}
+ position={[-60, 5, -80]}
+ intensity={0.6}
+ color="#ffccaa"
+ />
</group>
);
}
diff --git a/client/src/components/city/cityConstants.js b/client/src/components/city/cityConstants.js
index 84fc55e028..447af31a76 100644
--- a/client/src/components/city/cityConstants.js
+++ b/client/src/components/city/cityConstants.js
@@ -3,8 +3,6 @@ export const PIXEL_FONT_URL = '/fonts/GeistPixel-Square.ttf';
export const CITY_COLORS = {
ground: '#06b6d4',
- fog: '#050510',
- sky: '#030308',
ambient: '#0d0d2b',
building: {
online: '#06b6d4',
@@ -21,15 +19,66 @@ export const CITY_COLORS = {
// Celestial colors
planet: '#3b82f6',
orbit: '#1e3a5f',
- // Sky dome + sun colors
- sky: {
- zenith: '#050520',
- midSky: '#1a0a2e',
- horizonHigh: '#ff4060',
- horizonLow: '#ff8040',
- sunCore: '#ffaa44',
- sunGlow: '#ff6080',
- sunLight: '#ffccaa',
+ // Time-of-day presets (used by CitySky + CityLights)
+ // hour: 0-24 mapped to sun arc. Sun traces east(6h) → overhead(12h) → west(18h) → below(0h)
+ // daylightFactor: multiplier for scene ambient/point lights (bright day, dim night)
+ timeOfDay: {
+ sunrise: {
+ hour: 6,
+ zenith: '#0a0a30',
+ midSky: '#1a1040',
+ horizonHigh: '#ff6050',
+ horizonLow: '#ffaa40',
+ sunCore: '#ff8844',
+ sunGlow: '#ff6060',
+ sunLight: '#ffccaa',
+ sunIntensity: 0.5,
+ sunScale: 1.0,
+ isMoon: false,
+ daylightFactor: 0.6,
+ },
+ noon: {
+ hour: 12,
+ zenith: '#182848',
+ midSky: '#2a3d6a',
+ horizonHigh: '#506888',
+ horizonLow: '#7090a8',
+ sunCore: '#ffffdd',
+ sunGlow: '#ffffbb',
+ sunLight: '#eeeeff',
+ sunIntensity: 1.0,
+ sunScale: 0.7,
+ isMoon: false,
+ daylightFactor: 1.8,
+ },
+ sunset: {
+ hour: 18,
+ zenith: '#050520',
+ midSky: '#1a0a2e',
+ horizonHigh: '#ff4060',
+ horizonLow: '#ff8040',
+ sunCore: '#ffaa44',
+ sunGlow: '#ff6080',
+ sunLight: '#ffccaa',
+ sunIntensity: 0.6,
+ sunScale: 1.0,
+ isMoon: false,
+ daylightFactor: 0.6,
+ },
+ midnight: {
+ hour: 0,
+ zenith: '#020208',
+ midSky: '#040412',
+ horizonHigh: '#08081a',
+ horizonLow: '#0a0a22',
+ sunCore: '#ccccee',
+ sunGlow: '#8888bb',
+ sunLight: '#334466',
+ sunIntensity: 0.12,
+ sunScale: 0.6,
+ isMoon: true,
+ daylightFactor: 0.3,
+ },
},
};
diff --git a/client/src/hooks/useCitySettings.js b/client/src/hooks/useCitySettings.js
index 2c3e00999b..73c8d89862 100644
--- a/client/src/hooks/useCitySettings.js
+++ b/client/src/hooks/useCitySettings.js
@@ -8,7 +8,7 @@ const QUALITY_PRESETS = {
reflectionsEnabled: false, chromaticAberration: false,
filmGrain: false, colorGrading: false,
particleDensity: 0.5, scanlineOverlay: false,
- ambientBrightness: 1.0, fogDensity: 0.008,
+ ambientBrightness: 1.0,
neonBrightness: 1.0,
dpr: [1, 1],
},
@@ -17,7 +17,7 @@ const QUALITY_PRESETS = {
reflectionsEnabled: true, chromaticAberration: false,
filmGrain: false, colorGrading: true,
particleDensity: 0.75, scanlineOverlay: true,
- ambientBrightness: 1.0, fogDensity: 0.01,
+ ambientBrightness: 1.0,
neonBrightness: 1.0,
dpr: [1, 1.25],
},
@@ -26,7 +26,7 @@ const QUALITY_PRESETS = {
reflectionsEnabled: true, chromaticAberration: true,
filmGrain: true, colorGrading: true,
particleDensity: 1.0, scanlineOverlay: true,
- ambientBrightness: 1.2, fogDensity: 0.008,
+ ambientBrightness: 1.2,
neonBrightness: 1.2,
dpr: [1, 1.5],
},
@@ -35,7 +35,7 @@ const QUALITY_PRESETS = {
reflectionsEnabled: true, chromaticAberration: true,
filmGrain: true, colorGrading: true,
particleDensity: 1.5, scanlineOverlay: true,
- ambientBrightness: 1.5, fogDensity: 0.006,
+ ambientBrightness: 1.5,
neonBrightness: 1.5,
dpr: [1, 2],
},
@@ -47,6 +47,7 @@ const DEFAULT_SETTINGS = {
sfxEnabled: true,
sfxVolume: 0.5,
qualityPreset: 'high',
+ timeOfDay: 'sunset',
...QUALITY_PRESETS.high,
};