Files
Portfolio/src/scene/world/dawn-light.ts

28 lines
1.1 KiB
TypeScript

import * as THREE from 'three';
/**
* END OF SHIFT: first light. A fixed low sun straight down the road throws a
* warm rim on the terrain, the district facades and the asphalt as the dawn
* rises. Shared uniform (one set for every generation), like the headlight
* beam: the environment writes one float per frame, and 0 skips the term.
*/
export const dawnLightUniforms = {
uDawnLight: { value: 0 },
};
/** Toward the sun: low over the horizon, down the road (-z). */
const SUN_DIRECTION = new THREE.Vector3(0, 0.2, -1).normalize();
/** GLSL: dawnRim(normal, toCamera) -> warm light to add (0 when uDawnLight is 0). */
export const DAWN_PARS = /* glsl */ `
uniform float uDawnLight;
vec3 dawnRim(vec3 n, vec3 toCamera) {
if (uDawnLight <= 0.0) return vec3(0.0);
vec3 sunDir = vec3(${SUN_DIRECTION.x.toFixed(4)}, ${SUN_DIRECTION.y.toFixed(4)}, ${SUN_DIRECTION.z.toFixed(4)});
float facing = abs(dot(n, sunDir));
float rim = pow(1.0 - abs(dot(n, toCamera)), 2.0);
float against = max(0.0, dot(-toCamera, sunDir));
return vec3(1.0, 0.6, 0.36) * uDawnLight * (facing * 0.09 + rim * against * 0.24);
}
`;