roamwright 0.4.0 → 0.20.1
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/CONTRIBUTING.md +3 -1
- package/README.md +11 -34
- package/geometry/bedding.js +141 -0
- package/geometry/builder-cells.js +42 -0
- package/geometry/builder-frame.js +47 -0
- package/geometry/builder.js +189 -177
- package/geometry/cell-mask.js +25 -0
- package/geometry/creased-sheet.js +34 -34
- package/geometry/ear.js +36 -36
- package/geometry/erosion.js +65 -42
- package/geometry/face-grid.js +65 -65
- package/geometry/foliage.js +10 -10
- package/geometry/hair-gathers.js +41 -41
- package/geometry/hair-locks.js +41 -41
- package/geometry/hair-patch.js +18 -18
- package/geometry/hair-shell.js +31 -31
- package/geometry/head-profile.js +15 -15
- package/geometry/head-shape.js +77 -77
- package/geometry/heightfield.js +27 -18
- package/geometry/index-parts.js +2 -2
- package/geometry/instance-visibility.js +12 -12
- package/geometry/instances.js +15 -15
- package/geometry/outline-grid.js +7 -7
- package/geometry/part-ranges.js +3 -3
- package/geometry/path-field.js +63 -33
- package/geometry/placement.js +52 -52
- package/geometry/point-buckets.js +50 -0
- package/geometry/primitives.js +63 -47
- package/geometry/sagging-tube.js +27 -27
- package/geometry/sampled-surface.js +109 -77
- package/geometry/scatter-grid.js +46 -6
- package/geometry/sculpt.js +93 -93
- package/geometry/shore-grid.js +77 -34
- package/geometry/strata-field.js +92 -92
- package/geometry/strata-tiles.js +91 -91
- package/geometry/stream.js +70 -48
- package/geometry/terrain-chunks.js +87 -82
- package/geometry/terrain-extension.js +6 -6
- package/index.js +5 -0
- package/math/cell-edge.js +16 -16
- package/math/cell-key.js +6 -0
- package/math/circle-clearances.js +19 -0
- package/math/cloth-textures.js +6 -6
- package/math/cloud-textures.js +20 -20
- package/math/color.js +14 -14
- package/math/curve.js +22 -22
- package/math/mountain-ranges.js +216 -165
- package/math/noise.js +101 -49
- package/math/particle-noise.js +28 -28
- package/math/periodic.js +5 -5
- package/math/random.js +24 -15
- package/math/rectangles.js +52 -0
- package/math/rock-texture.js +7 -7
- package/math/scalar.js +5 -5
- package/math/surface-textures.js +54 -54
- package/motion/arm-reach.js +24 -24
- package/motion/ballistic-arc.js +11 -0
- package/motion/biped-cycle.js +44 -0
- package/motion/biped-leg.js +37 -0
- package/motion/biped-stride.js +98 -122
- package/motion/contact-transition.js +33 -0
- package/motion/crowd-alarms.js +39 -39
- package/motion/crowd-routine.js +94 -65
- package/motion/daily-clock.js +9 -9
- package/motion/deck-surface.js +38 -0
- package/motion/ground-lookahead.js +5 -5
- package/motion/instance-sight.js +8 -8
- package/motion/player.js +36 -28
- package/motion/quadruped.js +155 -155
- package/motion/spaces.js +32 -32
- package/motion/weather.js +73 -24
- package/motion/wind.js +32 -13
- package/package.json +7 -3
- package/rendering/caster-motion.js +5 -5
- package/rendering/cell-lod.js +138 -82
- package/rendering/cloud-dome.js +28 -28
- package/rendering/cloud-field.js +2 -2
- package/rendering/compilation-schedule.js +68 -11
- package/rendering/contact-shadows.js +2 -2
- package/rendering/context.js +12 -0
- package/rendering/crowd-skinning.js +13 -13
- package/rendering/crust.js +18 -12
- package/rendering/daylight.js +3 -3
- package/rendering/detail-range.js +28 -0
- package/rendering/dispose-meshes.js +18 -0
- package/rendering/dof.js +9 -9
- package/rendering/eye-adapt.js +14 -14
- package/rendering/far-shadow.js +8 -8
- package/rendering/flocks.js +78 -78
- package/rendering/garment-material.js +17 -17
- package/rendering/glow-lines.js +13 -13
- package/rendering/hair-strands.js +20 -20
- package/rendering/height-probe.js +149 -19
- package/rendering/label-layout.js +46 -0
- package/rendering/label-range.js +38 -0
- package/rendering/light-budget.js +52 -52
- package/rendering/light-shafts.js +23 -23
- package/rendering/local-lights.js +15 -4
- package/rendering/material-lod.js +49 -49
- package/rendering/particle-emitters.js +90 -90
- package/rendering/particles.js +78 -67
- package/rendering/piece-batch.js +17 -6
- package/rendering/planar-reflection.js +38 -38
- package/rendering/post-shaders.js +17 -13
- package/rendering/post.js +71 -71
- package/rendering/rain-streaks.js +67 -0
- package/rendering/road-surface.js +11 -11
- package/rendering/sea-shaders.js +11 -11
- package/rendering/shader-warmup.js +29 -16
- package/rendering/shadow-alignment.js +4 -4
- package/rendering/shadow-depth.js +7 -7
- package/rendering/sky-occlusion.js +16 -16
- package/rendering/sky.js +16 -6
- package/rendering/stage-lights.js +6 -6
- package/rendering/static-point-shadow.js +3 -3
- package/rendering/still-casters.js +1 -1
- package/rendering/strata-material.js +10 -10
- package/rendering/stream-flow.js +10 -10
- package/rendering/taa.js +26 -26
- package/rendering/talus.js +15 -15
- package/rendering/terrain-rock.js +7 -7
- package/rendering/texture-fills.js +8 -8
- package/rendering/textures.js +28 -28
- package/rendering/wakes.js +24 -24
- package/rendering/water-material.js +36 -23
- package/rendering/world-matrices.js +38 -38
- package/runtime/diagnostic-log.js +2 -2
- package/runtime/first-use.js +33 -28
- package/runtime/frame-pacing.js +33 -0
- package/runtime/gpu-timing.js +7 -7
- package/runtime/grid-cache.js +1 -1
- package/runtime/grid-rows.js +44 -5
- package/runtime/hand-over.js +41 -23
- package/runtime/pool.js +58 -16
- package/runtime/quality-fit.js +1 -1
- package/runtime/search.js +22 -22
- package/runtime/spatial-audio.js +13 -13
- package/runtime/withdrawable-task.js +35 -0
- package/runtime/worker.js +7 -0
package/rendering/flocks.js
CHANGED
|
@@ -21,26 +21,26 @@ export const WRIST = 0.8; // and the wrists
|
|
|
21
21
|
const SPAN = 3.2; // a bird across the wings at size 1
|
|
22
22
|
|
|
23
23
|
/** A bird's geometry from its look: position, aW (0 body, 1 arm, 2 hand), and for a coloured look, color and aUnder. */
|
|
24
|
-
export function birdGeometry(
|
|
25
|
-
const
|
|
26
|
-
|
|
24
|
+
export function birdGeometry(birdStyle) {
|
|
25
|
+
const positions = [],
|
|
26
|
+
wingWeights = [],
|
|
27
27
|
K = [],
|
|
28
28
|
U = [], // the under face's colour and which way the triangle's front face looks (1 up, -1 down, 0 one colour on both faces)
|
|
29
|
-
col =
|
|
30
|
-
tri = (
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
col = birdStyle.colours,
|
|
30
|
+
tri = (firstPoint, secondPoint, thirdPoint, w = 0, part = 'body') => {
|
|
31
|
+
positions.push(...firstPoint, ...secondPoint, ...thirdPoint);
|
|
32
|
+
wingWeights.push(w, w, w);
|
|
33
33
|
if (!col) return;
|
|
34
|
-
const under =
|
|
35
|
-
up = Math.sign((
|
|
36
|
-
for (const p of [
|
|
37
|
-
const tip = part !== 'body' && part !== 'head' && Math.abs(p[0]) >
|
|
34
|
+
const under = birdStyle.under?.[part],
|
|
35
|
+
up = Math.sign((secondPoint[2] - firstPoint[2]) * (thirdPoint[0] - firstPoint[0]) - (secondPoint[0] - firstPoint[0]) * (thirdPoint[2] - firstPoint[2]));
|
|
36
|
+
for (const p of [firstPoint, secondPoint, thirdPoint]) {
|
|
37
|
+
const tip = part !== 'body' && part !== 'head' && Math.abs(p[0]) > birdStyle.tips;
|
|
38
38
|
K.push(...(tip ? col.tip : col[part]));
|
|
39
|
-
if (
|
|
39
|
+
if (birdStyle.under) U.push(...(under && !tip ? under : tip ? col.tip : col[part]), under && !tip ? up : 0);
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
// the body: rings along z [z, half width, half height, centre y], from the beak's tip to the root of the tail
|
|
43
|
-
const
|
|
43
|
+
const bodyRings = [
|
|
44
44
|
[1.08, 0, 0, 0.02],
|
|
45
45
|
[0.86, 0.06, 0.06, 0.04],
|
|
46
46
|
[0.68, 0.1, 0.1, 0.05],
|
|
@@ -51,63 +51,63 @@ export function birdGeometry(L) {
|
|
|
51
51
|
],
|
|
52
52
|
AROUND = 6,
|
|
53
53
|
at = (r, j) => {
|
|
54
|
-
const
|
|
55
|
-
return [Math.cos(
|
|
54
|
+
const angle = (j / AROUND) * TAU;
|
|
55
|
+
return [Math.cos(angle) * r[1], r[3] + Math.sin(angle) * r[2], r[0]];
|
|
56
56
|
};
|
|
57
|
-
for (let i = 0; i <
|
|
57
|
+
for (let i = 0; i < bodyRings.length - 1; i++)
|
|
58
58
|
for (let j = 0; j < AROUND; j++) {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
const ringStart = at(bodyRings[i], j),
|
|
60
|
+
ringEnd = at(bodyRings[i], j + 1),
|
|
61
|
+
nextRingStart = at(bodyRings[i + 1], j),
|
|
62
|
+
nextRingEnd = at(bodyRings[i + 1], j + 1);
|
|
63
63
|
const part = i < 2 ? 'head' : 'body';
|
|
64
|
-
tri(
|
|
65
|
-
if (i > 0) tri(
|
|
64
|
+
tri(ringStart, nextRingStart, nextRingEnd, 0, part);
|
|
65
|
+
if (i > 0) tri(ringStart, nextRingEnd, ringEnd, 0, part);
|
|
66
66
|
}
|
|
67
67
|
// the tail, a fan a little wider at its end, its middle feathers longest
|
|
68
|
-
const [back, wide] =
|
|
68
|
+
const [back, wide] = birdStyle.tail;
|
|
69
69
|
tri([-0.05, 0.02, -0.5], [0.05, 0.02, -0.5], [wide, 0.02, -back + 0.08]);
|
|
70
70
|
tri([-0.05, 0.02, -0.5], [wide, 0.02, -back + 0.08], [0, 0.02, -back]);
|
|
71
71
|
tri([-0.05, 0.02, -0.5], [0, 0.02, -back], [-wide, 0.02, -back + 0.08]);
|
|
72
72
|
for (const s of [-1, 1]) {
|
|
73
73
|
const X = (x, y, z) => [s * x, y, z];
|
|
74
74
|
for (const [rows, w] of [
|
|
75
|
-
[
|
|
76
|
-
[
|
|
75
|
+
[birdStyle.arm, 1],
|
|
76
|
+
[birdStyle.hand, 2],
|
|
77
77
|
])
|
|
78
78
|
for (let i = 0; i < rows.length - 1; i++) {
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
la = X(
|
|
82
|
-
ta = X(
|
|
83
|
-
lb = X(
|
|
84
|
-
tb = X(
|
|
79
|
+
const currentRow = rows[i],
|
|
80
|
+
nextRow = rows[i + 1],
|
|
81
|
+
la = X(currentRow[0], currentRow[1], currentRow[2]),
|
|
82
|
+
ta = X(currentRow[3], currentRow[4], currentRow[5]),
|
|
83
|
+
lb = X(nextRow[0], nextRow[1], nextRow[2]),
|
|
84
|
+
tb = X(nextRow[3], nextRow[4], nextRow[5]);
|
|
85
85
|
tri(la, ta, tb, w, w === 1 ? 'arm' : 'hand');
|
|
86
86
|
tri(la, tb, lb, w, w === 1 ? 'arm' : 'hand');
|
|
87
87
|
}
|
|
88
|
-
for (const [x, z, dx, dz] of
|
|
88
|
+
for (const [x, z, dx, dz] of birdStyle.fingers) tri(X(x - 0.07, 0.01, z + 0.05), X(x + 0.05, 0.01, z + 0.04), X(x + dx, 0, z + dz), 2, 'tip');
|
|
89
89
|
}
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (col)
|
|
94
|
-
if (U.length)
|
|
95
|
-
|
|
96
|
-
return
|
|
90
|
+
const geometry = new THREE.BufferGeometry();
|
|
91
|
+
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|
|
92
|
+
geometry.setAttribute('aW', new THREE.Float32BufferAttribute(wingWeights, 1));
|
|
93
|
+
if (col) geometry.setAttribute('color', new THREE.Float32BufferAttribute(K, 3));
|
|
94
|
+
if (U.length) geometry.setAttribute('aUnder', new THREE.Float32BufferAttribute(U, 4));
|
|
95
|
+
geometry.computeVertexNormals();
|
|
96
|
+
return geometry;
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
/** A plain bird for far or stylised flocks: a body diamond and two wings, aW marking how far out along the wing a vertex sits. */
|
|
100
100
|
export function plainBirdGeometry() {
|
|
101
|
-
const
|
|
102
|
-
const
|
|
101
|
+
const geometry = new THREE.BufferGeometry();
|
|
102
|
+
const positions = [
|
|
103
103
|
0, 0, 0.9, 0.22, 0, 0, -0.22, 0, 0, 0.22, 0, 0, 0, 0, -1.0, -0.22, 0, 0, 0.2, 0, 0.35, 1.5, 0, 0.05, 0.2, 0, -0.35, -0.2, 0, -0.35,
|
|
104
104
|
-1.5, 0, 0.05, -0.2, 0, 0.35,
|
|
105
105
|
];
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
return
|
|
106
|
+
const wingWeights = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0];
|
|
107
|
+
geometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|
|
108
|
+
geometry.setAttribute('aW', new THREE.Float32BufferAttribute(wingWeights, 1));
|
|
109
|
+
geometry.computeVertexNormals();
|
|
110
|
+
return geometry;
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
// The beat in the vertex shader: the arm about the shoulder, the hand about the wrist a little behind it, drawn in and swept back
|
|
@@ -133,9 +133,9 @@ const UNDER_HEAD = /* glsl */ ` attribute vec4 aUnder; varying vec4 vUnder;`,
|
|
|
133
133
|
|
|
134
134
|
/** A plumage's colour (hex, sRGB) lifted to the linear luminance `least` if darker, its hue kept: black feathers still shine. */
|
|
135
135
|
export function plumage(hex, least = 0.035) {
|
|
136
|
-
const
|
|
137
|
-
lum = 0.2126 *
|
|
138
|
-
return lum < least ?
|
|
136
|
+
const color = new THREE.Color(hex),
|
|
137
|
+
lum = 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
|
|
138
|
+
return lum < least ? color.multiplyScalar(least / Math.max(lum, 1e-4)) : color;
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
/**
|
|
@@ -171,19 +171,19 @@ export function createFlock({
|
|
|
171
171
|
key = look ? 'bird' : 'plain',
|
|
172
172
|
}) {
|
|
173
173
|
const bird = !!look,
|
|
174
|
-
|
|
174
|
+
geometry = bird ? birdGeometry(look) : plainBirdGeometry(),
|
|
175
175
|
flap = bird ? new THREE.InstancedBufferAttribute(new Float32Array(n * 2), 2) : null;
|
|
176
|
-
if (flap)
|
|
176
|
+
if (flap) geometry.setAttribute('aFlap', flap.setUsage(THREE.DynamicDrawUsage));
|
|
177
177
|
const coloured = bird && !!look.colours,
|
|
178
178
|
under = bird && !!look.under,
|
|
179
|
-
|
|
179
|
+
material = new THREE.MeshStandardMaterial({
|
|
180
180
|
color: coloured ? 0xffffff : bird ? plumage(color, least) : color,
|
|
181
181
|
vertexColors: coloured,
|
|
182
182
|
roughness: (bird && look.gloss) || roughness,
|
|
183
183
|
side: THREE.DoubleSide,
|
|
184
184
|
flatShading: true,
|
|
185
185
|
});
|
|
186
|
-
|
|
186
|
+
material.onBeforeCompile = sh => {
|
|
187
187
|
sh.uniforms.uTime = time;
|
|
188
188
|
if (bird) sh.uniforms.uBeat = { value: look.beat * TAU };
|
|
189
189
|
sh.vertexShader = sh.vertexShader
|
|
@@ -211,8 +211,8 @@ export function createFlock({
|
|
|
211
211
|
.replace('#include <common>', '#include <common>\nvarying vec4 vUnder;')
|
|
212
212
|
.replace('#include <color_fragment>', '#include <color_fragment>' + UNDER);
|
|
213
213
|
};
|
|
214
|
-
|
|
215
|
-
const mesh = new THREE.InstancedMesh(
|
|
214
|
+
material.customProgramCacheKey = () => 'flock:' + key + (coloured ? ':coloured' : '') + (under ? ':under' : '');
|
|
215
|
+
const mesh = new THREE.InstancedMesh(geometry, material, n);
|
|
216
216
|
mesh.frustumCulled = false;
|
|
217
217
|
const birds = [];
|
|
218
218
|
for (let i = 0; i < n; i++)
|
|
@@ -251,9 +251,9 @@ function flockFlight({ mesh, birds, flap, size, lens, bird, soar, silent, calls,
|
|
|
251
251
|
dx = p.x - at.x,
|
|
252
252
|
dy = p.y - at.y,
|
|
253
253
|
dz = p.z - at.z,
|
|
254
|
-
|
|
255
|
-
if (
|
|
256
|
-
const k = clear / Math.max(
|
|
254
|
+
distance = Math.hypot(dx, dy, dz);
|
|
255
|
+
if (distance >= clear) return;
|
|
256
|
+
const k = clear / Math.max(distance, 1e-3);
|
|
257
257
|
p.x = at.x + dx * k;
|
|
258
258
|
p.y = at.y + dy * k;
|
|
259
259
|
p.z = at.z + dz * k;
|
|
@@ -263,10 +263,10 @@ function flockFlight({ mesh, birds, flap, size, lens, bird, soar, silent, calls,
|
|
|
263
263
|
if (!calls || silent || t < nextCall) return;
|
|
264
264
|
nextCall = t + gap[0] + Math.random() * (gap[1] - gap[0]);
|
|
265
265
|
const e = mesh.instanceMatrix.array,
|
|
266
|
-
|
|
267
|
-
x = e[
|
|
268
|
-
y = e[
|
|
269
|
-
z = e[
|
|
266
|
+
matrixOffset = Math.floor(Math.random() * n) * 16,
|
|
267
|
+
x = e[matrixOffset + 12],
|
|
268
|
+
y = e[matrixOffset + 13],
|
|
269
|
+
z = e[matrixOffset + 14];
|
|
270
270
|
if (Math.hypot(x - lens.position.x, y - lens.position.y, z - lens.position.z) > heard) return;
|
|
271
271
|
calls.sound(x, y, z, loud);
|
|
272
272
|
}
|
|
@@ -281,21 +281,21 @@ function flockFlight({ mesh, birds, flap, size, lens, bird, soar, silent, calls,
|
|
|
281
281
|
// own, so that a wider circle is flown faster.
|
|
282
282
|
update(cx, cy, cz, radius, height, t, airspeed = 0) {
|
|
283
283
|
const first = last === null,
|
|
284
|
-
|
|
284
|
+
deltaSeconds = first ? 0 : Math.min(0.1, Math.max(0, t - last)),
|
|
285
285
|
bob = Math.min(BOB, BOB_SHARE * height);
|
|
286
286
|
last = t;
|
|
287
287
|
for (let i = 0; i < n; i++) {
|
|
288
|
-
const
|
|
289
|
-
r = radius *
|
|
290
|
-
dir =
|
|
291
|
-
pace = 0.8 + (Math.abs(
|
|
292
|
-
turn = airspeed > 0 ? (dir * airspeed * pace) / Math.max(r, 1) :
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
yaw = -
|
|
296
|
-
place.x = cx + Math.cos(
|
|
297
|
-
place.z = cz + Math.sin(
|
|
298
|
-
place.y = cy +
|
|
288
|
+
const flockMember = birds[i],
|
|
289
|
+
r = radius * flockMember.r,
|
|
290
|
+
dir = flockMember.sp > 0 ? 1 : -1,
|
|
291
|
+
pace = 0.8 + (Math.abs(flockMember.sp) - 0.05) * 5, // 0.8 to 1.2: some birds fly a little faster than others
|
|
292
|
+
turn = airspeed > 0 ? (dir * airspeed * pace) / Math.max(r, 1) : flockMember.sp * 6; // radians a second round the circle
|
|
293
|
+
flockMember.a = first ? flockMember.ph + t * turn : flockMember.a + turn * deltaSeconds;
|
|
294
|
+
const orbitAngle = flockMember.a,
|
|
295
|
+
yaw = -orbitAngle + (dir > 0 ? 0 : Math.PI);
|
|
296
|
+
place.x = cx + Math.cos(orbitAngle) * r;
|
|
297
|
+
place.z = cz + Math.sin(orbitAngle) * r;
|
|
298
|
+
place.y = cy + flockMember.h * height + Math.sin(t * BOB_RATE + flockMember.wob) * bob;
|
|
299
299
|
place.ry = yaw;
|
|
300
300
|
if (!bird) {
|
|
301
301
|
place.rx = 0;
|
|
@@ -304,16 +304,16 @@ function flockFlight({ mesh, birds, flap, size, lens, bird, soar, silent, calls,
|
|
|
304
304
|
continue;
|
|
305
305
|
}
|
|
306
306
|
const speed = Math.abs(turn) * r,
|
|
307
|
-
climb = bob * BOB_RATE * Math.cos(t * BOB_RATE +
|
|
307
|
+
climb = bob * BOB_RATE * Math.cos(t * BOB_RATE + flockMember.wob), // metres a second up
|
|
308
308
|
bank = Math.min(MAX_BANK, Math.atan((speed * Math.abs(turn)) / GRAVITY)) * dir,
|
|
309
309
|
pitch = Math.atan2(climb, Math.max(speed, 1));
|
|
310
|
-
|
|
310
|
+
flockMember.beat += (sstep(-0.6, 0.2, climb) * (soar ? SOAR_BEAT : 1) - flockMember.beat) * Math.min(1, deltaSeconds * BEAT_EASE);
|
|
311
311
|
keepFromLens(place);
|
|
312
312
|
place.rx = -pitch;
|
|
313
313
|
place.rz = bank;
|
|
314
314
|
placeBankedAt(mesh.instanceMatrix.array, i * 16, place);
|
|
315
|
-
flap.array[i * 2] =
|
|
316
|
-
flap.array[i * 2 + 1] =
|
|
315
|
+
flap.array[i * 2] = flockMember.ph * 3;
|
|
316
|
+
flap.array[i * 2 + 1] = flockMember.beat;
|
|
317
317
|
}
|
|
318
318
|
mesh.instanceMatrix.needsUpdate = true;
|
|
319
319
|
if (flap) flap.needsUpdate = true;
|
|
@@ -11,7 +11,7 @@ const FOLDS = {
|
|
|
11
11
|
fade: [0.008, 0.022], // the size of a pixel (metres) from which the folds fade and are gone: a fold a pixel or two wide would crawl
|
|
12
12
|
slope: FOLD_SLOPES, // the steepest slope each field's byte holds (of its height, for each tile)
|
|
13
13
|
};
|
|
14
|
-
const
|
|
14
|
+
const shaderFloat = value => value.toFixed(4);
|
|
15
15
|
// What each kind of garment is to the eye (KIND order): how much of the
|
|
16
16
|
// cloth texture's weave is smoothed away and the tone it is left at (of a plain weave's), how much of the long folds and of
|
|
17
17
|
// the crumple it takes, how rough it is (a plain weave keeps the material's own: 0) and how much a metal.
|
|
@@ -28,7 +28,7 @@ const KINDS = [
|
|
|
28
28
|
PLATE_WEAR = { face: 0.22, edge: 0.38 },
|
|
29
29
|
MAIL = { around: 120, up: 210, fade: [0.18, 0.44] }, // links to the circumference and rows per metre
|
|
30
30
|
kindOf = column =>
|
|
31
|
-
`(kind < 0.5 ? ${
|
|
31
|
+
`(kind < 0.5 ? ${shaderFloat(KINDS[0][column])} : kind < 1.5 ? ${shaderFloat(KINDS[1][column])} : kind < 2.5 ? ${shaderFloat(KINDS[2][column])} : kind < 3.5 ? ${shaderFloat(KINDS[3][column])} : kind < 4.5 ? ${shaderFloat(KINDS[4][column])} : ${shaderFloat(KINDS[5][column])})`;
|
|
32
32
|
// What the fragment shader declares: the textures; the folds' slopes across the screen (metres of height a pixel), which
|
|
33
33
|
// GARMENT_FOLDS works out and FOLD_RELIEF turns the normal by; and how worn smooth a spot of leather is, for its sheen.
|
|
34
34
|
const FOLD_PARS = `/* glsl */
|
|
@@ -44,33 +44,33 @@ float mailLink(vec2 uv, float row, float aa) {
|
|
|
44
44
|
// In the surface's colour (after vSk, the tag, and vL, the point as built, are known): the garment's own weave or smoothness,
|
|
45
45
|
// the folds' slopes, and their shade.
|
|
46
46
|
const GARMENT_FOLDS = `/* glsl */
|
|
47
|
-
{ float worn = -vSk, kind = floor(worn + 0.001), show = step(0.05, worn) * (1.0 - smoothstep(${
|
|
47
|
+
{ float worn = -vSk, kind = floor(worn + 0.001), show = step(0.05, worn) * (1.0 - smoothstep(${shaderFloat(FOLDS.fade[0])}, ${shaderFloat(FOLDS.fade[1])}, length(fwidth(vViewPosition))));
|
|
48
48
|
vec3 bx = dFdx(vL), by = dFdy(vL);
|
|
49
|
-
if (worn > 0.05) { float even = ${kindOf(0)}; diffuseColor.rgb = mix(diffuseColor.rgb, vec3(${
|
|
49
|
+
if (worn > 0.05) { float even = ${kindOf(0)}; diffuseColor.rgb = mix(diffuseColor.rgb, vec3(${shaderFloat(WEAVE_TONE)}), even) * ${kindOf(1)}; gH = mix(gH, 0.5, even); }
|
|
50
50
|
if (show > 0.0) {
|
|
51
|
-
float crease = clamp((worn - kind - ${
|
|
51
|
+
float crease = clamp((worn - kind - ${shaderFloat(PLAIN)}) / ${shaderFloat(CREASED - PLAIN)}, 0.0, 1.0), turn = atan(vL.x, vL.z) * 0.15915494;
|
|
52
52
|
// how far round the body, and up it, a pixel to the right and a pixel up are
|
|
53
53
|
vec2 round = vec2(vL.z * bx.x - vL.x * bx.z, vL.z * by.x - vL.x * by.z) / (6.2832 * max(dot(vL.xz, vL.xz), 0.0036)), up = vec2(bx.y, by.y);
|
|
54
|
-
vec2 hu = round * ${
|
|
55
|
-
vec2 hang = textureLod(uFolds, vec2(turn * ${
|
|
56
|
-
vec3 crumple = textureLod(uCrumple, vec2(turn * ${
|
|
54
|
+
vec2 hu = round * ${shaderFloat(FOLDS.hang[0])}, cu = round * ${shaderFloat(FOLDS.crumple[0])} + up * ${shaderFloat(FOLDS.lean)}, cv = up * ${shaderFloat(FOLDS.crumple[1])};
|
|
55
|
+
vec2 hang = textureLod(uFolds, vec2(turn * ${shaderFloat(FOLDS.hang[0])}, vL.y * ${shaderFloat(FOLDS.hang[1])}), 0.5 * log2(max(dot(hu, hu), dot(up, up) * ${shaderFloat(FOLDS.hang[1] ** 2)}) * 65536.0)).rg;
|
|
56
|
+
vec3 crumple = textureLod(uCrumple, vec2(turn * ${shaderFloat(FOLDS.crumple[0])} + vL.y * ${shaderFloat(FOLDS.lean)}, vL.y * ${shaderFloat(FOLDS.crumple[1])}), 0.5 * log2(max(dot(cu, cu), dot(cv, cv)) * 65536.0)).rgb;
|
|
57
57
|
// half gathered, the cloth hangs in its long folds; past that it is crumpled as well. Leather is creased a little wherever it is
|
|
58
|
-
float leather = 1.0 - step(0.5, abs(kind - 3.0)), fall = show * mix(${
|
|
58
|
+
float leather = 1.0 - step(0.5, abs(kind - 3.0)), fall = show * mix(${shaderFloat(FOLDS.smooth)}, 1.0, min(1.0, crease * 2.0)) * ${kindOf(2)};
|
|
59
59
|
float crush = max(crease * 2.0 - 1.0, 0.0); crush = show * max(crush * crush, 0.15 * leather) * ${kindOf(3)};
|
|
60
|
-
gFold = fall * ${
|
|
61
|
-
+ crush * ${
|
|
62
|
-
diffuseColor.rgb *= (1.0 - ${
|
|
60
|
+
gFold = fall * ${shaderFloat(FOLDS.deep[0] * FOLDS.slope[0])} * (hang.r * 2.0 - 1.0) * hu
|
|
61
|
+
+ crush * ${shaderFloat(FOLDS.deep[1] * FOLDS.slope[1])} * ((crumple.r * 2.0 - 1.0) * cu + (crumple.g * 2.0 - 1.0) * cv);
|
|
62
|
+
diffuseColor.rgb *= (1.0 - ${shaderFloat(FOLDS.shade[0])} * fall * (1.0 - hang.g)) * (1.0 - ${shaderFloat(FOLDS.shade[1])} * crush * (1.0 - crumple.b));
|
|
63
63
|
// Plate's tag can mark an exposed edge. The existing crease field breaks up its polish.
|
|
64
64
|
float plate = step(4.5, kind);
|
|
65
65
|
float edge = plate * smoothstep(0.65, 0.96, crease) * mix(0.6, 1.0, crumple.b);
|
|
66
66
|
gWorn = show * max(max(leather, plate) * crumple.b, edge);
|
|
67
|
-
diffuseColor.rgb *= 1.0 + show * (${
|
|
68
|
-
diffuseColor.rgb *= 1.0 + leather * show * (${
|
|
67
|
+
diffuseColor.rgb *= 1.0 + show * (${shaderFloat(PLATE_WEAR.edge)} * edge - plate * ${shaderFloat(PLATE_WEAR.face)} * (1.0 - crumple.b) * (1.0 - edge));
|
|
68
|
+
diffuseColor.rgb *= 1.0 + leather * show * (${shaderFloat(LEATHER.worn)} * crumple.b * crumple.b - ${shaderFloat(LEATHER.grain)} * (1.0 - crumple.b));
|
|
69
69
|
if (kind == 4.0) {
|
|
70
|
-
float pixel = max(length(round) * ${
|
|
71
|
-
float detail = 1.0 - smoothstep(${
|
|
70
|
+
float pixel = max(length(round) * ${shaderFloat(MAIL.around)}, length(up) * ${shaderFloat(MAIL.up)});
|
|
71
|
+
float detail = 1.0 - smoothstep(${shaderFloat(MAIL.fade[0])}, ${shaderFloat(MAIL.fade[1])}, pixel);
|
|
72
72
|
if (detail > 0.0) {
|
|
73
|
-
vec2 uv = vec2(turn * ${
|
|
73
|
+
vec2 uv = vec2(turn * ${shaderFloat(MAIL.around)}, vL.y * ${shaderFloat(MAIL.up)});
|
|
74
74
|
float row = floor(uv.y), aa = max(0.02, pixel * 0.5);
|
|
75
75
|
// Alternating rows lean and stagger so adjacent links meet on the half-row.
|
|
76
76
|
float link = max(mailLink(uv, row, aa), mailLink(uv, row + (fract(uv.y) < 0.5 ? -1.0 : 1.0), aa));
|
package/rendering/glow-lines.js
CHANGED
|
@@ -8,27 +8,27 @@ attribute vec3 to;
|
|
|
8
8
|
uniform vec2 screen;
|
|
9
9
|
uniform float width;
|
|
10
10
|
varying float across;
|
|
11
|
-
vec4 seen(vec3
|
|
12
|
-
vec4
|
|
13
|
-
float
|
|
14
|
-
|
|
15
|
-
return projectionMatrix *
|
|
11
|
+
vec4 seen(vec3 localPoint) {
|
|
12
|
+
vec4 viewPoint = modelViewMatrix * vec4(localPoint, 1.0);
|
|
13
|
+
float viewDistance = length(viewPoint.xyz);
|
|
14
|
+
viewPoint.xyz -= viewPoint.xyz / viewDistance * (${PULL[0].toFixed(3)} + ${PULL[1].toFixed(4)} * viewDistance);
|
|
15
|
+
return projectionMatrix * viewPoint;
|
|
16
16
|
}
|
|
17
17
|
void main() {
|
|
18
|
-
vec4
|
|
18
|
+
vec4 clipStart = seen(from), clipEnd = seen(to);
|
|
19
19
|
across = position.y;
|
|
20
|
-
if (
|
|
20
|
+
if (clipStart.w <= 0.0 || clipEnd.w <= 0.0) {
|
|
21
21
|
gl_Position = vec4(0.0, 0.0, 2.0, 1.0); // an end behind the viewer: the segment is not drawn
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
24
|
vec2 halfScreen = 0.5 * screen,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
along = normalize(
|
|
25
|
+
screenStart = clipStart.xy / clipStart.w * halfScreen,
|
|
26
|
+
screenEnd = clipEnd.xy / clipEnd.w * halfScreen,
|
|
27
|
+
along = normalize(screenEnd - screenStart + vec2(1e-5, 0.0)),
|
|
28
28
|
side = vec2(-along.y, along.x);
|
|
29
|
-
vec4
|
|
30
|
-
|
|
31
|
-
gl_Position =
|
|
29
|
+
vec4 clipPoint = mix(clipStart, clipEnd, position.x);
|
|
30
|
+
clipPoint.xy += (side * position.y + along * (position.x * 2.0 - 1.0)) * width / halfScreen * clipPoint.w;
|
|
31
|
+
gl_Position = clipPoint;
|
|
32
32
|
}`;
|
|
33
33
|
|
|
34
34
|
const FRAGMENT = /* glsl */ `
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HAIR_NEAR, HAIR_FAR, STRANDS } from '../geometry/hair-tags.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const shaderFloat = value => value.toFixed(4);
|
|
4
4
|
const LOOK = {
|
|
5
5
|
fade: [0.22, 0.6], // clumps to a pixel from which the strands fade, and are gone
|
|
6
6
|
stand: [0.1, 0.3], // and from which the clumps no longer stand out of the surface
|
|
@@ -18,37 +18,37 @@ const LOOK = {
|
|
|
18
18
|
const HAIR_PARS = `
|
|
19
19
|
float gHair = 0.0, gSheen = 0.0, gClump = 0.5; vec2 gAcross = vec2(0.0);
|
|
20
20
|
float strandOf(float cell, float period) { return fract(sin(mod(cell, period) * 91.7 + 3.1) * 43758.5453); }`;
|
|
21
|
-
const smoothOf = tag => `(${tag} > ${
|
|
21
|
+
const smoothOf = tag => `(${tag} > ${shaderFloat(HAIR_NEAR - 0.5)} ? ${shaderFloat(HAIR_FAR)} : ${tag})`;
|
|
22
22
|
// In the surface's colour, once the tag (vSk) and the point as built (vL) are known: the strands' tone and relief.
|
|
23
23
|
const HAIR_STRANDS = `/* glsl */
|
|
24
|
-
{ vec2 slope = vec2(dFdx(vSk), dFdy(vSk)) * ${
|
|
25
|
-
if (vSk > ${
|
|
24
|
+
{ vec2 slope = vec2(dFdx(vSk), dFdy(vSk)) * ${shaderFloat(STRANDS.clumps)};
|
|
25
|
+
if (vSk > ${shaderFloat(HAIR_NEAR - 0.5)}) {
|
|
26
26
|
float thick = length(slope);
|
|
27
27
|
gAcross = slope;
|
|
28
|
-
gSheen = 1.0 - smoothstep(${
|
|
29
|
-
gHair = 1.0 - smoothstep(${
|
|
30
|
-
diffuseColor.rgb = vec3(${
|
|
28
|
+
gSheen = 1.0 - smoothstep(${shaderFloat(LOOK.sheen[0])}, ${shaderFloat(LOOK.sheen[1])}, length(vViewPosition));
|
|
29
|
+
gHair = 1.0 - smoothstep(${shaderFloat(LOOK.fade[0])}, ${shaderFloat(LOOK.fade[1])}, thick);
|
|
30
|
+
diffuseColor.rgb = vec3(${shaderFloat(LOOK.even)});
|
|
31
31
|
gH = 0.5;
|
|
32
32
|
if (gHair > 0.0) {
|
|
33
|
-
float across = fract(vSk) * ${
|
|
34
|
-
float wander = dot(vL, vec3(${LOOK.along.map(
|
|
33
|
+
float across = fract(vSk) * ${shaderFloat(STRANDS.clumps)}, cell = floor(across), t = across - cell;
|
|
34
|
+
float wander = dot(vL, vec3(${LOOK.along.map(shaderFloat).join(', ')})), ease = t * t * (3.0 - 2.0 * t);
|
|
35
35
|
// a clump's tone, and its slow change along its length, each eased into the next clump's
|
|
36
|
-
float clump = mix(strandOf(cell, ${
|
|
37
|
-
strandOf(cell + 1.0, ${
|
|
38
|
-
float thin = across * ${
|
|
39
|
-
float fine = mix(strandOf(cell2 + 7.0, ${
|
|
40
|
-
float few = 1.0 - smoothstep(${
|
|
36
|
+
float clump = mix(strandOf(cell, ${shaderFloat(STRANDS.clumps * STRANDS.period)}) + 0.22 * sin(wander + cell * 2.4),
|
|
37
|
+
strandOf(cell + 1.0, ${shaderFloat(STRANDS.clumps * STRANDS.period)}) + 0.22 * sin(wander + cell * 2.4 + 2.4), ease);
|
|
38
|
+
float thin = across * ${shaderFloat(LOOK.fine)}, cell2 = floor(thin), t2 = thin - cell2;
|
|
39
|
+
float fine = mix(strandOf(cell2 + 7.0, ${shaderFloat(STRANDS.clumps * STRANDS.period * LOOK.fine)}), strandOf(cell2 + 8.0, ${shaderFloat(STRANDS.clumps * STRANDS.period * LOOK.fine)}), t2 * t2 * (3.0 - 2.0 * t2));
|
|
40
|
+
float few = 1.0 - smoothstep(${shaderFloat(LOOK.fade[0] / LOOK.fine)}, ${shaderFloat(LOOK.fade[1] / LOOK.fine)}, thick);
|
|
41
41
|
// the fine strands are a tone only; the clumps also stand out of the surface and shift the light, while they are
|
|
42
42
|
// wide enough on the screen for their slopes to be read from one pixel to the next
|
|
43
43
|
gClump = clamp(clump, 0.0, 1.0);
|
|
44
|
-
diffuseColor.rgb *= 1.0 + gHair * ${
|
|
45
|
-
gHair *= 1.0 - smoothstep(${
|
|
46
|
-
gH += gHair * ${
|
|
44
|
+
diffuseColor.rgb *= 1.0 + gHair * ${shaderFloat(LOOK.tone)} * (mix(gClump, 0.55 * gClump + 0.45 * fine, few) - 0.5);
|
|
45
|
+
gHair *= 1.0 - smoothstep(${shaderFloat(LOOK.stand[0])}, ${shaderFloat(LOOK.stand[1])}, thick);
|
|
46
|
+
gH += gHair * ${shaderFloat(LOOK.relief)} * (gClump - 0.5);
|
|
47
47
|
}
|
|
48
48
|
} }`;
|
|
49
49
|
// After the material's own roughness is known.
|
|
50
50
|
const HAIR_SHEEN = `/* glsl */
|
|
51
|
-
if (vSk > ${
|
|
51
|
+
if (vSk > ${shaderFloat(HAIR_NEAR - 0.5)}) roughnessFactor = mix(roughnessFactor, ${shaderFloat(LOOK.rough)}, gSheen);`;
|
|
52
52
|
// After the surface's normal is known: turned toward the normal a strand shows the eye, which is square to the strand, so that
|
|
53
53
|
// the light on a head of hair lies in a band across the strands.
|
|
54
54
|
const HAIR_LIE = `/* glsl */
|
|
@@ -57,9 +57,9 @@ const HAIR_LIE = `/* glsl */
|
|
|
57
57
|
vec3 climb = sign(dot(hgx, h1)) * (gAcross.x * h1 + gAcross.y * h2), strand = cross(normal, climb);
|
|
58
58
|
float sl = dot(strand, strand);
|
|
59
59
|
if (sl > 1e-20) {
|
|
60
|
-
strand = normalize(strand * inversesqrt(sl) + normal * (${
|
|
60
|
+
strand = normalize(strand * inversesqrt(sl) + normal * (${shaderFloat(LOOK.shift)} * gHair * (gClump - 0.5)));
|
|
61
61
|
vec3 toEye = normalize(vViewPosition), shown = toEye - strand * dot(toEye, strand);
|
|
62
|
-
vec3 lie = mix(normal, shown * inversesqrt(max(dot(shown, shown), 1e-8)), ${
|
|
62
|
+
vec3 lie = mix(normal, shown * inversesqrt(max(dot(shown, shown), 1e-8)), ${shaderFloat(LOOK.lie)} * gSheen);
|
|
63
63
|
normal = lie * inversesqrt(max(dot(lie, lie), 1e-8));
|
|
64
64
|
}
|
|
65
65
|
}`;
|