|
12 | 12 | // sRGB hex helper -> linear THREE.Color |
13 | 13 | const L = (h) => E.lin(h); |
14 | 14 | E.PRESETS = { |
| 15 | + // Night Drop. One key: the moon, cool and from the same direction as before (stealth reads it), strong enough to |
| 16 | + // throw long shadows but not to paint the fields pale; a low, cool fill so shadow is real dark (lifted a little by |
| 17 | + // the grade, never crushed); a wide soft glow round the moon in a broken deck. Lamps and windows do the rest. |
15 | 18 | night_moon: { |
16 | | - skyTop: 0x070a12, skyHor: 0x26303f, ground: 0x0e1014, fog: 0x1d2531, fogD: 0.0105, mist: 0.55, mistTop: 1.8, |
17 | | - sunDir: [-0.5, 0.74, 0.45], sunCol: 0xb4c6ea, sunI: 3.9, sunShadow: true, moon: 1, stars: 1, cloud: 0.4, cloudCol: 0x2b3442, |
18 | | - hemiSky: 0x5f7298, hemiGround: 0x48433a, hemiI: 0.84, env: 0.6, exposure: 0.9, wind: 0.35, wet: 0.15, rain: 0, grade: 'night' |
| 19 | + skyTop: 0x04060b, skyHor: 0x26303f, ground: 0x07080a, fog: 0x161d27, fogD: 0.0105, mist: 0.5, mistTop: 1.8, |
| 20 | + sunDir: [-0.5, 0.74, 0.45], sunCol: 0xa3b8de, sunI: 2.2, sunShadow: true, soft: 2.5, moon: 1, stars: 1, cloud: 0.42, cloudCol: 0x161b24, glow: 0.55, cscale: 0.6, |
| 21 | + hemiSky: 0x33435f, hemiGround: 0x1c1712, hemiI: 0.5, env: 0.45, exposure: 1.1, wind: 0.35, wet: 0.22, rain: 0, grade: 'night', rim: 0.55, rimCol: 0x8aa0c8 |
19 | 22 | }, |
20 | 23 | night_overcast: { |
21 | 24 | skyTop: 0x080a0d, skyHor: 0x1b1f25, ground: 0x0b0c0d, fog: 0x171b20, fogD: 0.0135, mist: 0.7, mistTop: 2.2, |
|
44 | 47 | sunDir: [-0.85, 0.22, -0.2], sunCol: 0xb79a88, sunI: 0.75, sunShadow: true, moon: 0, gap: 0.7, stars: 0, cloud: 1.0, cloudCol: 0x2c3036, |
45 | 48 | hemiSky: 0x7a8494, hemiGround: 0x2e2c2a, hemiI: 0.85, env: 0.8, exposure: 1.0, wind: 1.3, wet: 1.0, rain: 1, grade: 'rain' |
46 | 49 | }, |
| 50 | + // Boot Camp. Overcast, but with a direction: the sun is a bright patch behind thinner cloud low in the south-west |
| 51 | + // quarter, so there is a lit side and a shade side, soft shadows under huts, sandbags and people, and big cloud |
| 52 | + // shapes with a lit edge toward it; the fill is lower than before so things have weight; haze separates the range, |
| 53 | + // the hedge line and the hills. |
47 | 54 | day_overcast: { |
48 | | - skyTop: 0x7f8c99, skyHor: 0xb3b7b6, ground: 0x4b4a44, fog: 0xa4a9aa, fogD: 0.0042, mist: 0.0, mistTop: 1.0, |
49 | | - sunDir: [0.4, 0.7, 0.35], sunCol: 0xe8e2d6, sunI: 1.1, sunShadow: true, moon: 0, stars: 0, cloud: 0.85, cloudCol: 0x9ea2a4, |
50 | | - hemiSky: 0xb6c0cc, hemiGround: 0x5a5448, hemiI: 0.75, env: 0.9, exposure: 0.9, wind: 0.6, wet: 0.0, rain: 0, grade: 'day' |
| 55 | + skyTop: 0x5f6f80, skyHor: 0xaeb4b7, ground: 0x4b4a44, fog: 0xa3a9ac, fogD: 0.0042, mist: 0.0, mistTop: 1.0, |
| 56 | + sunDir: [0.55, 0.36, -0.77], sunCol: 0xece0c8, sunI: 1.3, sunShadow: true, soft: 4, moon: 0, stars: 0, cloud: 1.0, cloudCol: 0x6a7076, glow: 0.6, cscale: 0.75, |
| 57 | + hemiSky: 0xa3b3c6, hemiGround: 0x8a7f68, hemiI: 1.7, env: 0.8, exposure: 1.0, wind: 0.6, wet: 0.0, rain: 0, grade: 'day', rim: 0.08, cloudShadow: 1 |
51 | 58 | } |
52 | 59 | }; |
53 | 60 |
|
|
134 | 141 |
|
135 | 142 | // ------------------------------------------------------------------ sky |
136 | 143 | const SKY_VS = 'varying vec3 vD; void main(){ vD = normalize(position); vec4 p = projectionMatrix * modelViewMatrix * vec4(position,1.0); gl_Position = p.xyww; }'; |
| 144 | + // The sky: a gradient that is brighter in the quarter of the sky the key light is in, a wide glow round the sun or |
| 145 | + // moon (haze scattering it forward) and a tighter core, stars, the moon's disc, and a cloud deck with relief: the |
| 146 | + // deck's density sampled again a step toward the light, so cloud sides facing the light are lit and the far sides |
| 147 | + // and thick cores fall dark; thin edges near the light glow. Lightning lights the deck from inside. |
137 | 148 | const SKY_FS = E.GLSL.noise + ` |
138 | | - uniform vec3 top, hor, gnd, moonDir, moonCol, cloudCol, flashDir; uniform float moonAmt, starAmt, cloud, time, bright, gap, flash; |
| 149 | + uniform vec3 top, hor, gnd, moonDir, moonCol, cloudCol, flashDir; uniform float moonAmt, starAmt, cloud, time, bright, gap, flash, glow, cscale; |
139 | 150 | varying vec3 vD; |
140 | 151 | float fbm3(vec2 p){ float s = 0.0, a = 0.5; for (int i = 0; i < 5; i++){ s += a * ivN(p); p = p * 2.03 + 7.1; a *= 0.5; } return s; } |
141 | 152 | void main(){ |
142 | 153 | vec3 d = normalize(vD); |
143 | 154 | float h = d.y; |
| 155 | + float md = max(dot(d, moonDir), 0.0); |
| 156 | + vec2 hz = normalize(d.xz + 1e-4), lz = normalize(moonDir.xz + 1e-4); |
| 157 | + float side = max(dot(hz, lz), 0.0); |
144 | 158 | vec3 c = mix(hor, top, pow(clamp(h, 0.0, 1.0), 0.5)); |
| 159 | + c *= 1.0 + glow * 0.5 * side * side * (1.0 - smoothstep(0.0, 0.7, h)); |
145 | 160 | c = mix(c, gnd, smoothstep(0.0, -0.08, h)); |
146 | | - float md = max(dot(d, moonDir), 0.0); |
147 | | - // stars: hashed cells on the sphere, small, twinkling a little |
148 | 161 | if (starAmt > 0.0 && h > 0.0) { |
149 | 162 | vec2 sp = vec2(atan(d.z, d.x) * 180.0, asin(clamp(h, -1.0, 1.0)) * 180.0); |
150 | 163 | vec2 ci = floor(sp), cf = fract(sp) - 0.5; |
|
153 | 166 | star *= (0.5 + 0.5 * b) * (0.8 + 0.2 * sin(time * (2.0 + b * 3.0) + r * 40.0)); |
154 | 167 | c += vec3(0.55, 0.6, 0.75) * star * starAmt * smoothstep(0.0, 0.25, h); |
155 | 168 | } |
156 | | - // moon: disc with soft halo |
157 | 169 | if (moonAmt > 0.0) { |
158 | 170 | float disc = smoothstep(0.99955, 0.99975, md); |
159 | 171 | float mare = 0.8 + 0.2 * ivN(d.xy * 900.0); |
160 | 172 | c = mix(c, moonCol * 2.2 * mare, disc * moonAmt); |
161 | | - c += moonCol * (pow(md, 60.0) * 0.12 + pow(md, 8.0) * 0.035) * moonAmt; |
162 | 173 | } |
163 | | - // clouds: a slab seen from below, lit from the moon side, drifting |
| 174 | + // the glow round the light (and the sun's own small bright core by day) |
| 175 | + vec3 halo = moonCol * glow * (pow(md, 5.0) * 0.22 + pow(md, 40.0) * 0.5 + pow(md, 900.0) * 3.0 * (1.0 - moonAmt)); |
| 176 | + float cov = 0.0; |
164 | 177 | if (h > 0.0 && cloud > 0.0) { |
165 | | - vec2 cp = d.xz / (h + 0.08) * 1.6 + vec2(time * 0.012, time * 0.005); |
166 | | - float n = fbm3(cp * 0.8); |
167 | | - float cov = smoothstep(1.0 - cloud * 0.85 - 0.12, 1.0 - cloud * 0.85 + 0.25, n + cloud * 0.35); |
168 | | - // a ragged gap in the deck round the key light (the moon or a low sun shows through it, edges torn by the noise) |
| 178 | + vec2 cp = d.xz / (h + 0.1) * cscale + vec2(time * 0.010, time * 0.004); |
| 179 | + float n = fbm3(cp); |
| 180 | + cov = smoothstep(1.0 - cloud * 0.85 - 0.12, 1.0 - cloud * 0.85 + 0.28, n + cloud * 0.35); |
169 | 181 | if (gap > 0.0) { float gd = md + (n - 0.5) * 0.16 + (fbm3(cp * 2.3 + 5.0) - 0.5) * 0.05; cov *= 1.0 - gap * 0.9 * smoothstep(0.9, 0.975, gd); } |
170 | | - // relief: the cloud base sampled again a little toward the light; where it thins toward the light the edge is lit |
171 | | - vec2 ld = normalize(moonDir.xz + 1e-4) * 0.09; |
172 | | - float rel = clamp((n - fbm3((cp + ld) * 0.8)) * 5.0, -1.0, 1.0); |
173 | | - float lit = 0.6 + 0.6 * pow(md, 4.0) * moonAmt + 0.25 * fbm3(cp * 1.7 + 3.0); |
174 | | - lit *= 1.0 + rel * 0.35 * (0.4 + 0.6 * pow(md, 3.0)); |
175 | | - vec3 cc = cloudCol * lit; |
176 | | - // lightning inside the deck: a glow centred on this strike's direction, strongest where the cloud is thick, |
177 | | - // with the cloud relief toward it picking out the billows |
| 182 | + // relief: thinner a step toward the light = this side faces the light |
| 183 | + float n2 = fbm3(cp + lz * 0.16); |
| 184 | + float rel = clamp((n - n2) * 5.0, -1.0, 1.0); |
| 185 | + float thick = smoothstep(0.45, 0.95, n); |
| 186 | + float toward = 0.35 + 0.65 * pow(md, 2.0); |
| 187 | + vec3 dark = cloudCol * 0.6, litc = mix(cloudCol, moonCol, 0.25) * (1.0 + 0.45 * toward); |
| 188 | + vec3 cc = mix(dark, litc, clamp(0.45 + 0.55 * rel * toward - 0.4 * thick, 0.0, 1.0)); |
| 189 | + float edge = cov * (1.0 - cov) * 4.0; |
| 190 | + cc += moonCol * glow * (pow(md, 6.0) * 0.6 + pow(md, 30.0) * 1.2) * edge; |
178 | 191 | if (flash > 0.0) { |
179 | 192 | float fd = max(dot(d, flashDir), 0.0), dens = cov * smoothstep(0.3, 0.75, n); |
180 | | - vec2 fl = normalize(flashDir.xz + 1e-4) * 0.07; float frel = clamp((n - fbm3((cp + fl) * 0.8)) * 4.0, -1.0, 1.0); |
181 | | - float core = pow(fd, 14.0) * (0.15 + 1.6 * dens * dens) * (1.0 + 0.8 * frel), halo = pow(fd, 4.0) * 0.1 * dens; |
182 | | - cc += vec3(0.5, 0.56, 0.74) * flash * (core + halo) * 0.55; |
| 193 | + vec2 fl = normalize(flashDir.xz + 1e-4) * 0.07; float frel = clamp((n - fbm3(cp + fl)) * 4.0, -1.0, 1.0); |
| 194 | + float core = pow(fd, 14.0) * (0.15 + 1.6 * dens * dens) * (1.0 + 0.8 * frel), hl = pow(fd, 4.0) * 0.1 * dens; |
| 195 | + cc += vec3(0.5, 0.56, 0.74) * flash * (core + hl) * 0.55; |
183 | 196 | } |
184 | | - // structure: slow darker bands of heavier cloud base, and (by day) a brighter thin patch toward the hidden sun |
185 | 197 | float band = fbm3(cp * 0.33 + vec2(7.0, 1.3)); |
186 | | - cc *= mix(0.68, 1.12, smoothstep(0.32, 0.68, band)); |
187 | | - cc += cloudCol * (1.0 - moonAmt) * (0.45 * pow(max(md, 0.0), 5.0) + 0.12 * smoothstep(0.55, 0.8, band)); |
188 | | - c = mix(c, cc, cov * smoothstep(0.0, 0.12, h)); |
| 198 | + cc *= mix(0.72, 1.1, smoothstep(0.32, 0.68, band)); |
| 199 | + cov *= smoothstep(0.0, 0.12, h); |
| 200 | + c = mix(c, cc, cov); |
189 | 201 | } |
| 202 | + c += halo * (1.0 - 0.7 * cov); |
190 | 203 | c *= bright; |
191 | | - // dither against banding (one 8-bit step) |
192 | 204 | c += (ivH(gl_FragCoord.xy + fract(time) * 61.0) - 0.5) / 255.0; |
193 | 205 | gl_FragColor = vec4(c, 1.0); |
194 | 206 | }`; |
|
197 | 209 | uniforms: { |
198 | 210 | top: { value: new THREE.Color() }, hor: { value: new THREE.Color() }, gnd: { value: new THREE.Color() }, moonDir: { value: new THREE.Vector3(0, 1, 0) }, |
199 | 211 | moonCol: { value: new THREE.Color(0xdde6ff) }, cloudCol: { value: new THREE.Color() }, moonAmt: { value: 1 }, starAmt: { value: 1 }, cloud: { value: 0.4 }, time: { value: 0 }, bright: { value: 1 }, |
200 | | - gap: { value: 0 }, flash: { value: 0 }, flashDir: { value: new THREE.Vector3(0.3, 0.4, -0.8).normalize() } |
| 212 | + gap: { value: 0 }, flash: { value: 0 }, glow: { value: 0.3 }, cscale: { value: 1.3 }, flashDir: { value: new THREE.Vector3(0.3, 0.4, -0.8).normalize() } |
201 | 213 | }, |
202 | 214 | vertexShader: SKY_VS, fragmentShader: SKY_FS, side: THREE.BackSide, depthWrite: false, depthTest: true, fog: false, toneMapped: true |
203 | 215 | }); |
|
274 | 286 | A.dir.set(P.sunDir[0], P.sunDir[1], P.sunDir[2]).normalize(); |
275 | 287 | const u = sky.uniforms; |
276 | 288 | u.top.value.copy(L(P.skyTop)); u.hor.value.copy(L(P.skyHor)); u.gnd.value.copy(L(P.ground)); u.moonDir.value.copy(A.dir); |
277 | | - u.moonAmt.value = P.moon; u.starAmt.value = P.stars; u.cloud.value = P.cloud; u.cloudCol.value.copy(L(P.cloudCol)); u.gap.value = P.gap || 0; |
| 289 | + u.moonAmt.value = P.moon; u.starAmt.value = P.stars; u.cloud.value = P.cloud; u.glow.value = P.glow != null ? P.glow : 0.3; u.cscale.value = P.cscale || 1.3; u.cloudCol.value.copy(L(P.cloudCol)); u.gap.value = P.gap || 0; |
278 | 290 | if (!P.moon) u.moonCol.value.copy(L(P.sunCol)); else u.moonCol.value.set(0xdde6ff).convertSRGBToLinear(); |
279 | | - sun.color.copy(L(P.sunCol)); sun.intensity = P.sunI; sun.castShadow = opts.shadows !== false && !!P.sunShadow && (P.shadowHi < 0.5 || !P.shadowHi || Q.name === 'high'); |
| 291 | + sun.color.copy(L(P.sunCol)); sun.intensity = P.sunI; sun.shadow.radius = (P.soft || 3) * (Q.name === 'high' ? 1.25 : 1); // shadow edge width in map texels (js/render.js widens the kernel) |
| 292 | + sun.castShadow = opts.shadows !== false && !!P.sunShadow && (P.shadowHi < 0.5 || !P.shadowHi || Q.name === 'high'); |
280 | 293 | hemi.color.copy(L(P.hemiSky)); hemi.groundColor.copy(L(P.hemiGround)); hemi.intensity = P.hemiI; |
| 294 | + E.U.uRim.value.copy(L(P.rimCol || P.hemiSky)).multiplyScalar(P.rim != null ? P.rim : 0.1); |
| 295 | + E.U.uWinC.value.copy(L(P.hemiSky)).multiplyScalar(P.hemiI).add(L(P.sunCol).multiplyScalar(P.sunI * 0.12)); // the light coming in at windows and doors |
| 296 | + // a room's own scattered light: by day a little of the window light; at night more, and warm from the lamps in the |
| 297 | + // rooms (moonlit windows alone left a hall near black and blue) |
| 298 | + if (P.grade === 'night' || P.grade === 'rain') E.U.uRoomAmb.value.copy(E.U.uWinC.value).multiplyScalar(0.2).add(new THREE.Color(0.05, 0.034, 0.018)); else E.U.uRoomAmb.value.copy(E.U.uWinC.value).multiplyScalar(0.12); |
281 | 299 | fog.color.copy(L(P.fog)); fog.near = (opts.fogD || P.fogD) * (opts.fogMul || 1); // opts.fogD: a map's own haze in place of the preset's fog.far = packMist(A.mistBase + P.mistTop - 1.8, P.mist * 0.99); |
282 | 300 | scene.background = null; |
283 | | - renderer.toneMappingExposure = P.exposure * (A.brightness || 1) * (E.Q.post ? 1 : 1.45); // Low has no grade/lift pass |
| 301 | + renderer.toneMappingExposure = P.exposure * (A.brightness || 1) * (E.Q.post ? 1 : P.grade === 'day' ? 1.2 : 1.0); // Low has no grade/lift pass |
284 | 302 | E.U.uWet.value = P.wet; E.U.uRain.value = P.rain ? 1 : 0; E.U.uDust.value = P.rain ? 0 : P.grade === 'day' ? 0.5 : 0.35; E.U.uNight.value = P.grade === 'night' || P.grade === 'rain' ? 1 : 0; |
285 | 303 | E.setWind(E.U.uWind.value.x, E.U.uWind.value.y, P.wind); |
286 | 304 | rain.visible = !!P.rain && Q.name !== 'low' || (!!P.rain && opts.rainOnLow); |
|
296 | 314 | return A; |
297 | 315 | }; |
298 | 316 | // brightness setting for players (multiplies exposure) |
299 | | - A.setBrightness = function (b) { A.brightness = b; renderer.toneMappingExposure = A.P.exposure * b * (E.Q.post ? 1 : 1.45); }; |
| 317 | + A.setBrightness = function (b) { A.brightness = b; renderer.toneMappingExposure = A.P.exposure * b * (E.Q.post ? 1 : A.P.grade === 'day' ? 1.2 : 1.0); }; |
300 | 318 | A.setFlashes = function (on) { A.flashes = !!on; if (!on) A.flashAge = 99; }; // reduced-effects setting |
301 | 319 | A.update = function (dt, camera) { |
302 | 320 | if (A.blend) A.stepBlend(dt); |
|
0 commit comments