Skip to content

Commit 90d169c

Browse files
authored
Merge pull request #314 from ngcoding10/war-render
2 parents 8cf5b5e + 8c5ddb5 commit 90d169c

17 files changed

Lines changed: 949 additions & 86 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎e63334287a3deaa3/ironveil/chars-test.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ <h1>Ironveil characters</h1>
4040
<script src="/lib/three/r187/three-addons.min.js"></script>
4141
<script src="env/texgen.js"></script>
4242
<script src="env/core.js"></script>
43+
<script src="env/rooms.js"></script>
4344
<script src="chars.js"></script>
4445
<script>
4546
(function () {

‎e63334287a3deaa3/ironveil/chars.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
}
112112
if (m.normalMap) m.normalScale.set(1, 1);
113113
if (m.map) m.map.anisotropy = 4;
114+
if (window.IVEnv && IVEnv.rimPatch) IVEnv.rimPatch(m); // edge light so a soldier reads against the dark (env/rooms.js)
114115
}
115116

116117
// ---------- clips

‎e63334287a3deaa3/ironveil/env-test.html‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<script src="/lib/three/r187/three.min.js"></script>
3030
<script src="env/texgen.js"></script>
3131
<script src="env/core.js"></script>
32+
<script src="env/rooms.js"></script>
3233
<script src="env/atmosphere.js"></script>
3334
<script src="env/grass.js"></script>
3435
<script src="env/ground.js"></script>
@@ -37,8 +38,8 @@
3738
<script src="env/nature.js"></script>
3839
<script src="env/props.js"></script>
3940
<script src="env/decals.js"></script>
40-
<script src="env/post.js"></script>
4141
<script src="env/index.js"></script>
42+
<script src="js/render.js"></script>
4243
<script>
4344
(function () {
4445
'use strict';
@@ -181,7 +182,7 @@
181182
atmo = E.atmosphere(scene, renderer, preset, { mistBase: -2.2 });
182183
ground = E.ground(height, { surfaceAt, x0: -130, z0: -130, x1: 130, z1: 130 });
183184
scene.add(ground.group);
184-
window.T.post = E.post(renderer, scene, camera, quality); resize();
185+
window.T.post = IVRender.create(renderer, scene, camera, quality); resize(); // the game's frame pipeline (js/render.js)
185186
grass = E.grass(surfaceAt, height, { longAt });
186187
scene.add(grass.group);
187188
// lamp posts along the lane and in the yard (real props, each with a point light and a glow)

‎e63334287a3deaa3/ironveil/env/atmosphere.js‎

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
// sRGB hex helper -> linear THREE.Color
1313
const L = (h) => E.lin(h);
1414
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.
1518
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
1922
},
2023
night_overcast: {
2124
skyTop: 0x080a0d, skyHor: 0x1b1f25, ground: 0x0b0c0d, fog: 0x171b20, fogD: 0.0135, mist: 0.7, mistTop: 2.2,
@@ -44,10 +47,14 @@
4447
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,
4548
hemiSky: 0x7a8494, hemiGround: 0x2e2c2a, hemiI: 0.85, env: 0.8, exposure: 1.0, wind: 1.3, wet: 1.0, rain: 1, grade: 'rain'
4649
},
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.
4754
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
5158
}
5259
};
5360

@@ -134,17 +141,23 @@
134141

135142
// ------------------------------------------------------------------ sky
136143
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.
137148
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;
139150
varying vec3 vD;
140151
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; }
141152
void main(){
142153
vec3 d = normalize(vD);
143154
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);
144158
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));
145160
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
148161
if (starAmt > 0.0 && h > 0.0) {
149162
vec2 sp = vec2(atan(d.z, d.x) * 180.0, asin(clamp(h, -1.0, 1.0)) * 180.0);
150163
vec2 ci = floor(sp), cf = fract(sp) - 0.5;
@@ -153,42 +166,41 @@
153166
star *= (0.5 + 0.5 * b) * (0.8 + 0.2 * sin(time * (2.0 + b * 3.0) + r * 40.0));
154167
c += vec3(0.55, 0.6, 0.75) * star * starAmt * smoothstep(0.0, 0.25, h);
155168
}
156-
// moon: disc with soft halo
157169
if (moonAmt > 0.0) {
158170
float disc = smoothstep(0.99955, 0.99975, md);
159171
float mare = 0.8 + 0.2 * ivN(d.xy * 900.0);
160172
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;
162173
}
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;
164177
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);
169181
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;
178191
if (flash > 0.0) {
179192
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;
183196
}
184-
// structure: slow darker bands of heavier cloud base, and (by day) a brighter thin patch toward the hidden sun
185197
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);
189201
}
202+
c += halo * (1.0 - 0.7 * cov);
190203
c *= bright;
191-
// dither against banding (one 8-bit step)
192204
c += (ivH(gl_FragCoord.xy + fract(time) * 61.0) - 0.5) / 255.0;
193205
gl_FragColor = vec4(c, 1.0);
194206
}`;
@@ -197,7 +209,7 @@
197209
uniforms: {
198210
top: { value: new THREE.Color() }, hor: { value: new THREE.Color() }, gnd: { value: new THREE.Color() }, moonDir: { value: new THREE.Vector3(0, 1, 0) },
199211
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() }
201213
},
202214
vertexShader: SKY_VS, fragmentShader: SKY_FS, side: THREE.BackSide, depthWrite: false, depthTest: true, fog: false, toneMapped: true
203215
});
@@ -274,13 +286,19 @@
274286
A.dir.set(P.sunDir[0], P.sunDir[1], P.sunDir[2]).normalize();
275287
const u = sky.uniforms;
276288
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;
278290
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');
280293
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);
281299
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);
282300
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
284302
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;
285303
E.setWind(E.U.uWind.value.x, E.U.uWind.value.y, P.wind);
286304
rain.visible = !!P.rain && Q.name !== 'low' || (!!P.rain && opts.rainOnLow);
@@ -296,7 +314,7 @@
296314
return A;
297315
};
298316
// 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); };
300318
A.setFlashes = function (on) { A.flashes = !!on; if (!on) A.flashAge = 99; }; // reduced-effects setting
301319
A.update = function (dt, camera) {
302320
if (A.blend) A.stepBlend(dt);

‎e63334287a3deaa3/ironveil/env/build.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,12 @@
935935
house(B2, S2, { w, d, T, floors: 1, storey, out: 'planks', in: 'plaster_interior', roof: 'slate', ridgeMat: 'slate', pitch: 0.42, over: 0.4, gableOver: 0.3, head: 'timber', doorHead: 'timber', shutters: false, quoins: false, front: sideW, back: sideW.map(o => Object.assign({}, o)), right: door, left: end, sill: false, trim: true, sag: 0.03 });
936936
mergeB(B, B2, 0, 0, 0, lift);
937937
S.windows.push(...S2.windows.map(o => Object.assign({}, o, { y: o.y + lift })));
938+
// inside: tie beams across at the eaves, a pair of rafters on each, a ridge board (no flat black ceiling)
939+
{ const rise = d / 2 * Math.tan(0.42), y0 = lift + storey, len = Math.hypot(d / 2, rise), nb = Math.max(3, Math.round(w / 1.8));
940+
for (let i = 0; i < nb; i++) { const x = -w / 2 + T + 0.3 + (w - 2 * T - 0.6) * i / (nb - 1);
941+
B.box('timber', x, y0 - 0.16, 0, 0.1, 0.15, d - 2 * T, 0, { grain: 'long', noFoot: true });
942+
for (const side of [1, -1]) B.box('timber', x, y0 + rise / 2 - 0.2, side * d / 4, 0.08, 0.13, len - 0.1, 0, { rx: side * 0.42, grain: 'long', noFoot: true }); }
943+
B.box('timber', 0, y0 + rise - 0.24, 0, w - 2 * T, 0.16, 0.05, 0, { grain: 'long', noFoot: true }); }
938944
// plinth with air bricks, and the floor
939945
B.box('brick_red', 0, -0.25, 0, w + 0.06, lift + 0.25, d + 0.06, 0, { tint: tintJ(R, 0.05) });
940946
for (let i = 0; i < 4; i++) for (const s of [-1, 1]) B.box('metal_rust', -w / 2 + (i + 0.5) * w / 4, 0.18, s * (d / 2 + 0.035), 0.22, 0.07, 0.01, 0, { noFoot: true, tint: new THREE.Color(0.4, 0.4, 0.4) });

0 commit comments

Comments
 (0)