roamwright 0.61.28 → 0.61.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/examples/fliers.js +33 -0
- package/examples/land-features.js +19 -0
- package/examples/troops.js +37 -0
- package/geometry/bridge-masonry.js +414 -0
- package/geometry/builder.js +7 -12
- package/geometry/index.js +8 -1
- package/geometry/part-ops.js +152 -0
- package/motion/crawler-pack.js +138 -2
- package/motion/index.js +1 -1
- package/package.json +1 -1
- package/rendering/crawler-pack.js +44 -1
- package/rendering/flier-long-body-company.js +2 -0
- package/rendering/flocks.js +27 -22
- package/rendering/height-probe.js +7 -4
- package/rendering/house-kit-meshes.js +15 -10
- package/rendering/index.js +2 -1
- package/rendering/lamp-wash.js +2 -0
- package/rendering/material-lod.js +50 -26
- package/rendering/road-traffic.js +268 -0
- package/rendering/scene-projectiles.js +3 -0
- package/rendering/settlement-town.js +6 -1
- package/rendering/ship-meshes.js +10 -7
- package/rendering/street-lamps.js +4 -1
- package/rendering/surface-material.js +60 -24
- package/rendering/surface-snippets.js +83 -45
- package/rendering/vehicle-train.js +1 -0
- package/rendering/water-material.js +9 -0
- package/scripts/build.py +5 -3
|
@@ -42,7 +42,15 @@ const S = 'uLook.x',
|
|
|
42
42
|
STOREY = 'uFloors.x',
|
|
43
43
|
TIMBER = 'uFloors.y',
|
|
44
44
|
WINW = 'uFloors.z',
|
|
45
|
-
WINH = 'uFloors.w'
|
|
45
|
+
WINH = 'uFloors.w',
|
|
46
|
+
// Triplanar non-skin surfaces reuse uFloors (unused outside kind === 'wall') for uniform-gated feature switches
|
|
47
|
+
// so stone, rock, wood, plaster, mossed stone, and bedded rock share one WebGL program.
|
|
48
|
+
TRI_TAG = 'uFloors.x',
|
|
49
|
+
TRI_WASH = 'uFloors.y',
|
|
50
|
+
TRI_BEDS = 'uFloors.z',
|
|
51
|
+
TRI_NIGHT = 'uFloors.w',
|
|
52
|
+
WALL_LAMP = 'uMore.z',
|
|
53
|
+
ROOF_TILE = 'uFloors.x';
|
|
46
54
|
|
|
47
55
|
function defaultSurfaceUniforms() {
|
|
48
56
|
return {
|
|
@@ -123,19 +131,28 @@ export function createSurfaceMaterialFactory({
|
|
|
123
131
|
side: o.side ?? THREE.FrontSide,
|
|
124
132
|
};
|
|
125
133
|
const look = { value: new THREE.Vector4(o.scale ?? 0.16, o.gain ?? 1.7, o.bump ?? 4, o.base ?? 0) };
|
|
126
|
-
const
|
|
127
|
-
const floors = { value: new THREE.Vector4(o.storey ?? 3, o.timber ?? 0, o.windowW ?? 0, o.windowH ?? 0) };
|
|
128
|
-
|
|
129
|
-
const garment = o.skin ? garmentShader({ scale: S, threads: clothThreads, smoothness: hair.smoothOf('vSk'), wear: garmentWear }) : null;
|
|
130
|
-
const ruin = (o.windows ?? 1) === 0;
|
|
134
|
+
const isWall = o.kind === 'wall';
|
|
131
135
|
const leaf = o.kind === 'leaf';
|
|
132
136
|
const roof = o.kind === 'roof' || o.kind === 'tile';
|
|
137
|
+
const triPlain = !isWall && !roof && !leaf && !o.skin;
|
|
133
138
|
const useLamp = lampWash && !!o.lamp;
|
|
134
139
|
const useLampWall = lampWash && !!o.lampWall;
|
|
135
|
-
const useCityLight = lampWash && !!(o.tag ||
|
|
140
|
+
const useCityLight = lampWash && !!(triPlain || o.tag || isWall);
|
|
141
|
+
const more = {
|
|
142
|
+
value: new THREE.Vector4(o.windows ?? 1, o.gas ?? 0, isWall ? (useLampWall ? 1 : 0) : (o.moss ?? 0), o.fine ?? 0),
|
|
143
|
+
};
|
|
144
|
+
const floors = {
|
|
145
|
+
value: triPlain
|
|
146
|
+
? new THREE.Vector4(o.tag ? 1 : 0, o.wash ? 1 : 0, o.beds || 0, o.tag || o.night ? 1 : 0)
|
|
147
|
+
: roof
|
|
148
|
+
? new THREE.Vector4(o.kind === 'tile' ? 1 : 0, 0, 0, 0)
|
|
149
|
+
: new THREE.Vector4(o.storey ?? 3, o.timber ?? 0, o.windowW ?? 0, o.windowH ?? 0),
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const garment = o.skin ? garmentShader({ scale: S, threads: clothThreads, smoothness: hair.smoothOf('vSk'), wear: garmentWear }) : null;
|
|
136
153
|
|
|
137
154
|
let map;
|
|
138
|
-
if (
|
|
155
|
+
if (isWall) {
|
|
139
156
|
map = facadeColorGLSL({
|
|
140
157
|
scale: S,
|
|
141
158
|
gain: G,
|
|
@@ -146,16 +163,27 @@ export function createSurfaceMaterialFactory({
|
|
|
146
163
|
timber: TIMBER,
|
|
147
164
|
windowW: WINW,
|
|
148
165
|
windowH: WINH,
|
|
149
|
-
ruin,
|
|
150
|
-
lampWall:
|
|
166
|
+
ruin: 'uniform',
|
|
167
|
+
lampWall: useCityLight ? WALL_LAMP : false,
|
|
151
168
|
lampWash,
|
|
152
169
|
});
|
|
153
|
-
} else if (
|
|
154
|
-
map =
|
|
155
|
-
|
|
156
|
-
|
|
170
|
+
} else if (roof) {
|
|
171
|
+
map = `/* glsl */
|
|
172
|
+
if (${ROOF_TILE} > 0.5) {
|
|
173
|
+
${tileRoofColorGLSL({ scale: S, gain: G })}
|
|
174
|
+
} else {
|
|
175
|
+
${roofColorGLSL({ scale: S, gain: G })}
|
|
176
|
+
}`;
|
|
157
177
|
} else if (leaf) {
|
|
158
178
|
map = foliageColorGLSL({ scale: S });
|
|
179
|
+
} else if (triPlain) {
|
|
180
|
+
map = `/* glsl */
|
|
181
|
+
${triplanarColor({ texture: 'uTex', scale: S, gain: G, height: 'gH' })}
|
|
182
|
+
float wallHeight = vWy - 1000.0 * step(500.0, vWy);${beddedRockGLSL(TRI_BEDS)}${fineGrainGLSL(FINE)}${mossAndLichenGLSL({
|
|
183
|
+
scale: S,
|
|
184
|
+
moss: MOSS,
|
|
185
|
+
tagged: TRI_TAG,
|
|
186
|
+
})}${weatheredWallGLSL({ wash: TRI_WASH, dustTint: wallDustTint, lampWash, gas: GAS, enabled: TRI_TAG })}`;
|
|
159
187
|
} else {
|
|
160
188
|
map = `/* glsl */
|
|
161
189
|
${triplanarColor({ texture: 'uTex', scale: S, gain: G, height: 'gH' })}${o.tag ? '\nfloat wallHeight = vWy - 1000.0 * step(500.0, vWy);' : ''}${
|
|
@@ -195,29 +223,37 @@ ${triplanarColor({ texture: 'uTex', scale: S, gain: G, height: 'gH' })}${o.tag ?
|
|
|
195
223
|
uniforms.uActorWear = actorWearUniform;
|
|
196
224
|
}
|
|
197
225
|
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
|
|
226
|
+
const nightSkyVec = wallNightSky.map(c => (c * wallNight * Math.PI).toFixed(4)).join(', ');
|
|
227
|
+
const nightIrradiance = triPlain
|
|
228
|
+
? `irradiance += vec3(${nightSkyVec}) * uNight * uNightSky * ${TRI_NIGHT} * (1.0 - abs(normalize(vLN).y));`
|
|
229
|
+
: o.tag || o.kind === 'wall' || o.night
|
|
230
|
+
? `irradiance += vec3(${nightSkyVec}) * uNight * uNightSky * (1.0 - abs(normalize(vLN).y));`
|
|
201
231
|
: '';
|
|
202
232
|
|
|
203
|
-
const cacheKey =
|
|
204
|
-
'surf:' +
|
|
205
|
-
|
|
206
|
-
|
|
233
|
+
const cacheKey = triPlain
|
|
234
|
+
? 'surf:tri:' + [!!o.flat, useLamp].join(':') + (lampWash ? '' : ':nolamp')
|
|
235
|
+
: isWall
|
|
236
|
+
? 'surf:wall:' + !!o.flat + (lampWash ? '' : ':nolamp')
|
|
237
|
+
: roof
|
|
238
|
+
? 'surf:roof:' + !!o.flat + (lampWash ? '' : ':nolamp')
|
|
239
|
+
: 'surf:' +
|
|
240
|
+
[o.kind, !!o.moss, !!o.fine, o.beds || 0, !!o.flat, !!o.tag, !!o.wash, !!o.skin, useLamp, useLampWall, !!o.night].join(':') +
|
|
241
|
+
(lampWash ? '' : ':nolamp');
|
|
207
242
|
|
|
243
|
+
const hasWallTag = triPlain || !!o.tag;
|
|
208
244
|
const mat = createProjectedMaterial(parameters, {
|
|
209
245
|
cacheKey,
|
|
210
246
|
uniforms,
|
|
211
247
|
vertex: {
|
|
212
248
|
declarations:
|
|
213
249
|
(leaf ? '\nattribute float aLeaf; varying float vLeaf; uniform float uTime; uniform vec3 uWind;' + WIND_SWAY_GLSL : '') +
|
|
214
|
-
(
|
|
250
|
+
(hasWallTag ? '\nattribute float aTag; varying float vWy;' : '') +
|
|
215
251
|
(o.skin ? '\nattribute float aTag; varying float vSk;' : '') +
|
|
216
252
|
(useLamp ? '\nuniform sampler2D uLampMap; uniform vec4 uLampR; uniform float uNight; varying float vLamp;' : ''),
|
|
217
253
|
deformInstance: leaf
|
|
218
254
|
? 'transformed.xz += aLeaf * windSway(instanceMatrix[3].xyz, position.y, 0.004, 0.008, position.y * 0.6);'
|
|
219
255
|
: '',
|
|
220
|
-
assign: `${leaf ? ' vLeaf = aLeaf;' : ''}${
|
|
256
|
+
assign: `${leaf ? ' vLeaf = aLeaf;' : ''}${hasWallTag ? ' vWy = position.y - aTag;' : ''}${
|
|
221
257
|
o.skin ? ` vSk = aTag${o.tagSteps ? ' / ' + o.tagSteps.toFixed(1) : ''};` : ''
|
|
222
258
|
}${
|
|
223
259
|
useLamp
|
|
@@ -235,7 +271,7 @@ ${triplanarColor({ texture: 'uTex', scale: S, gain: G, height: 'gH' })}${o.tag ?
|
|
|
235
271
|
`\nuniform sampler2D uTex; uniform float uNight, uNightSky, uDamp;${lampWash ? ' uniform vec3 uGas;' : ''} uniform vec4 uLook, uMore, uFloors; ` +
|
|
236
272
|
projectedVaryings +
|
|
237
273
|
(leaf ? ' varying float vLeaf; uniform float uSunLight;' : '') +
|
|
238
|
-
(
|
|
274
|
+
(hasWallTag ? ' varying float vWy;' : '') +
|
|
239
275
|
(useLamp ? ' varying float vLamp;' : '') +
|
|
240
276
|
(useCityLight ? ' uniform sampler2D uLampMap;' : '') +
|
|
241
277
|
(roof ? LOW_LIGHT_REFLECTANCE : '') +
|
|
@@ -23,8 +23,8 @@ import { groundDustGradient } from './surface-projection.js';
|
|
|
23
23
|
* @param {string} options.timber GLSL expression enabling timber-framed upper storeys.
|
|
24
24
|
* @param {string} options.windowW GLSL expression for district window width in metres (0 for fixed grid).
|
|
25
25
|
* @param {string} options.windowH GLSL expression for district window height in metres.
|
|
26
|
-
* @param {boolean} [options.ruin=false] Omit doors, glazing bars, shutters, and lit interiors.
|
|
27
|
-
* @param {boolean} [options.lampWall=false] Use local lamp map sampling instead of ambient city wash.
|
|
26
|
+
* @param {boolean | 'uniform'} [options.ruin=false] Omit doors, glazing bars, shutters, and lit interiors (`'uniform'` switches via `${windows} <= 0.0`).
|
|
27
|
+
* @param {boolean | string} [options.lampWall=false] Use local lamp map sampling instead of ambient city wash (boolean or uniform GLSL expression `> 0.5`).
|
|
28
28
|
* @param {boolean} [options.lampWash=true] Emit night lamp wash on the facade.
|
|
29
29
|
* @returns {string} GLSL snippet for `#include <map_fragment>`.
|
|
30
30
|
*/
|
|
@@ -42,9 +42,52 @@ export function facadeColorGLSL({
|
|
|
42
42
|
lampWall = false,
|
|
43
43
|
lampWash = true,
|
|
44
44
|
}) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const uniformRuin = ruin === 'uniform';
|
|
46
|
+
const lampExpr =
|
|
47
|
+
typeof lampWall === 'string'
|
|
48
|
+
? `(${lampWall} > 0.5 ? localLampGlow(cityLight(vCW).r, wy) * (0.5 + gH) : exp(-max(wy, 0.0) * 0.28) * gasHere())`
|
|
49
|
+
: lampWall
|
|
50
|
+
? 'localLampGlow(cityLight(vCW).r, wy) * (0.5 + gH)'
|
|
51
|
+
: 'exp(-max(wy, 0.0) * 0.28) * gasHere()';
|
|
52
|
+
const lampLine = lampWash ? `\n if (uNight > 0.0) gGlow = ${lampExpr} * ${gas};` : '';
|
|
53
|
+
const doorFaceExpr = uniformRuin ? '(1.0 - isRuin)' : ruin ? '0.0' : '1.0';
|
|
54
|
+
const hasThresh = uniformRuin ? 'mix(0.3, 0.45, isRuin)' : ruin ? '0.45' : '0.3';
|
|
55
|
+
const muntExpr = uniformRuin
|
|
56
|
+
? '(1.0 - isRuin) * open * max(step(abs(wc.x), 0.07), step(abs(wc.y + 0.12), 0.06))'
|
|
57
|
+
: ruin
|
|
58
|
+
? '0.0'
|
|
59
|
+
: 'open * max(step(abs(wc.x), 0.07), step(abs(wc.y + 0.12), 0.06))';
|
|
60
|
+
const shutExpr = uniformRuin
|
|
61
|
+
? '(1.0 - isRuin) * step(0.55, fract(vSeed * 3.7)) * has * step(1.24, abs(wc.x)) * step(abs(wc.x), 1.96) * step(abs(wc.y), 1.02)'
|
|
62
|
+
: ruin
|
|
63
|
+
? '0.0'
|
|
64
|
+
: 'step(0.55, fract(vSeed * 3.7)) * has * step(1.24, abs(wc.x)) * step(abs(wc.x), 1.96) * step(abs(wc.y), 1.02)';
|
|
65
|
+
const winWeight = uniformRuin ? `mix(${windows}, 1.0, isRuin)` : ruin ? '1.0' : windows;
|
|
66
|
+
const litExpr = uniformRuin
|
|
67
|
+
? '(1.0 - isRuin) * open * (1.0 - munt) * step(0.7, fract(r * 7.13 + 0.2))'
|
|
68
|
+
: ruin
|
|
69
|
+
? '0.0'
|
|
70
|
+
: 'open * (1.0 - munt) * step(0.7, fract(r * 7.13 + 0.2))';
|
|
71
|
+
const interiorBlock =
|
|
72
|
+
ruin === true
|
|
73
|
+
? ''
|
|
74
|
+
: `if (open > 0.0${uniformRuin ? ' && isRuin < 0.5' : ''}) { // each window its own: curtains of dyed cloth drawn to the sides or nearly shut, an inner shutter half closed, and behind a lit one a room
|
|
75
|
+
float r2 = fract(r * 31.7 + 0.13), r3 = fract(r * 5.13 + 0.41), r4 = fract(r * 3.31 + 0.77);
|
|
76
|
+
float cw = mix(0.22, 0.9, r3 * r3), curt = step(0.35, r2) * open * max(step(1.0 - cw, abs(wc.x)), step(0.78, wc.y));
|
|
77
|
+
float ishut = step(0.8, r4) * open * step(wc.x, -0.04) * (1.0 - curt);
|
|
78
|
+
vec3 cloth = r2 < 0.55 ? vec3(0.42, 0.12, 0.09) : r2 < 0.7 ? vec3(0.5, 0.38, 0.17) : r2 < 0.85 ? vec3(0.62, 0.58, 0.5) : vec3(0.16, 0.27, 0.19);
|
|
79
|
+
float fold = 0.72 + 0.28 * sin(wc.x * 21.0 + r * 9.0);
|
|
80
|
+
diffuseColor.rgb = mix(diffuseColor.rgb, cloth * fold * 0.8, curt);
|
|
81
|
+
diffuseColor.rgb = mix(diffuseColor.rgb, vec3(0.21, 0.14, 0.085) * (0.8 + 0.2 * step(0.5, fract(wc.x * 2.6))), ishut); // plain boards inside the glass
|
|
82
|
+
if (uNight > 0.0 && gLit > 0.0) {
|
|
83
|
+
gWarm = floor(fract(r * 13.71) * 3.0) * 0.5;
|
|
84
|
+
gPower = 0.7 + 0.58 * fract(r * 17.71);
|
|
85
|
+
float lx = (fract(r * 71.3) - 0.5) * 1.2, hot = exp(-((wc.x - lx) * (wc.x - lx) * 2.2 + (wc.y - 0.15) * (wc.y - 0.15) * 3.0));
|
|
86
|
+
float furn = step(wc.y, -0.42 + 0.22 * step(0.5, fract((wc.x + r) * 1.7))) * step(0.3, fract(r * 13.1 + floor((wc.x + 1.0) * 1.6) * 0.29));
|
|
87
|
+
gTint = mix(vec3(0.55 + 0.75 * hot) * (1.0 - 0.75 * furn) * (0.75 + 0.25 * smoothstep(-1.0, 1.0, wc.y)), cloth * 1.1 * fold, curt);
|
|
88
|
+
}
|
|
89
|
+
gLit *= 1.0 - ishut; gH += (curt * 0.25 + ishut * 0.4) * gWin;
|
|
90
|
+
}`;
|
|
48
91
|
return `/* glsl */
|
|
49
92
|
vec3 bw = abs(vLN);
|
|
50
93
|
vec2 wuv = bw.y > 0.5 ? vL.xz : (bw.x > 0.5 ? vL.zy : vL.xy);
|
|
@@ -72,13 +115,13 @@ export function facadeColorGLSL({
|
|
|
72
115
|
float timber = mix(0.22, max(max(post, rail), brace), smoothstep(0.2, 0.09, max(ax, ay))) * framed; // finer than a pixel: the frame's share of the wall
|
|
73
116
|
diffuseColor.rgb = mix(diffuseColor.rgb, vec3(0.07, 0.042, 0.026) * (0.75 + 0.5 * gH), timber); gH += timber * 0.3;
|
|
74
117
|
}
|
|
75
|
-
if (halfW > 1.3) {
|
|
118
|
+
if (halfW > 1.3) {${uniformRuin ? `\n float isRuin = step(${windows}, 0.0);` : ''}
|
|
76
119
|
vec2 gq = vec2(gx, wy / ${storey}); vec2 cell = floor(gq), fq = fract(gq);
|
|
77
120
|
float r = fract(sin(dot(cell + floor(vSeed * 13.0), vec2(12.9898, 78.233))) * 43758.5453);
|
|
78
|
-
float isDoorFace = step(0.5, bw.z) * ${
|
|
121
|
+
float isDoorFace = step(0.5, bw.z) * ${doorFaceExpr};
|
|
79
122
|
float door = step(abs(wuv.x), 0.62) * step(wy, 2.3) * step(0.0, wy) * isDoorFace;
|
|
80
123
|
float dframe = step(abs(wuv.x), 0.84) * step(wy, 2.54) * step(0.0, wy) * isDoorFace - door;
|
|
81
|
-
float has = step(${
|
|
124
|
+
float has = step(${hasThresh}, r) * step(0.2, wy) * step(wy, hgt - 0.5) * step(abs(wuv.x), halfW - 0.6) * (1.0 - step(abs(wuv.x), 1.25) * step(wy, ${storey}) * isDoorFace);
|
|
82
125
|
vec2 wc = (fq - vec2(0.5, 0.58)) / vec2(0.2, 0.22);
|
|
83
126
|
if (${windowW} > 0.0) { // a near house's window: its sill 1.05 m over the floor below and 0.88 m over the upper ones
|
|
84
127
|
float ground = step(cell.y, 0.5), wh = min(${windowH}, ${storey} - mix(1.45, 1.7, ground)), wb = mix(0.88, 1.05, ground);
|
|
@@ -87,33 +130,13 @@ export function facadeColorGLSL({
|
|
|
87
130
|
float open = step(abs(wc.x), 1.0) * step(abs(wc.y), 1.0) * has;
|
|
88
131
|
float frame = step(abs(wc.x), 1.24) * step(abs(wc.y), 1.2) * has - open; // stone surround
|
|
89
132
|
float sill = step(abs(wc.x), 1.42) * step(-1.44, wc.y) * step(wc.y, -1.2) * has;
|
|
90
|
-
float munt = ${
|
|
91
|
-
float shut = ${
|
|
92
|
-
gWin = open * (1.0 - munt) * ${
|
|
93
|
-
gLit = ${
|
|
133
|
+
float munt = ${muntExpr}; // glazing bars
|
|
134
|
+
float shut = ${shutExpr};
|
|
135
|
+
gWin = open * (1.0 - munt) * ${winWeight};
|
|
136
|
+
gLit = ${litExpr}; // a lit window shines across the pane
|
|
94
137
|
vec3 glass = vec3(0.028, 0.04, 0.06) * (1.0 - 0.6 * smoothstep(0.2, 1.0, wc.y)); // darker under the lintel
|
|
95
138
|
diffuseColor.rgb = mix(diffuseColor.rgb, glass, gWin);
|
|
96
|
-
${
|
|
97
|
-
ruin
|
|
98
|
-
? ''
|
|
99
|
-
: `if (open > 0.0) { // each window its own: curtains of dyed cloth drawn to the sides or nearly shut, an inner shutter half closed, and behind a lit one a room
|
|
100
|
-
float r2 = fract(r * 31.7 + 0.13), r3 = fract(r * 5.13 + 0.41), r4 = fract(r * 3.31 + 0.77);
|
|
101
|
-
float cw = mix(0.22, 0.9, r3 * r3), curt = step(0.35, r2) * open * max(step(1.0 - cw, abs(wc.x)), step(0.78, wc.y));
|
|
102
|
-
float ishut = step(0.8, r4) * open * step(wc.x, -0.04) * (1.0 - curt);
|
|
103
|
-
vec3 cloth = r2 < 0.55 ? vec3(0.42, 0.12, 0.09) : r2 < 0.7 ? vec3(0.5, 0.38, 0.17) : r2 < 0.85 ? vec3(0.62, 0.58, 0.5) : vec3(0.16, 0.27, 0.19);
|
|
104
|
-
float fold = 0.72 + 0.28 * sin(wc.x * 21.0 + r * 9.0);
|
|
105
|
-
diffuseColor.rgb = mix(diffuseColor.rgb, cloth * fold * 0.8, curt);
|
|
106
|
-
diffuseColor.rgb = mix(diffuseColor.rgb, vec3(0.21, 0.14, 0.085) * (0.8 + 0.2 * step(0.5, fract(wc.x * 2.6))), ishut); // plain boards inside the glass
|
|
107
|
-
if (uNight > 0.0 && gLit > 0.0) {
|
|
108
|
-
gWarm = floor(fract(r * 13.71) * 3.0) * 0.5;
|
|
109
|
-
gPower = 0.7 + 0.58 * fract(r * 17.71);
|
|
110
|
-
float lx = (fract(r * 71.3) - 0.5) * 1.2, hot = exp(-((wc.x - lx) * (wc.x - lx) * 2.2 + (wc.y - 0.15) * (wc.y - 0.15) * 3.0));
|
|
111
|
-
float furn = step(wc.y, -0.42 + 0.22 * step(0.5, fract((wc.x + r) * 1.7))) * step(0.3, fract(r * 13.1 + floor((wc.x + 1.0) * 1.6) * 0.29));
|
|
112
|
-
gTint = mix(vec3(0.55 + 0.75 * hot) * (1.0 - 0.75 * furn) * (0.75 + 0.25 * smoothstep(-1.0, 1.0, wc.y)), cloth * 1.1 * fold, curt);
|
|
113
|
-
}
|
|
114
|
-
gLit *= 1.0 - ishut; gH += (curt * 0.25 + ishut * 0.4) * gWin;
|
|
115
|
-
}`
|
|
116
|
-
}
|
|
139
|
+
${interiorBlock}
|
|
117
140
|
diffuseColor.rgb = mix(diffuseColor.rgb, vec3(0.15, 0.11, 0.08), munt);
|
|
118
141
|
diffuseColor.rgb *= 1.0 + frame * 0.26 + sill * 0.34 + dframe * 0.24;
|
|
119
142
|
vec3 shc = mix(vec3(0.09, 0.2, 0.18), vec3(0.28, 0.1, 0.08), step(0.5, fract(vSeed * 5.3)));
|
|
@@ -182,15 +205,18 @@ export function foliageColorGLSL({ scale }) {
|
|
|
182
205
|
|
|
183
206
|
/**
|
|
184
207
|
* Horizontal bedding laminae for sedimentary rock faces, fading via `fwidth` before sub-pixel aliasing.
|
|
208
|
+
* Accepts either a fixed number of laminae per metre or a uniform GLSL expression (skipped when `<= 0`).
|
|
185
209
|
*
|
|
186
|
-
* @param {number} beds Laminae per metre.
|
|
210
|
+
* @param {number | string} beds Laminae per metre or GLSL uniform expression.
|
|
187
211
|
* @returns {string} GLSL snippet appended after `triplanarColor`.
|
|
188
212
|
*/
|
|
189
213
|
export function beddedRockGLSL(beds) {
|
|
214
|
+
const expr = typeof beds === 'string' ? beds : beds.toFixed(2);
|
|
215
|
+
const open = typeof beds === 'string' ? `if (${expr} > 0.0) {` : '{';
|
|
190
216
|
return `
|
|
191
|
-
{ // laminae of a bedded rock, o.beds to the metre, wandering a little: on its faces, not on what faces the sky. Each fades
|
|
217
|
+
${open} // laminae of a bedded rock, o.beds to the metre, wandering a little: on its faces, not on what faces the sky. Each fades
|
|
192
218
|
// as it nears a pixel's height, so a far face is even, not striped
|
|
193
|
-
float ly = vL.y * ${
|
|
219
|
+
float ly = vL.y * ${expr} + 1.7 * texture2D(uTex, vec2(vL.x + vL.z, vL.y * 0.2) * 0.031).g;
|
|
194
220
|
float lam = sin(ly * 6.2832) * (1.0 - smoothstep(0.05, 0.18, fwidth(ly))) * (1.0 - smoothstep(0.45, 0.8, abs(vLN.y)));
|
|
195
221
|
diffuseColor.rgb *= 1.0 + 0.07 * lam;
|
|
196
222
|
gH += 0.18 * lam; }`;
|
|
@@ -198,13 +224,15 @@ export function beddedRockGLSL(beds) {
|
|
|
198
224
|
|
|
199
225
|
/**
|
|
200
226
|
* Secondary close-range triplanar grain so large stone and rock faces keep fine detail at walking height.
|
|
227
|
+
* Guarded by `${fineScale} > 0.0` so materials without fine grain share one program with zero extra texture reads.
|
|
201
228
|
*
|
|
202
229
|
* @param {string} fineScale GLSL expression for the fine grain scale.
|
|
203
230
|
* @returns {string} GLSL snippet appended after `triplanarColor`.
|
|
204
231
|
*/
|
|
205
232
|
export function fineGrainGLSL(fineScale) {
|
|
206
233
|
return `
|
|
207
|
-
{
|
|
234
|
+
if (${fineScale} > 0.0) {
|
|
235
|
+
float fk = 1.0 - smoothstep(6.0, 45.0, length(vViewPosition));
|
|
208
236
|
if (fk > 0.0) {
|
|
209
237
|
vec3 fp = vL * ${fineScale} + 0.37;
|
|
210
238
|
float f = dot(texture2D(uTex, fp.zy).rgb * bw.x + texture2D(uTex, fp.xz).rgb * bw.y + texture2D(uTex, fp.xy).rgb * bw.z, vec3(0.333));
|
|
@@ -214,15 +242,22 @@ export function fineGrainGLSL(fineScale) {
|
|
|
214
242
|
|
|
215
243
|
/**
|
|
216
244
|
* Procedural moss cushions (tops, ledges, damp north faces, wall feet, and mortar joints) and pale lichen rosettes.
|
|
245
|
+
* Guarded by `${moss} > 0.0` so unmossed surfaces share one program with zero extra texture reads.
|
|
217
246
|
*
|
|
218
|
-
* @param {{ scale: string, moss: string, tagged?: boolean }} options
|
|
247
|
+
* @param {{ scale: string, moss: string, tagged?: boolean | string }} options
|
|
219
248
|
* @returns {string} GLSL snippet appended after `triplanarColor`.
|
|
220
249
|
*/
|
|
221
250
|
export function mossAndLichenGLSL({ scale, moss, tagged = false }) {
|
|
251
|
+
const footExpr =
|
|
252
|
+
typeof tagged === 'string'
|
|
253
|
+
? `${tagged} > 0.5 ? (1.0 - smoothstep(0.1, 1.4, wallHeight)) * step(abs(vLN.y), 0.5) : 0.0`
|
|
254
|
+
: tagged
|
|
255
|
+
? '(1.0 - smoothstep(0.1, 1.4, wallHeight)) * step(abs(vLN.y), 0.5)'
|
|
256
|
+
: '0.0';
|
|
222
257
|
return `
|
|
223
|
-
{ float upf = smoothstep(0.55, 0.95, vLN.y); // what faces the sky;
|
|
258
|
+
if (${moss} > 0.0) { float upf = smoothstep(0.55, 0.95, vLN.y); // what faces the sky;
|
|
224
259
|
float north = smoothstep(0.1, 0.8, -vLN.z) * (1.0 - upf); // a face turned from the sun (north is -z);
|
|
225
|
-
float foot = ${
|
|
260
|
+
float foot = ${footExpr}; // the foot of a wall, wet from the ground or the water
|
|
226
261
|
float damp = max(north * 0.75, foot); // the faces that stay wet; a top dries between rains and is walked on
|
|
227
262
|
vec3 bj = abs(vLN); vec2 fuv = bj.y > 0.5 ? vL.xz : (bj.x > 0.5 ? vL.zy : vL.xy), juv = fuv * ${scale};
|
|
228
263
|
// the joints and pits: where the stone is darker than round it. The texture's own blur (its coarser levels) takes them away
|
|
@@ -250,16 +285,18 @@ export function mossAndLichenGLSL({ scale, moss, tagged = false }) {
|
|
|
250
285
|
* optional worn limewash patches, and optional city lamp/window bounce at night.
|
|
251
286
|
*
|
|
252
287
|
* @param {object} options
|
|
253
|
-
* @param {boolean} [options.wash=false] Include worn limewash patches and sill rain runs.
|
|
288
|
+
* @param {boolean | string} [options.wash=false] Include worn limewash patches and sill rain runs (boolean or uniform expression `> 0.5`).
|
|
254
289
|
* @param {string | [number, number, number]} options.dustTint Ground dust tint RGB expression or tuple.
|
|
255
290
|
* @param {boolean} [options.lampWash=true] Sample city lamp map and ambient wash at night.
|
|
256
291
|
* @param {string} [options.gas='uMore.y'] GLSL expression for lamp wash gain.
|
|
292
|
+
* @param {string | null} [options.enabled=null] Optional uniform GLSL expression (`> 0.5`) gating the whole block.
|
|
257
293
|
* @returns {string} GLSL snippet appended after `triplanarColor`.
|
|
258
294
|
*/
|
|
259
|
-
export function weatheredWallGLSL({ wash = false, dustTint, lampWash = true, gas = 'uMore.y' }) {
|
|
260
|
-
const
|
|
295
|
+
export function weatheredWallGLSL({ wash = false, dustTint, lampWash = true, gas = 'uMore.y', enabled = null }) {
|
|
296
|
+
const washOpen = typeof wash === 'string' ? `if (${wash} > 0.5) {` : wash ? '{' : null;
|
|
297
|
+
const washBlock = washOpen
|
|
261
298
|
? `
|
|
262
|
-
{ float upr = step(abs(vLN.y), 0.5); vec2 wv = vec2(vL.x + vL.z, vL.y);
|
|
299
|
+
${washOpen} float upr = step(abs(vLN.y), 0.5); vec2 wv = vec2(vL.x + vL.z, vL.y);
|
|
263
300
|
// limewash worn through in patches a metre or two across, ragged as the moss's (differences of the texture with itself),
|
|
264
301
|
// the render under it greyer and darker, with a shadowed lip where the coat stands proud; more of them near the street
|
|
265
302
|
float pw = 0.5 + 2.0 * (texture2D(uTex, wv * 0.083 + 0.21).g - texture2D(uTex, wv * 0.061 + 0.58).r)
|
|
@@ -279,7 +316,7 @@ export function weatheredWallGLSL({ wash = false, dustTint, lampWash = true, gas
|
|
|
279
316
|
gGlow = (0.3 * exp(-max(vWy, 0.0) * 0.28) * gasHere() + localLampGlow(lm.r, lampWy)) * (0.5 + gH) * ${gas}; // a faint wash over the gaslit city, and real light where a lamp stands
|
|
280
317
|
gWindow = lm.g * exp(-max(vWy - 0.6, 0.0) * 0.7) * step(abs(vLN.y), 0.5); } // and the foot of a wall takes the warm light of a lit window across the lane`
|
|
281
318
|
: '';
|
|
282
|
-
|
|
319
|
+
const body = `
|
|
283
320
|
{ float upr = step(abs(vLN.y), 0.5);
|
|
284
321
|
float run = texture2D(uTex, vec2((vL.x + vL.z) * 0.52, vL.y * 0.019)).g; // rain runs: narrow across a wall, long down it
|
|
285
322
|
float lip = texture2D(uTex, vec2(vL.x - vL.z, 0.31) * 0.047).r; // damp rises from the ground to an uneven tide line, and greens the foot of the wall
|
|
@@ -289,6 +326,7 @@ export function weatheredWallGLSL({ wash = false, dustTint, lampWash = true, gas
|
|
|
289
326
|
diffuseColor.rgb = mix(diffuseColor.rgb, diffuseColor.rgb * vec3(0.4, 0.45, 0.35) * (0.75 + 0.5 * tx.g), damp * 0.85); // wet and greened below it, mottled
|
|
290
327
|
diffuseColor.rgb = mix(diffuseColor.rgb, vec3(0.62, 0.6, 0.55), salt * 0.22); } // a pale fringe of salts where it dries
|
|
291
328
|
${groundDustGradient({ height: 'wallHeight', dustTint })}${washBlock}${lampBlock}`;
|
|
329
|
+
return enabled ? `\n if (${enabled} > 0.5) {${body}\n }` : body;
|
|
292
330
|
}
|
|
293
331
|
|
|
294
332
|
/**
|
|
@@ -49,6 +49,7 @@ export function createVehicleTrains({ kitNew, kitAt, kitInstanced, propCart, pro
|
|
|
49
49
|
const cloneUnshadowed = list =>
|
|
50
50
|
list.map(src => {
|
|
51
51
|
const m = new THREE.InstancedMesh(src.geometry, src.material, src.instanceMatrix.count);
|
|
52
|
+
if (src.instanceColor) m.instanceColor = src.instanceColor;
|
|
52
53
|
m.frustumCulled = false;
|
|
53
54
|
m.castShadow = false;
|
|
54
55
|
m.receiveShadow = src.receiveShadow;
|
|
@@ -429,12 +429,20 @@ function stillByDefault(material) {
|
|
|
429
429
|
material.defaultAttributeValues.aBank = [DEEP, 1, FAR, FAR];
|
|
430
430
|
}
|
|
431
431
|
|
|
432
|
+
/** Horizontal open-water plane without a normal attribute so it shares one water program with streams and sea grids. */
|
|
433
|
+
export function waterPlane(width, depth, widthSegments = 1, depthSegments = 1) {
|
|
434
|
+
const geometry = new THREE.PlaneGeometry(width, depth, widthSegments, depthSegments).rotateX(-Math.PI / 2);
|
|
435
|
+
geometry.deleteAttribute('normal');
|
|
436
|
+
return geometry;
|
|
437
|
+
}
|
|
438
|
+
|
|
432
439
|
/** Populate `aBank` visibility weights across a partial open-water sheet. */
|
|
433
440
|
export function partSheet(geometry, shareAt) {
|
|
434
441
|
const pos = geometry.attributes.position,
|
|
435
442
|
bank = new Float32Array(pos.count * 4);
|
|
436
443
|
for (let v = 0; v < pos.count; v++) bank.set([DEEP, shareAt(pos.getX(v), pos.getZ(v)), FAR, FAR], v * 4);
|
|
437
444
|
geometry.setAttribute('aBank', new THREE.BufferAttribute(bank, 4));
|
|
445
|
+
geometry.deleteAttribute('normal');
|
|
438
446
|
return geometry;
|
|
439
447
|
}
|
|
440
448
|
|
|
@@ -444,6 +452,7 @@ export function sheetDepths(geometry, depthAt) {
|
|
|
444
452
|
bank = new Float32Array(count * 4);
|
|
445
453
|
for (let v = 0; v < count; v++) bank.set([depthAt(v) ?? DEEP, 1, FAR, FAR], v * 4);
|
|
446
454
|
geometry.setAttribute('aBank', new THREE.BufferAttribute(bank, 4));
|
|
455
|
+
geometry.deleteAttribute('normal');
|
|
447
456
|
return geometry;
|
|
448
457
|
}
|
|
449
458
|
|
package/scripts/build.py
CHANGED
|
@@ -45,6 +45,8 @@ GLSL_COMMENTS = re.compile(r"//[^\n]*|/\*.*?\*/", re.S)
|
|
|
45
45
|
GLSL_DIRECTIVES = re.compile(r"(^[ \t]*#(?:[^\n]*\\\n)*[^\n]*(?:\n|$))", re.M)
|
|
46
46
|
PART_IMPORT = re.compile(r'(\bimport\("\./(part-[0-9A-Za-z]+\.js)"\))') # an import() of a hashed bundle
|
|
47
47
|
PRELOAD = os.environ.get("BUILD_PRELOAD_FN", "preloadParts")
|
|
48
|
+
# How long one bundling or parsing step may take: a busy machine (several builds at once) needs far more than an idle one.
|
|
49
|
+
STEP_TIMEOUT = int(os.environ.get("BUILD_STEP_TIMEOUT", "600"))
|
|
48
50
|
SPLIT_PREFIX = re.compile(r"^split:") # how scripts/bundle.mjs names a piece of a module split into parts
|
|
49
51
|
GLSL_JOINED_OPERATORS = {
|
|
50
52
|
"++",
|
|
@@ -99,7 +101,7 @@ def esbuild(args, text=None, root=None):
|
|
|
99
101
|
cwd = ROOT if root is None else Path(root)
|
|
100
102
|
cmd = [cwd / "node_modules/.bin/esbuild", "--target=es2022", "--log-level=warning"] + args
|
|
101
103
|
try:
|
|
102
|
-
r = subprocess.run(cmd, input=text, capture_output=True, text=True, timeout=
|
|
104
|
+
r = subprocess.run(cmd, input=text, capture_output=True, text=True, timeout=STEP_TIMEOUT, cwd=cwd)
|
|
103
105
|
except (OSError, subprocess.TimeoutExpired) as e:
|
|
104
106
|
print(f" esbuild could not be run ({e})", file=sys.stderr)
|
|
105
107
|
return None
|
|
@@ -119,7 +121,7 @@ def bundle_modules(options, bundle_script=None, root=None):
|
|
|
119
121
|
script = bundle_script or os.environ.get("BUILD_BUNDLE_SCRIPT", "scripts/bundle.mjs")
|
|
120
122
|
args = ["node", "--no-warnings", script]
|
|
121
123
|
try:
|
|
122
|
-
r = subprocess.run(args, input=json.dumps(options), capture_output=True, text=True, timeout=
|
|
124
|
+
r = subprocess.run(args, input=json.dumps(options), capture_output=True, text=True, timeout=STEP_TIMEOUT, cwd=cwd)
|
|
123
125
|
except (OSError, subprocess.TimeoutExpired) as e:
|
|
124
126
|
print(f" esbuild could not be run ({e})", file=sys.stderr)
|
|
125
127
|
return False
|
|
@@ -202,7 +204,7 @@ def minify_shader_literals(js, root=None):
|
|
|
202
204
|
capture_output=True,
|
|
203
205
|
text=True,
|
|
204
206
|
encoding="utf-8",
|
|
205
|
-
timeout=
|
|
207
|
+
timeout=STEP_TIMEOUT,
|
|
206
208
|
cwd=cwd,
|
|
207
209
|
check=True,
|
|
208
210
|
)
|