roamwright 0.2.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 +19 -21
- 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 +47 -0
- 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 +60 -0
- package/geometry/instance-visibility.js +41 -0
- package/geometry/instances.js +35 -12
- package/geometry/outline-grid.js +7 -7
- package/geometry/part-ranges.js +18 -0
- 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 +101 -92
- 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 +29 -0
- 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 +8 -4
- package/rendering/caster-motion.js +5 -5
- package/rendering/cell-lod.js +147 -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 +91 -26
- 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-budget.js +49 -0
- package/runtime/frame-pacing.js +33 -0
- package/runtime/gpu-timing.js +13 -10
- 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/sky.js
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render the sky and its depth mask from a cloud field and a cloud dome.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
import * as THREE from 'three';
|
|
2
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Combine a cloud field and dome into a sky mesh and a mask for effects passes.
|
|
10
|
+
* Both meshes share geometry. Call the returned `dispose()` when finished with the pair.
|
|
11
|
+
* @param options - Outputs from `createCloudField` and `createCloudDome`, plus an optional moon angular radius in radians.
|
|
12
|
+
*/
|
|
3
13
|
export function createSky({ field, dome, moonRadius: MOON_RADIUS = 0.0347 }) {
|
|
4
14
|
const {
|
|
5
15
|
fieldGLSL: CLOUD_FIELD_PARS,
|
|
@@ -52,16 +62,16 @@ export function createSky({ field, dome, moonRadius: MOON_RADIUS = 0.0347 }) {
|
|
|
52
62
|
const float SHEET = ${(FLARE / CLOUD_SHEET).toFixed(6)}; // the sheet's share of a unit of the layer
|
|
53
63
|
const float MANY = 0.86; // how much of the light scattered many times in a cloud comes out of it,
|
|
54
64
|
const float ONCE = 0.5; // and of the light scattered once
|
|
55
|
-
float hash12(vec2
|
|
56
|
-
float hash13(vec3
|
|
57
|
-
float vn(vec2
|
|
58
|
-
return mix(mix(hash12(
|
|
65
|
+
float hash12(vec2 samplePosition){ vec3 mixed = fract(vec3(samplePosition.xyx) * .1031); mixed += dot(mixed, mixed.yzx + 33.33); return fract((mixed.x + mixed.y) * mixed.z); }
|
|
66
|
+
float hash13(vec3 samplePosition){ samplePosition = fract(samplePosition * .1031); samplePosition += dot(samplePosition, samplePosition.zyx + 31.32); return fract((samplePosition.x + samplePosition.y) * samplePosition.z); }
|
|
67
|
+
float vn(vec2 samplePosition){ vec2 cell = floor(samplePosition), blend = fract(samplePosition); blend = blend*blend*(3.-2.*blend);
|
|
68
|
+
return mix(mix(hash12(cell), hash12(cell+vec2(1,0)), blend.x), mix(hash12(cell+vec2(0,1)), hash12(cell+vec2(1,1)), blend.x), blend.y); }
|
|
59
69
|
// where a direction meets the clouds' base, on the sheet
|
|
60
|
-
vec2 sheetAt(vec3
|
|
70
|
+
vec2 sheetAt(vec3 viewDirection){ return viewDirection.xz / (max(viewDirection.y, 0.0) + ${DIP}) * SHEET + uCloudAt; }
|
|
61
71
|
// how much of a cloud is drawn at a direction's height: none low in the sky, over the roofs and hills (cloud-field.js)
|
|
62
72
|
float aloft(float y){ return smoothstep(${LOWEST}, ${WHOLE}, y); }
|
|
63
73
|
// how much of the light a drop sends on at an angle from the way it came (c the cosine): g > 0 mostly onwards
|
|
64
|
-
float sentOn(float
|
|
74
|
+
float sentOn(float cosAngle, float anisotropy){ float phaseTerm = 1.0 + anisotropy * anisotropy - 2.0 * anisotropy * cosAngle; return (1.0 - anisotropy * anisotropy) / (phaseTerm * sqrt(phaseTerm)); }
|
|
65
75
|
// the clouds in a direction: rgb the light they send to the eye, a how much of the sky behind them they hide
|
|
66
76
|
vec4 clouds(vec3 d, vec3 behind){
|
|
67
77
|
vec4 dome = cloudDome(d);
|
|
@@ -197,13 +197,13 @@ export function createNarrowFraming({
|
|
|
197
197
|
export function cameraKeyAt(keys, t, out) {
|
|
198
198
|
let i = 0;
|
|
199
199
|
while (i < keys.length - 2 && keys[i + 1][0] <= t) i++;
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
cutNext = !!
|
|
203
|
-
let u = cutNext ? 0 : clamp((t -
|
|
200
|
+
const currentKey = keys[i],
|
|
201
|
+
nextKey = keys[i + 1],
|
|
202
|
+
cutNext = !!nextKey[7];
|
|
203
|
+
let u = cutNext ? 0 : clamp((t - currentKey[0]) / (nextKey[0] - currentKey[0]), 0, 1);
|
|
204
204
|
u = u * u * (3 - 2 * u);
|
|
205
|
-
out.src = cutNext && t >=
|
|
206
|
-
out.dst = cutNext ? out.src :
|
|
205
|
+
out.src = cutNext && t >= nextKey[0] ? nextKey : currentKey;
|
|
206
|
+
out.dst = cutNext ? out.src : nextKey;
|
|
207
207
|
out.u = u;
|
|
208
208
|
return out;
|
|
209
209
|
}
|
|
@@ -14,8 +14,8 @@ export function createStaticPointShadow(renderer) {
|
|
|
14
14
|
let previousClear;
|
|
15
15
|
|
|
16
16
|
function framebuffer(target, face) {
|
|
17
|
-
const
|
|
18
|
-
return target.isWebGLCubeRenderTarget ?
|
|
17
|
+
const framebuffer = renderer.properties.get(target).__webglFramebuffer;
|
|
18
|
+
return target.isWebGLCubeRenderTarget ? framebuffer[face] : framebuffer;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function copyFace(source, destination, face) {
|
|
@@ -56,7 +56,7 @@ export function createStaticPointShadow(renderer) {
|
|
|
56
56
|
const target = renderer.getRenderTarget(), face = renderer.getActiveCubeFace(), level = renderer.getActiveMipmapLevel();
|
|
57
57
|
try {
|
|
58
58
|
renderer.setRenderTarget(map);
|
|
59
|
-
for (let
|
|
59
|
+
for (let faceIndex = 0; faceIndex < (map.isWebGLCubeRenderTarget ? 6 : 1); faceIndex++) copyFace(map, picture, faceIndex);
|
|
60
60
|
} finally { renderer.setRenderTarget(target, face, level); }
|
|
61
61
|
origin.copy(current);
|
|
62
62
|
cachedNear = shadow.camera.near;
|
|
@@ -10,7 +10,7 @@ const still = { kept: false, sum: 0, round: 0 }; // round: which drawing of the
|
|
|
10
10
|
const markStill = object => object.layers.enable(STILL_LAYER);
|
|
11
11
|
const isStill = object => (object.layers.mask & STILL_BIT) !== 0;
|
|
12
12
|
// Where a mesh stands, how it is turned (about any axis) and its size, as one number
|
|
13
|
-
const placeOf =
|
|
13
|
+
const placeOf = elements => elements[12] * 1.37 + elements[13] * 2.11 + elements[14] * 0.59 + elements[0] * 5.3 + elements[1] * 3.3 + elements[2] * 4.1 + elements[5] * 1.9 + elements[6] * 2.7;
|
|
14
14
|
|
|
15
15
|
// Record a caster during cache generation. On subsequent draws, skip it only
|
|
16
16
|
// when its cached revision still matches the caller-supplied transform or batch revision.
|
|
@@ -59,35 +59,35 @@ const FULL_LIGHT = 'float rockShade(vec2 xz) { return 1.0; }';
|
|
|
59
59
|
|
|
60
60
|
export function createStrataMaterial({ texture, palette, snowline = 1e7, shading = FULL_LIGHT, vertex = STATIC_VERTEX, uniforms = {} }) {
|
|
61
61
|
const head = vertex + '\nvarying vec3 vWP, vWN; varying vec4 vRock; varying float vYY;';
|
|
62
|
-
const
|
|
62
|
+
const material = new MeshStandardMaterial({ vertexColors: true, roughness: 0.93 });
|
|
63
63
|
const colors = {};
|
|
64
64
|
for (const key of ['dark', 'light', 'iron', 'shale', 'dust', 'lichen', 'crust', 'snow']) {
|
|
65
65
|
const rgb = palette[key];
|
|
66
66
|
if (!rgb || rgb.length !== 3 || !rgb.every(Number.isFinite)) throw new TypeError('Expected a linear RGB triple for ' + key);
|
|
67
67
|
colors['u' + key[0].toUpperCase() + key.slice(1)] = { value: new Color(...rgb) };
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
Object.assign(
|
|
71
|
-
|
|
69
|
+
material.onBeforeCompile = shader => {
|
|
70
|
+
Object.assign(shader.uniforms, uniforms, colors, { uRockTex: { value: texture }, uSnowline: { value: snowline } });
|
|
71
|
+
shader.vertexShader = shader.vertexShader
|
|
72
72
|
.replace('#include <common>', '#include <common>\n' + head)
|
|
73
73
|
.replace('#include <beginnormal_vertex>', 'cliffMorph(); vec3 objectNormal = cN;')
|
|
74
74
|
.replace('#include <begin_vertex>', 'vec3 transformed = cP; vWP = cP; vWN = cN; vRock = aRock; vYY = aYY;')
|
|
75
75
|
.replace('#include <project_vertex>', '#include <project_vertex>\nif (cHide > 0.5) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);');
|
|
76
|
-
|
|
76
|
+
shader.fragmentShader = shader.fragmentShader
|
|
77
77
|
.replace('#include <common>', '#include <common>\n' + shading + '\n' + CLIFF_FRAG_HEAD + '\n' + terrainReliefGLSL)
|
|
78
78
|
.replace('#include <color_fragment>', CLIFF_FRAG)
|
|
79
79
|
.replace('#include <roughnessmap_fragment>', '#include <roughnessmap_fragment>\nroughnessFactor = mix(roughnessFactor, 0.62, gSnow);')
|
|
80
80
|
.replace('#include <normal_fragment_maps>', CLIFF_BUMP);
|
|
81
81
|
};
|
|
82
|
-
|
|
82
|
+
material.customProgramCacheKey = () => 'strata:' + vertex + ':' + shading;
|
|
83
83
|
const depth = new MeshDepthMaterial({ depthPacking: RGBADepthPacking });
|
|
84
|
-
depth.onBeforeCompile =
|
|
85
|
-
Object.assign(
|
|
86
|
-
|
|
84
|
+
depth.onBeforeCompile = shader => {
|
|
85
|
+
Object.assign(shader.uniforms, uniforms);
|
|
86
|
+
shader.vertexShader = shader.vertexShader
|
|
87
87
|
.replace('#include <common>', '#include <common>\n' + vertex)
|
|
88
88
|
.replace('#include <begin_vertex>', 'cliffMorph(); vec3 transformed = cP;')
|
|
89
89
|
.replace('#include <project_vertex>', '#include <project_vertex>\nif (cHide > 0.5) gl_Position = vec4(2.0, 2.0, 2.0, 1.0);');
|
|
90
90
|
};
|
|
91
91
|
depth.customProgramCacheKey = () => 'strata-depth:' + vertex;
|
|
92
|
-
return { material:
|
|
92
|
+
return { material: material, depth };
|
|
93
93
|
}
|
package/rendering/stream-flow.js
CHANGED
|
@@ -6,21 +6,21 @@ export const STREAM_FLOW_GLSL = /* glsl */ `
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
vec4 streamFlow(vec3 flow, float acrossMetres, float depth, float travel, float distanceToEye, float footprint) {
|
|
9
|
-
vec2
|
|
10
|
-
footprint = max(footprint, max(length(dFdx(
|
|
9
|
+
vec2 flowPosition = vec2(acrossMetres, flow.y - travel);
|
|
10
|
+
footprint = max(footprint, max(length(dFdx(flowPosition)), length(dFdy(flowPosition))));
|
|
11
11
|
vec2 broad = vec2(0.78, 0.24), middle = vec2(-1.35, 0.43), fine = vec2(2.4, 1.22);
|
|
12
12
|
vec2 broadWarp = vec2(0.33, -0.22), middleWarp = vec2(0.38, 0.28), fineWarp = vec2(-0.58, 0.63);
|
|
13
|
-
float
|
|
14
|
-
float broadPhase = dot(
|
|
15
|
-
float middlePhase = dot(
|
|
16
|
-
float finePhase = dot(
|
|
17
|
-
vec2 broadRate = broad + 1.55 * cos(
|
|
18
|
-
vec2 middleRate = middle - 1.35 * sin(
|
|
19
|
-
vec2 fineRate = fine + 0.9 * cos(
|
|
13
|
+
float broadWarpPhase = dot(flowPosition, broadWarp), middleWarpPhase = dot(flowPosition, middleWarp), fineWarpPhase = dot(flowPosition, fineWarp);
|
|
14
|
+
float broadPhase = dot(flowPosition, broad) + 1.55 * sin(broadWarpPhase);
|
|
15
|
+
float middlePhase = dot(flowPosition, middle) + 1.35 * cos(middleWarpPhase);
|
|
16
|
+
float finePhase = dot(flowPosition, fine) + 0.9 * sin(fineWarpPhase);
|
|
17
|
+
vec2 broadRate = broad + 1.55 * cos(broadWarpPhase) * broadWarp;
|
|
18
|
+
vec2 middleRate = middle - 1.35 * sin(middleWarpPhase) * middleWarp;
|
|
19
|
+
vec2 fineRate = fine + 0.9 * cos(fineWarpPhase) * fineWarp;
|
|
20
20
|
float broadDetail = streamWaveDetail(footprint, length(broadRate));
|
|
21
21
|
float middleDetail = streamWaveDetail(footprint, length(middleRate));
|
|
22
22
|
float fineDetail = streamWaveDetail(footprint, length(fineRate));
|
|
23
|
-
float packet = 0.5 + 0.5 * sin(dot(
|
|
23
|
+
float packet = 0.5 + 0.5 * sin(dot(flowPosition, vec2(0.23, -0.19)) + 0.9 * sin(middleWarpPhase));
|
|
24
24
|
vec2 slope = 0.085 * broadRate * cos(broadPhase) * broadDetail * (0.38 + 0.62 * packet)
|
|
25
25
|
+ 0.048 * middleRate * cos(middlePhase) * middleDetail * (1.0 - 0.55 * packet)
|
|
26
26
|
+ 0.016 * fineRate * cos(finePhase) * fineDetail;
|
package/rendering/taa.js
CHANGED
|
@@ -24,13 +24,13 @@ const JITTER_POINTS = 8, // the Halton points the lens steps through, then again
|
|
|
24
24
|
STALE = 1000; // milliseconds between two frames that start it afresh (a page that was hidden, a long pause)
|
|
25
25
|
|
|
26
26
|
const halton = (i, base) => {
|
|
27
|
-
let
|
|
28
|
-
|
|
27
|
+
let digitWeight = 1,
|
|
28
|
+
sequenceValue = 0;
|
|
29
29
|
for (; i > 0; i = Math.floor(i / base)) {
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
digitWeight /= base;
|
|
31
|
+
sequenceValue += digitWeight * (i % base);
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return sequenceValue;
|
|
34
34
|
};
|
|
35
35
|
// The lens's offsets, in pixels from the pixel's centre.
|
|
36
36
|
const JITTER = Array.from({ length: JITTER_POINTS }, (_, i) => [halton(i + 1, 2) - 0.5, halton(i + 1, 3) - 0.5]);
|
|
@@ -64,8 +64,8 @@ export function createTemporalAA(camera) {
|
|
|
64
64
|
for (const t of taa.history) t.dispose();
|
|
65
65
|
taa.history = [];
|
|
66
66
|
}
|
|
67
|
-
function sizeHistory(
|
|
68
|
-
for (const t of taa.history) t.setSize(
|
|
67
|
+
function sizeHistory(width, height) {
|
|
68
|
+
for (const t of taa.history) t.setSize(width, height);
|
|
69
69
|
taa.fresh = true;
|
|
70
70
|
}
|
|
71
71
|
// The running picture starts afresh on the next frame: a cut, a crossing, a new size.
|
|
@@ -80,34 +80,34 @@ export function createTemporalAA(camera) {
|
|
|
80
80
|
}
|
|
81
81
|
const historyNow = () => taa.history[taa.flip];
|
|
82
82
|
|
|
83
|
-
// Moves the lens by this frame's offset for a
|
|
84
|
-
function jitterLens(
|
|
83
|
+
// Moves the lens by this frame's offset for a viewport of the given width and height in pixels, after noting how the lens moved since the last frame.
|
|
84
|
+
function jitterLens(width, height) {
|
|
85
85
|
const now = performance.now(),
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
projectionMatrix = camera.projectionMatrix,
|
|
87
|
+
elements = projectionMatrix.elements;
|
|
88
88
|
if (now - taa.last > STALE || camera.position.distanceToSquared(lastLens) > JUMP * JUMP) taa.fresh = true;
|
|
89
89
|
taa.last = now;
|
|
90
90
|
lastLens.copy(camera.position);
|
|
91
|
-
viewProj.multiplyMatrices(
|
|
91
|
+
viewProj.multiplyMatrices(projectionMatrix, camera.matrixWorldInverse);
|
|
92
92
|
taaUniforms.uReproj.value.copy(viewProj).invert().premultiply(lastViewProj);
|
|
93
93
|
lastViewProj.copy(viewProj);
|
|
94
94
|
taaUniforms.uFresh.value = taa.fresh ? 1 : 0;
|
|
95
95
|
taa.fresh = false;
|
|
96
96
|
const point = JITTER[taa.index++ % JITTER_POINTS], // read by index: no iterator made in a frame
|
|
97
|
-
dx = (2 * point[0]) /
|
|
98
|
-
dy = (2 * point[1]) /
|
|
97
|
+
dx = (2 * point[0]) / width,
|
|
98
|
+
dy = (2 * point[1]) / height;
|
|
99
99
|
taaUniforms.uJit.value.set(dx, dy);
|
|
100
|
-
taa.saved[0] =
|
|
101
|
-
taa.saved[1] =
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
camera.projectionMatrixInverse.copy(
|
|
100
|
+
taa.saved[0] = elements[8];
|
|
101
|
+
taa.saved[1] = elements[9];
|
|
102
|
+
elements[8] -= dx; // a point's clip x gains -dx times its view depth, which is dx once divided by w = -depth
|
|
103
|
+
elements[9] -= dy;
|
|
104
|
+
camera.projectionMatrixInverse.copy(projectionMatrix).invert();
|
|
105
105
|
}
|
|
106
106
|
// Puts the lens back where it stands, for everything drawn after the scene.
|
|
107
107
|
function steadyLens() {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
const elements = camera.projectionMatrix.elements;
|
|
109
|
+
elements[8] = taa.saved[0];
|
|
110
|
+
elements[9] = taa.saved[1];
|
|
111
111
|
camera.projectionMatrixInverse.copy(camera.projectionMatrix).invert();
|
|
112
112
|
}
|
|
113
113
|
// The running pictures while they exist, for the reckoning of memory.
|
|
@@ -128,14 +128,14 @@ export function createTemporalAA(camera) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// Exposed light squashed into 0 to 1 and back: the running picture's form.
|
|
131
|
-
const SQUASH = `/* glsl */ vec3 squash(vec3
|
|
132
|
-
vec3 unsquash(vec3
|
|
131
|
+
const SQUASH = `/* glsl */ vec3 squash(vec3 hdrColor){ return hdrColor / (1.0 + max(hdrColor.r, max(hdrColor.g, hdrColor.b))); }
|
|
132
|
+
vec3 unsquash(vec3 compressedColor){ return compressedColor / max(1.0 - max(compressedColor.r, max(compressedColor.g, compressedColor.b)), 1e-3); }`;
|
|
133
133
|
// The final pass's part (post-shaders.js, under TAA): steady(cur, mean, spread) returns the running picture at this pixel (squashed)
|
|
134
134
|
// from this frame's exposed light cur and its neighbourhood's mean and spread (standard deviation) in YCoCg. It needs the final
|
|
135
135
|
// pass's tDepth and uPx.
|
|
136
136
|
const TAA_FS = `/* glsl */ uniform sampler2D tHistory; uniform mat4 uReproj; uniform vec2 uJit; uniform float uFresh; ${SQUASH}
|
|
137
|
-
vec3 toYCoCg(vec3
|
|
138
|
-
vec3 fromYCoCg(vec3
|
|
137
|
+
vec3 toYCoCg(vec3 rgbColor){ return vec3(0.25 * rgbColor.r + 0.5 * rgbColor.g + 0.25 * rgbColor.b, 0.5 * rgbColor.r - 0.5 * rgbColor.b, -0.25 * rgbColor.r + 0.5 * rgbColor.g - 0.25 * rgbColor.b); }
|
|
138
|
+
vec3 fromYCoCg(vec3 lumaChroma){ return vec3(lumaChroma.x + lumaChroma.y - lumaChroma.z, lumaChroma.x + lumaChroma.z, lumaChroma.x - lumaChroma.y - lumaChroma.z); }
|
|
139
139
|
// where this pixel's point stood in the last frame's picture: carried by the nearest of five depths round it, so an edge moves
|
|
140
140
|
// with what stands in front of it
|
|
141
141
|
vec2 lastUv(vec2 uv){
|
package/rendering/talus.js
CHANGED
|
@@ -3,24 +3,24 @@
|
|
|
3
3
|
export const talusGLSL = /* glsl */ `
|
|
4
4
|
vec2 talusFragment(vec2 metres, vec2 dx, vec2 dy, float spacing, float seed) {
|
|
5
5
|
mat2 basis = mat2(0.868, -0.497, 0.497, 0.868) / spacing;
|
|
6
|
-
vec2
|
|
6
|
+
vec2 gridPosition = basis * metres;
|
|
7
7
|
vec2 footprint = abs(basis * dx) + abs(basis * dy);
|
|
8
8
|
float resolved = 1.0 - smoothstep(0.12, 0.45, max(footprint.x, footprint.y));
|
|
9
|
-
|
|
10
|
-
vec2 cell = floor(
|
|
11
|
-
vec3
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
float angle =
|
|
16
|
-
|
|
17
|
-
float halfWidth = mix(0.13, 0.32,
|
|
18
|
-
vec2 shape =
|
|
9
|
+
gridPosition.x += 0.5 * mod(floor(gridPosition.y), 2.0);
|
|
10
|
+
vec2 cell = floor(gridPosition), cellPosition = fract(gridPosition) - 0.5;
|
|
11
|
+
vec3 cellHash = fract(vec3(cell.xyx) * vec3(0.1031, 0.11369, 0.13787) + seed);
|
|
12
|
+
cellHash += dot(cellHash, cellHash.yzx + 19.19);
|
|
13
|
+
cellHash = fract((cellHash.xxy + cellHash.yzz) * cellHash.zyx);
|
|
14
|
+
cellPosition -= (cellHash.xy - 0.5) * 0.14;
|
|
15
|
+
float angle = cellHash.z * 6.28318;
|
|
16
|
+
cellPosition = mat2(cos(angle), -sin(angle), sin(angle), cos(angle)) * cellPosition;
|
|
17
|
+
float halfWidth = mix(0.13, 0.32, cellHash.y);
|
|
18
|
+
vec2 shape = cellPosition / vec2(halfWidth, halfWidth * mix(0.5, 0.9, cellHash.x));
|
|
19
19
|
// Two chipped corners and a slanted top distinguish a fragment from a round pebble.
|
|
20
20
|
float edge = max(max(abs(shape.x), abs(shape.y)), max(dot(shape, vec2(0.77, 0.88)), dot(shape, vec2(-0.74, -0.80))));
|
|
21
|
-
float
|
|
22
|
-
float inside = (1.0 - smoothstep(1.0 -
|
|
21
|
+
float filterWidth = min(0.8, max(0.025, max(footprint.x, footprint.y) / halfWidth));
|
|
22
|
+
float inside = (1.0 - smoothstep(1.0 - filterWidth, 1.0 + filterWidth, edge)) * resolved;
|
|
23
23
|
float crest = max(0.0, 1.0 - edge);
|
|
24
|
-
float facet = mix(-0.32, 0.36, smoothstep(-
|
|
25
|
-
return inside * vec2(facet + (
|
|
24
|
+
float facet = mix(-0.32, 0.36, smoothstep(-filterWidth, filterWidth, shape.x * 0.8 + shape.y * 0.2 + cellHash.z - 0.5));
|
|
25
|
+
return inside * vec2(facet + (cellHash.x - 0.5) * 0.34, 0.28 + 0.72 * crest);
|
|
26
26
|
}`;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
// World-space rock for a heightfield. The horizontal components of the surface normal
|
|
2
2
|
// weight fixed vertical projections; changing the normal never changes the coordinates.
|
|
3
3
|
export const terrainRockGLSL = /* glsl */ `
|
|
4
|
-
vec3 rockFaceSample(sampler2D grain, vec3
|
|
5
|
-
return mix(texture2D(grain,
|
|
4
|
+
vec3 rockFaceSample(sampler2D grain, vec3 texturePosition, float xWeight) {
|
|
5
|
+
return mix(texture2D(grain, texturePosition.xy).rgb, texture2D(grain, texturePosition.zy + vec2(0.37, 0.19)).rgb, xWeight);
|
|
6
6
|
}
|
|
7
7
|
float rockBed(float height, float frequency, float phase, float footprint) {
|
|
8
8
|
return 0.5 + 0.5 * sin(height * frequency + phase) *
|
|
9
9
|
(1.0 - smoothstep(0.2, 0.5, footprint * frequency));
|
|
10
10
|
}
|
|
11
|
-
vec4 terrainRock(sampler2D grain, vec3
|
|
11
|
+
vec4 terrainRock(sampler2D grain, vec3 worldPosition, vec3 normal, vec3 darkBed, vec3 lightBed, vec3 iron, vec3 lime) {
|
|
12
12
|
vec2 weights = normal.xz * normal.xz;
|
|
13
13
|
weights *= weights;
|
|
14
14
|
float across = weights.x / max(weights.x + weights.y, 0.00001);
|
|
15
|
-
vec3 broad = rockFaceSample(grain,
|
|
16
|
-
vec3 broken = rockFaceSample(grain,
|
|
17
|
-
vec3 fine = rockFaceSample(grain,
|
|
15
|
+
vec3 broad = rockFaceSample(grain, worldPosition * 0.021, across);
|
|
16
|
+
vec3 broken = rockFaceSample(grain, worldPosition * 0.13, across);
|
|
17
|
+
vec3 fine = rockFaceSample(grain, worldPosition * 0.68, across);
|
|
18
18
|
// Warped beds follow the height through corners. Individual grains keep roughly the same size in both axes.
|
|
19
|
-
float height =
|
|
19
|
+
float height = worldPosition.y + (texture2D(grain, worldPosition.xz * 0.0031).r - 0.5) * 22.0
|
|
20
20
|
+ (broad.g - 0.5) * 3.5 + (broken.b - 0.5) * 1.5;
|
|
21
21
|
float footprint = fwidth(height) * 0.15915;
|
|
22
22
|
float major = rockBed(height, 0.83, 0.0, footprint), minor = rockBed(height, 2.57, 1.3, footprint);
|
|
@@ -12,12 +12,12 @@ export function createTextureFills({ definitions, fillPixels, request, available
|
|
|
12
12
|
const fillCost = name => definitions[name].cost ?? 1;
|
|
13
13
|
// An empty texture of a fill by name, repeating unless clamped, in sRGB unless it holds data, as `pixelTexture` makes one, and what
|
|
14
14
|
// puts pixels in it. A fill with a `depth` is a block: a texture in three dimensions.
|
|
15
|
-
function emptyTexture(name,
|
|
15
|
+
function emptyTexture(name, options) {
|
|
16
16
|
const { size, depth } = definitions[name],
|
|
17
17
|
texture = depth ? new THREE.Data3DTexture(null, size, size, depth) : new THREE.DataTexture(null, size, size);
|
|
18
|
-
texture.wrapS = texture.wrapT = texture.wrapR =
|
|
19
|
-
texture.colorSpace =
|
|
20
|
-
texture.anisotropy =
|
|
18
|
+
texture.wrapS = texture.wrapT = texture.wrapR = options.clamp ? THREE.ClampToEdgeWrapping : THREE.RepeatWrapping;
|
|
19
|
+
texture.colorSpace = options.data ? THREE.NoColorSpace : THREE.SRGBColorSpace;
|
|
20
|
+
texture.anisotropy = options.aniso || 4;
|
|
21
21
|
texture.magFilter = THREE.LinearFilter;
|
|
22
22
|
texture.minFilter = THREE.LinearMipmapLinearFilter;
|
|
23
23
|
texture.generateMipmaps = true;
|
|
@@ -29,8 +29,8 @@ export function createTextureFills({ definitions, fillPixels, request, available
|
|
|
29
29
|
return { texture, fill };
|
|
30
30
|
}
|
|
31
31
|
// The texture of a fill by name.
|
|
32
|
-
function filledTexture(name,
|
|
33
|
-
const { texture, fill } = emptyTexture(name,
|
|
32
|
+
function filledTexture(name, options = {}) {
|
|
33
|
+
const { texture, fill } = emptyTexture(name, options),
|
|
34
34
|
ask = () => pending.push(request(name, fillCost(name)).then(fill, () => fill(fillPixels(name))));
|
|
35
35
|
if (!available() || started) fill(fillPixels(name));
|
|
36
36
|
else if (asking) ask();
|
|
@@ -51,8 +51,8 @@ export function createTextureFills({ definitions, fillPixels, request, available
|
|
|
51
51
|
|
|
52
52
|
// A texture asked for in the world, by something built ahead of need, that is not drawn before `filled()`: filled on the pool's
|
|
53
53
|
// workers, or here by `fillNow()` if it is wanted before they answer.
|
|
54
|
-
function filledLater(name,
|
|
55
|
-
const { texture, fill } = emptyTexture(name,
|
|
54
|
+
function filledLater(name, options = {}) {
|
|
55
|
+
const { texture, fill } = emptyTexture(name, options);
|
|
56
56
|
let done = false;
|
|
57
57
|
const fillOnce = pixels => {
|
|
58
58
|
if (done) return;
|
package/rendering/textures.js
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import * as THREE from 'three';
|
|
2
2
|
|
|
3
|
-
//
|
|
3
|
+
// Create a canvas of the requested width and height. samplePixel(u, v, out) writes RGBA bytes at each pixel centre. A light's texture is
|
|
4
4
|
// made this way, never by a canvas's own gradient: WebKit (an iPhone's engine) dithers a gradient a little in each channel
|
|
5
5
|
// apart, which a night's exposure turns into red and green specks over a lantern's pool or a window's patch of light.
|
|
6
|
-
function pixelCanvas(
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
function pixelCanvas(width, height, samplePixel) {
|
|
7
|
+
const canvas = document.createElement('canvas');
|
|
8
|
+
canvas.width = width;
|
|
9
|
+
canvas.height = height;
|
|
10
|
+
const context = canvas.getContext('2d'),
|
|
11
|
+
imageData = context.createImageData(width, height),
|
|
12
|
+
pixels = imageData.data,
|
|
13
13
|
out = [0, 0, 0, 255];
|
|
14
|
-
for (let y = 0,
|
|
15
|
-
for (let x = 0; x <
|
|
14
|
+
for (let y = 0, pixelOffset = 0; y < height; y++)
|
|
15
|
+
for (let x = 0; x < width; x++, pixelOffset += 4) {
|
|
16
16
|
out[3] = 255;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
samplePixel((x + 0.5) / width, (y + 0.5) / height, out);
|
|
18
|
+
pixels[pixelOffset] = out[0];
|
|
19
|
+
pixels[pixelOffset + 1] = out[1];
|
|
20
|
+
pixels[pixelOffset + 2] = out[2];
|
|
21
|
+
pixels[pixelOffset + 3] = out[3];
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
return
|
|
23
|
+
context.putImageData(imageData, 0, 0);
|
|
24
|
+
return canvas;
|
|
25
25
|
}
|
|
26
|
-
// A square texture built by pixelCanvas, with
|
|
27
|
-
function pixelTexture(size,
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
30
|
-
return canvasTexture(
|
|
26
|
+
// A square texture built by pixelCanvas, with options.draw(context, size) drawing over it.
|
|
27
|
+
function pixelTexture(size, samplePixel, options = {}) {
|
|
28
|
+
const canvas = pixelCanvas(size, size, samplePixel);
|
|
29
|
+
if (options.draw) options.draw(canvas.getContext('2d'), size);
|
|
30
|
+
return canvasTexture(canvas, options);
|
|
31
31
|
}
|
|
32
32
|
// The value at t of a falloff given by stops [[t, value], ...] in rising t, straight between them and held beyond the ends, as
|
|
33
33
|
// a canvas gradient's stops are.
|
|
@@ -43,12 +43,12 @@ function falloffAt(stops, t) {
|
|
|
43
43
|
return stops[stops.length - 1][1];
|
|
44
44
|
}
|
|
45
45
|
// A texture from a canvas: repeating unless clamped, in sRGB unless it holds data.
|
|
46
|
-
function canvasTexture(
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return
|
|
46
|
+
function canvasTexture(canvas, options = {}) {
|
|
47
|
+
const texture = new THREE.CanvasTexture(canvas);
|
|
48
|
+
texture.wrapS = texture.wrapT = options.clamp ? THREE.ClampToEdgeWrapping : THREE.RepeatWrapping;
|
|
49
|
+
texture.colorSpace = options.data ? THREE.NoColorSpace : THREE.SRGBColorSpace;
|
|
50
|
+
texture.anisotropy = options.aniso || 4;
|
|
51
|
+
return texture;
|
|
52
52
|
}
|
|
53
53
|
// A map of numbers that is written once need not stay in memory once it is on the graphics card: its array is let go there.
|
|
54
54
|
// Regenerate the texture after a graphics context loss when using this option.
|
package/rendering/wakes.js
CHANGED
|
@@ -8,41 +8,41 @@ export function createWakes({ slots = 6, minSpeed = 0.25, reach = 450, ease = 4
|
|
|
8
8
|
};
|
|
9
9
|
const hulls = []; // { obj, length, beam, x, z, vx, vz, known, d2 }
|
|
10
10
|
|
|
11
|
-
// Follows the hull carried by
|
|
12
|
-
function followWake(
|
|
13
|
-
const hull = { obj, length, beam, x: 0, z: 0, vx: 0, vz: 0, known: false, d2: Infinity };
|
|
11
|
+
// Follows the hull carried by the object (her middle at its origin), `length` and `beam` metres, for as long as the page lives.
|
|
12
|
+
function followWake(object, length, beam = length * 0.3) {
|
|
13
|
+
const hull = { obj: object, length, beam, x: 0, z: 0, vx: 0, vz: 0, known: false, d2: Infinity };
|
|
14
14
|
hulls.push(hull);
|
|
15
15
|
return () => {
|
|
16
16
|
const i = hulls.indexOf(hull);
|
|
17
17
|
if (i >= 0) hulls.splice(i, 1);
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
|
-
// Whether
|
|
21
|
-
function shown(
|
|
22
|
-
let
|
|
23
|
-
for (;
|
|
24
|
-
return
|
|
20
|
+
// Whether the object is in the scene and nothing holding it is hidden.
|
|
21
|
+
function shown(object) {
|
|
22
|
+
let ancestor = object;
|
|
23
|
+
for (; ancestor.parent; ancestor = ancestor.parent) if (!ancestor.visible) return false;
|
|
24
|
+
return ancestor.isScene === true;
|
|
25
25
|
}
|
|
26
26
|
// Each frame: how fast each hull is moving, measured from where her frame was last drawn; the nearest under way fill the slots.
|
|
27
|
-
function updateWakes(
|
|
27
|
+
function updateWakes(deltaSeconds, eye) {
|
|
28
28
|
for (let i = 0; i < hulls.length; i++) {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (!shown(
|
|
33
|
-
|
|
29
|
+
const hull = hulls[i],
|
|
30
|
+
worldElements = hull.obj.matrixWorld.elements;
|
|
31
|
+
hull.d2 = Infinity;
|
|
32
|
+
if (!shown(hull.obj)) {
|
|
33
|
+
hull.known = false;
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
|
-
if (
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
} else
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const d2 = (
|
|
45
|
-
if (d2 < reach * reach &&
|
|
36
|
+
if (hull.known && deltaSeconds > 0) {
|
|
37
|
+
const speedBlend = Math.min(1, deltaSeconds * ease);
|
|
38
|
+
hull.vx += ((worldElements[12] - hull.x) / deltaSeconds - hull.vx) * speedBlend;
|
|
39
|
+
hull.vz += ((worldElements[14] - hull.z) / deltaSeconds - hull.vz) * speedBlend;
|
|
40
|
+
} else hull.vx = hull.vz = 0;
|
|
41
|
+
hull.x = worldElements[12];
|
|
42
|
+
hull.z = worldElements[14];
|
|
43
|
+
hull.known = true;
|
|
44
|
+
const d2 = (hull.x - eye.x) ** 2 + (hull.z - eye.z) ** 2;
|
|
45
|
+
if (d2 < reach * reach && hull.vx * hull.vx + hull.vz * hull.vz > minSpeed * minSpeed) hull.d2 = d2;
|
|
46
46
|
}
|
|
47
47
|
const at = wakeUniforms.uWake.value,
|
|
48
48
|
size = wakeUniforms.uWakeS.value;
|