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.
Files changed (139) hide show
  1. package/CONTRIBUTING.md +3 -1
  2. package/README.md +11 -34
  3. package/geometry/bedding.js +141 -0
  4. package/geometry/builder-cells.js +42 -0
  5. package/geometry/builder-frame.js +47 -0
  6. package/geometry/builder.js +189 -177
  7. package/geometry/cell-mask.js +25 -0
  8. package/geometry/creased-sheet.js +34 -34
  9. package/geometry/ear.js +36 -36
  10. package/geometry/erosion.js +65 -42
  11. package/geometry/face-grid.js +65 -65
  12. package/geometry/foliage.js +10 -10
  13. package/geometry/hair-gathers.js +41 -41
  14. package/geometry/hair-locks.js +41 -41
  15. package/geometry/hair-patch.js +18 -18
  16. package/geometry/hair-shell.js +31 -31
  17. package/geometry/head-profile.js +15 -15
  18. package/geometry/head-shape.js +77 -77
  19. package/geometry/heightfield.js +27 -18
  20. package/geometry/index-parts.js +2 -2
  21. package/geometry/instance-visibility.js +12 -12
  22. package/geometry/instances.js +15 -15
  23. package/geometry/outline-grid.js +7 -7
  24. package/geometry/part-ranges.js +3 -3
  25. package/geometry/path-field.js +63 -33
  26. package/geometry/placement.js +52 -52
  27. package/geometry/point-buckets.js +50 -0
  28. package/geometry/primitives.js +63 -47
  29. package/geometry/sagging-tube.js +27 -27
  30. package/geometry/sampled-surface.js +109 -77
  31. package/geometry/scatter-grid.js +46 -6
  32. package/geometry/sculpt.js +93 -93
  33. package/geometry/shore-grid.js +77 -34
  34. package/geometry/strata-field.js +92 -92
  35. package/geometry/strata-tiles.js +91 -91
  36. package/geometry/stream.js +70 -48
  37. package/geometry/terrain-chunks.js +87 -82
  38. package/geometry/terrain-extension.js +6 -6
  39. package/index.js +5 -0
  40. package/math/cell-edge.js +16 -16
  41. package/math/cell-key.js +6 -0
  42. package/math/circle-clearances.js +19 -0
  43. package/math/cloth-textures.js +6 -6
  44. package/math/cloud-textures.js +20 -20
  45. package/math/color.js +14 -14
  46. package/math/curve.js +22 -22
  47. package/math/mountain-ranges.js +216 -165
  48. package/math/noise.js +101 -49
  49. package/math/particle-noise.js +28 -28
  50. package/math/periodic.js +5 -5
  51. package/math/random.js +24 -15
  52. package/math/rectangles.js +52 -0
  53. package/math/rock-texture.js +7 -7
  54. package/math/scalar.js +5 -5
  55. package/math/surface-textures.js +54 -54
  56. package/motion/arm-reach.js +24 -24
  57. package/motion/ballistic-arc.js +11 -0
  58. package/motion/biped-cycle.js +44 -0
  59. package/motion/biped-leg.js +37 -0
  60. package/motion/biped-stride.js +98 -122
  61. package/motion/contact-transition.js +33 -0
  62. package/motion/crowd-alarms.js +39 -39
  63. package/motion/crowd-routine.js +94 -65
  64. package/motion/daily-clock.js +9 -9
  65. package/motion/deck-surface.js +38 -0
  66. package/motion/ground-lookahead.js +5 -5
  67. package/motion/instance-sight.js +8 -8
  68. package/motion/player.js +36 -28
  69. package/motion/quadruped.js +155 -155
  70. package/motion/spaces.js +32 -32
  71. package/motion/weather.js +73 -24
  72. package/motion/wind.js +32 -13
  73. package/package.json +7 -3
  74. package/rendering/caster-motion.js +5 -5
  75. package/rendering/cell-lod.js +138 -82
  76. package/rendering/cloud-dome.js +28 -28
  77. package/rendering/cloud-field.js +2 -2
  78. package/rendering/compilation-schedule.js +68 -11
  79. package/rendering/contact-shadows.js +2 -2
  80. package/rendering/context.js +12 -0
  81. package/rendering/crowd-skinning.js +13 -13
  82. package/rendering/crust.js +18 -12
  83. package/rendering/daylight.js +3 -3
  84. package/rendering/detail-range.js +28 -0
  85. package/rendering/dispose-meshes.js +18 -0
  86. package/rendering/dof.js +9 -9
  87. package/rendering/eye-adapt.js +14 -14
  88. package/rendering/far-shadow.js +8 -8
  89. package/rendering/flocks.js +78 -78
  90. package/rendering/garment-material.js +17 -17
  91. package/rendering/glow-lines.js +13 -13
  92. package/rendering/hair-strands.js +20 -20
  93. package/rendering/height-probe.js +149 -19
  94. package/rendering/label-layout.js +46 -0
  95. package/rendering/label-range.js +38 -0
  96. package/rendering/light-budget.js +52 -52
  97. package/rendering/light-shafts.js +23 -23
  98. package/rendering/local-lights.js +15 -4
  99. package/rendering/material-lod.js +49 -49
  100. package/rendering/particle-emitters.js +90 -90
  101. package/rendering/particles.js +78 -67
  102. package/rendering/piece-batch.js +17 -6
  103. package/rendering/planar-reflection.js +38 -38
  104. package/rendering/post-shaders.js +17 -13
  105. package/rendering/post.js +71 -71
  106. package/rendering/rain-streaks.js +67 -0
  107. package/rendering/road-surface.js +11 -11
  108. package/rendering/sea-shaders.js +11 -11
  109. package/rendering/shader-warmup.js +29 -16
  110. package/rendering/shadow-alignment.js +4 -4
  111. package/rendering/shadow-depth.js +7 -7
  112. package/rendering/sky-occlusion.js +16 -16
  113. package/rendering/sky.js +16 -6
  114. package/rendering/stage-lights.js +6 -6
  115. package/rendering/static-point-shadow.js +3 -3
  116. package/rendering/still-casters.js +1 -1
  117. package/rendering/strata-material.js +10 -10
  118. package/rendering/stream-flow.js +10 -10
  119. package/rendering/taa.js +26 -26
  120. package/rendering/talus.js +15 -15
  121. package/rendering/terrain-rock.js +7 -7
  122. package/rendering/texture-fills.js +8 -8
  123. package/rendering/textures.js +28 -28
  124. package/rendering/wakes.js +24 -24
  125. package/rendering/water-material.js +36 -23
  126. package/rendering/world-matrices.js +38 -38
  127. package/runtime/diagnostic-log.js +2 -2
  128. package/runtime/first-use.js +33 -28
  129. package/runtime/frame-pacing.js +33 -0
  130. package/runtime/gpu-timing.js +7 -7
  131. package/runtime/grid-cache.js +1 -1
  132. package/runtime/grid-rows.js +44 -5
  133. package/runtime/hand-over.js +41 -23
  134. package/runtime/pool.js +58 -16
  135. package/runtime/quality-fit.js +1 -1
  136. package/runtime/search.js +22 -22
  137. package/runtime/spatial-audio.js +13 -13
  138. package/runtime/withdrawable-task.js +35 -0
  139. package/runtime/worker.js +7 -0
@@ -43,9 +43,9 @@ class Runs {
43
43
  while (i < this.gaps.length && this.gaps[i][0] < start) i++;
44
44
  this.gaps.splice(i, 0, [start, count]);
45
45
  for (const at of [i, i - 1]) {
46
- const a = this.gaps[at],
47
- b = this.gaps[at + 1];
48
- if (a && b && a[0] + a[1] === b[0]) this.gaps.splice(at, 2, [a[0], a[1] + b[1]]);
46
+ const firstGap = this.gaps[at],
47
+ nextGap = this.gaps[at + 1];
48
+ if (firstGap && nextGap && firstGap[0] + firstGap[1] === nextGap[0]) this.gaps.splice(at, 2, [firstGap[0], firstGap[1] + nextGap[1]]);
49
49
  }
50
50
  }
51
51
  }
@@ -56,6 +56,16 @@ class Runs {
56
56
  * context. Shadow hooks optionally integrate a cache of static point shadows.
57
57
  * Supply static triangle geometry with matching layouts and indexing to each
58
58
  * batch. Attributes use contiguous Float32Array, Int8Array or Uint8Array data.
59
+ * @returns A mesh constructor. Create one instance per batch material.
60
+ * @example
61
+ * ```js
62
+ * const Batch = createPieceBatch({ renderer, camera });
63
+ * const batch = new Batch(material);
64
+ * scene.add(batch);
65
+ * const id = batch.add(geometry);
66
+ * batch.setView(id, batch.materialView(highlightMaterial));
67
+ * batch.setView(id);
68
+ * ```
59
69
  */
60
70
  export function createPieceBatch({ renderer, camera, markStill = () => {}, isStill = () => false, keptAway = () => false }) {
61
71
  const _clip = new THREE.Matrix4(),
@@ -77,6 +87,7 @@ export function createPieceBatch({ renderer, camera, markStill = () => {}, isSti
77
87
  // vertices, indices: how many to make room for at first (a batch that is filled once says exactly how many); fit: LOOSE or TIGHT
78
88
  constructor(material, vertices = 0, indices = 0, fit = LOOSE) {
79
89
  super(new THREE.BufferGeometry(), material);
90
+ this.isPieceBatch = true;
80
91
  this.room = { vertices, indices };
81
92
  this.fit = fit;
82
93
  this.held = { vertices: 0, indices: 0 }; // what the buffers have room for
@@ -105,7 +116,7 @@ export function createPieceBatch({ renderer, camera, markStill = () => {}, isSti
105
116
  index = geometry.index,
106
117
  gl = renderer.getContext();
107
118
  if (!this.layout) {
108
- this.layout = Object.entries(geometry.attributes).map(([name, a]) => [name, a.array.constructor, a.itemSize, a.normalized]);
119
+ this.layout = Object.entries(geometry.attributes).map(([name, attribute]) => [name, attribute.array.constructor, attribute.itemSize, attribute.normalized]);
109
120
  if (index) this.indices = new Uint32Array(0);
110
121
  }
111
122
  const { vertexStart, start } = this.claim(vertexCount, count);
@@ -382,8 +393,8 @@ export function createPieceBatch({ renderer, camera, markStill = () => {}, isSti
382
393
  let seen = 0;
383
394
  for (const piece of pieces) {
384
395
  if (!piece || (mesh === this && piece.view) || !piece.shown || !_view.intersectsSphere(piece.sphere)) continue;
385
- const c = piece.sphere.center;
386
- piece.depth = e[2] * c.x + e[6] * c.y + e[10] * c.z + e[14];
396
+ const centre = piece.sphere.center;
397
+ piece.depth = e[2] * centre.x + e[6] * centre.y + e[10] * centre.z + e[14];
387
398
  _seen[seen++] = piece;
388
399
  }
389
400
  if (seen > 1) {
@@ -32,7 +32,7 @@ export function createPlanarReflection({ camera, renderer, scene, drawnSize, wat
32
32
  x1 = -1,
33
33
  y0 = 1,
34
34
  y1 = -1;
35
- for (let c = 0; c < cells.length; c += 2) {
35
+ for (let cellOffset = 0; cellOffset < cells.length; cellOffset += 2) {
36
36
  let left = true, // is the whole cell off one side of the picture?
37
37
  right = true,
38
38
  below = true,
@@ -54,12 +54,12 @@ export function createPlanarReflection({ camera, renderer, scene, drawnSize, wat
54
54
  by = Math.max(by, y);
55
55
  };
56
56
  for (let k = 0; k < 4; k++)
57
- _corner[k].set(cells[c] + (k === 1 || k === 2 ? cellSize : 0), level, cells[c + 1] + (k > 1 ? cellSize : 0), 1).applyMatrix4(view);
57
+ _corner[k].set(cells[cellOffset] + (k === 1 || k === 2 ? cellSize : 0), level, cells[cellOffset + 1] + (k > 1 ? cellSize : 0), 1).applyMatrix4(view);
58
58
  for (let k = 0; k < 4; k++) {
59
- const a = _corner[k],
60
- b = _corner[(k + 1) % 4];
61
- if (a.w > IN_FRONT) take(a);
62
- if (a.w > IN_FRONT !== b.w > IN_FRONT) take(_cut.lerpVectors(a, b, (IN_FRONT - a.w) / (b.w - a.w))); // where the edge passes the camera's plane
59
+ const corner = _corner[k],
60
+ nextCorner = _corner[(k + 1) % 4];
61
+ if (corner.w > IN_FRONT) take(corner);
62
+ if (corner.w > IN_FRONT !== nextCorner.w > IN_FRONT) take(_cut.lerpVectors(corner, nextCorner, (IN_FRONT - corner.w) / (nextCorner.w - corner.w))); // where the edge passes the camera's plane
63
63
  }
64
64
  if (bx < ax || left || right || below || above) continue;
65
65
  x0 = Math.min(x0, ax);
@@ -76,30 +76,30 @@ export function createPlanarReflection({ camera, renderer, scene, drawnSize, wat
76
76
  // Fits the mirror's camera and target to `part`: whole pixels of the target, and a projection that fills just those, so each
77
77
  // reflected thing lands on the pixel it would have in the whole picture.
78
78
  function fitToPart(projection, target) {
79
- const w = target.width,
80
- h = target.height,
81
- px0 = Math.floor(((part.x0 + 1) / 2) * w),
82
- px1 = Math.ceil(((part.x1 + 1) / 2) * w),
83
- py0 = Math.floor(((part.y0 + 1) / 2) * h),
84
- py1 = Math.ceil(((part.y1 + 1) / 2) * h),
85
- x0 = (2 * px0) / w - 1,
86
- x1 = (2 * px1) / w - 1,
87
- y0 = (2 * py0) / h - 1,
88
- y1 = (2 * py1) / h - 1,
89
- e = projection.elements;
79
+ const width = target.width,
80
+ height = target.height,
81
+ px0 = Math.floor(((part.x0 + 1) / 2) * width),
82
+ px1 = Math.ceil(((part.x1 + 1) / 2) * width),
83
+ py0 = Math.floor(((part.y0 + 1) / 2) * height),
84
+ py1 = Math.ceil(((part.y1 + 1) / 2) * height),
85
+ x0 = (2 * px0) / width - 1,
86
+ x1 = (2 * px1) / width - 1,
87
+ y0 = (2 * py0) / height - 1,
88
+ y1 = (2 * py1) / height - 1,
89
+ projectionElements = projection.elements;
90
90
  for (let col = 0; col < 16; col += 4) {
91
- e[col] = (2 * e[col] - (x0 + x1) * e[col + 3]) / (x1 - x0);
92
- e[col + 1] = (2 * e[col + 1] - (y0 + y1) * e[col + 3]) / (y1 - y0);
91
+ projectionElements[col] = (2 * projectionElements[col] - (x0 + x1) * projectionElements[col + 3]) / (x1 - x0);
92
+ projectionElements[col + 1] = (2 * projectionElements[col + 1] - (y0 + y1) * projectionElements[col + 3]) / (y1 - y0);
93
93
  }
94
94
  target.viewport.set(px0, py0, px1 - px0, py1 - py0);
95
95
  target.scissor.set(px0, py0, px1 - px0, py1 - py0);
96
96
  }
97
97
  function sizeMirror() {
98
98
  // half the size the world is drawn at each way: where the quality fit draws it smaller and upscales it, the mirror shrinks with it
99
- const [w, h] = drawnSize();
100
- if (mirror.rt) mirror.rt.setSize(Math.max(minSize, Math.round(w * scale)), Math.max(minSize, Math.round(h * scale)));
99
+ const [width, height] = drawnSize();
100
+ if (mirror.rt) mirror.rt.setSize(Math.max(minSize, Math.round(width * scale)), Math.max(minSize, Math.round(height * scale)));
101
101
  }
102
- function renderMirror(u, wl, k, unseen, frame) {
102
+ function renderMirror(u, waterLevel, k, unseen, frame) {
103
103
  const M = mirror, cp = camera.position;
104
104
  if (M.off) k = 0; // debug switch, for measuring what the mirror costs
105
105
  u.uReflOn.value = k;
@@ -110,28 +110,28 @@ export function createPlanarReflection({ camera, renderer, scene, drawnSize, wat
110
110
  u.uRefl.value = M.rt.texture;
111
111
  sizeMirror();
112
112
  }
113
- const c = M.cam,
114
- o = M.o.set(0, wl, 0);
113
+ const reflectionCamera = M.cam,
114
+ o = M.o.set(0, waterLevel, 0);
115
115
  M.a.subVectors(o, cp).reflect(M.n).negate().add(o);
116
- c.position.copy(M.a);
116
+ reflectionCamera.position.copy(M.a);
117
117
  M.rot.extractRotation(camera.matrixWorld);
118
118
  M.b.set(0, 0, -1).applyMatrix4(M.rot).add(cp);
119
119
  M.a.subVectors(o, M.b).reflect(M.n).negate().add(o);
120
- c.up.set(0, 1, 0).applyMatrix4(M.rot).reflect(M.n);
121
- c.lookAt(M.a);
122
- c.near = camera.near;
123
- c.far = camera.far;
124
- c.updateMatrixWorld();
125
- c.projectionMatrix.copy(camera.projectionMatrix);
120
+ reflectionCamera.up.set(0, 1, 0).applyMatrix4(M.rot).reflect(M.n);
121
+ reflectionCamera.lookAt(M.a);
122
+ reflectionCamera.near = camera.near;
123
+ reflectionCamera.far = camera.far;
124
+ reflectionCamera.updateMatrixWorld();
125
+ reflectionCamera.projectionMatrix.copy(camera.projectionMatrix);
126
126
  u.uReflM.value
127
127
  .set(0.5, 0, 0, 0.5, 0, 0.5, 0, 0.5, 0, 0, 0.5, 0.5, 0, 0, 0, 1)
128
- .multiply(c.projectionMatrix)
129
- .multiply(c.matrixWorldInverse);
130
- const whole = !findWaterPart(M.m.multiplyMatrices(c.projectionMatrix, c.matrixWorldInverse), wl); // no cell found where water was seen: draw it all
128
+ .multiply(reflectionCamera.projectionMatrix)
129
+ .multiply(reflectionCamera.matrixWorldInverse);
130
+ const whole = !findWaterPart(M.m.multiplyMatrices(reflectionCamera.projectionMatrix, reflectionCamera.matrixWorldInverse), waterLevel); // no cell found where water was seen: draw it all
131
131
  // tilt the near plane onto the water, so nothing under the surface gets into the mirror
132
- M.plane.setFromNormalAndCoplanarPoint(M.n, M.o.set(0, wl - 0.05, 0)).applyMatrix4(c.matrixWorldInverse);
132
+ M.plane.setFromNormalAndCoplanarPoint(M.n, M.o.set(0, waterLevel - 0.05, 0)).applyMatrix4(reflectionCamera.matrixWorldInverse);
133
133
  const cl = M.clip.set(M.plane.normal.x, M.plane.normal.y, M.plane.normal.z, M.plane.constant),
134
- pe = c.projectionMatrix.elements,
134
+ pe = reflectionCamera.projectionMatrix.elements,
135
135
  q = M.q;
136
136
  q.x = (Math.sign(cl.x) + pe[8]) / pe[0];
137
137
  q.y = (Math.sign(cl.y) + pe[9]) / pe[5];
@@ -155,11 +155,11 @@ export function createPlanarReflection({ camera, renderer, scene, drawnSize, wat
155
155
  renderer.clear();
156
156
  renderer.setClearColor(_colour, alpha);
157
157
  if (!whole) {
158
- fitToPart(c.projectionMatrix, M.rt);
158
+ fitToPart(reflectionCamera.projectionMatrix, M.rt);
159
159
  M.rt.scissorTest = true;
160
160
  renderer.setRenderTarget(M.rt);
161
161
  }
162
- renderer.render(scene, c);
162
+ renderer.render(scene, reflectionCamera);
163
163
  } finally {
164
164
  renderer.setClearColor(_colour, alpha);
165
165
  renderer.setRenderTarget(previous, face, mip);
@@ -57,7 +57,7 @@ const AO_FS = `/* glsl */ uniform sampler2D tDepth; uniform vec2 uNF, uTan, uPx;
57
57
  // Additive blending can overflow the half-float buffer; one infinite or invalid pixel would be smeared by bloom into a black square,
58
58
  // so both the bloom's input and the final pass make every pixel finite and cap it.
59
59
  const SANE =
60
- 'vec3 sane(vec3 c){ if (!(c.r >= 0.0)) c.r = 0.0; if (!(c.g >= 0.0)) c.g = 0.0; if (!(c.b >= 0.0)) c.b = 0.0; return min(c, vec3(48.0)); }';
60
+ 'vec3 sane(vec3 sampleColor){ if (!(sampleColor.r >= 0.0)) sampleColor.r = 0.0; if (!(sampleColor.g >= 0.0)) sampleColor.g = 0.0; if (!(sampleColor.b >= 0.0)) sampleColor.b = 0.0; return min(sampleColor, vec3(48.0)); }';
61
61
 
62
62
  // Bloom: what is brighter than BLOOM.threshold is blurred at five sizes, from half the frame down to a thirty-second, each level blurred
63
63
  // across and then down with a wider Gaussian (the same blur and weights as Three's UnrealBloomPass), and the final pass adds the five.
@@ -79,12 +79,12 @@ const BLUR_FS = `/* glsl */ uniform sampler2D tSrc; uniform vec2 uStep; uniform
79
79
  // The grade after tone mapping: saturation, a touch of contrast, cool shadows and warm lights, the vignette. Shared by the final
80
80
  // pass and the names drawn after it, so both are graded alike.
81
81
  const GRADE = `/* glsl */ uniform float uVig, uSat;
82
- vec3 gradeTail(vec3 c, vec2 uv){
83
- float l = dot(c, vec3(0.2126, 0.7152, 0.0722));
84
- c = mix(vec3(l), c, uSat);
85
- c = mix(c, c * c * (3.0 - 2.0 * c), 0.16);
86
- c *= mix(vec3(0.95, 0.985, 1.06), vec3(1.045, 1.0, 0.95), smoothstep(0.0, 0.75, l));
87
- vec2 q = uv - 0.5; return c * (1.0 - uVig * smoothstep(0.22, 1.0, dot(q, q) * 2.3)); }`;
82
+ vec3 gradeTail(vec3 sceneColor, vec2 uv){
83
+ float l = dot(sceneColor, vec3(0.2126, 0.7152, 0.0722));
84
+ sceneColor = mix(vec3(l), sceneColor, uSat);
85
+ sceneColor = mix(sceneColor, sceneColor * sceneColor * (3.0 - 2.0 * sceneColor), 0.16);
86
+ sceneColor *= mix(vec3(0.95, 0.985, 1.06), vec3(1.045, 1.0, 0.95), smoothstep(0.0, 0.75, l));
87
+ vec2 q = uv - 0.5; return sceneColor * (1.0 - uVig * smoothstep(0.22, 1.0, dot(q, q) * 2.3)); }`;
88
88
  // A pixel's own noise of half a step of the 8-bit screen, against banding.
89
89
  const DITHER = '(fract(sin(dot(gl_FragCoord.xy + uTime, vec2(12.9898, 78.233))) * 43758.5453) - 0.5) / 255.0';
90
90
 
@@ -94,7 +94,11 @@ const DOF_COC = `/* glsl */ float cocAt(float z){ return min(uDof.y * abs(z - uD
94
94
  const DOF_MIX = `/* glsl */
95
95
  if (uDof.w > 0.0) { soft = texture2D(tDof, vUv).rgb; softShare = smoothstep(0.8, 2.5, cocAt(viewDepth(vUv))) * uDof.w; }`;
96
96
  // ACES fitted curve by Stephen Hill, from Baking Lab (licenses/baking-lab.txt), as used in Three.js (licenses/three.txt).
97
- const ACES = `/* glsl */ vec3 fit(vec3 v){ vec3 a = v * (v + 0.0245786) - 0.000090537; vec3 b = v * (0.983729 * v + 0.4329510) + 0.238081; return a / b; }
97
+ const ACES = `/* glsl */ vec3 fit(vec3 exposedColor){
98
+ vec3 numerator = exposedColor * (exposedColor + 0.0245786) - 0.000090537;
99
+ vec3 denominator = exposedColor * (0.983729 * exposedColor + 0.4329510) + 0.238081;
100
+ return numerator / denominator;
101
+ }
98
102
  vec3 acesCurve(vec3 c){
99
103
  const mat3 mi = mat3(vec3(0.59719, 0.07600, 0.02840), vec3(0.35458, 0.90834, 0.13383), vec3(0.04823, 0.01566, 0.83777));
100
104
  const mat3 mo = mat3(vec3(1.60475, -0.10208, -0.00327), vec3(-0.53108, 1.10813, -0.07276), vec3(-0.07367, -0.00605, 1.07602));
@@ -173,11 +177,11 @@ ${STEADY}
173
177
  // Edge adaptation and sharpening follow AMD FidelityFX Super Resolution 1 (licenses/fidelityfx-fsr.txt).
174
178
  // A sharpening held within its neighbours (as FSR 1's RCAS): e is pushed away from the four round it (b above, d left, f right, h below)
175
179
  // by up to sharp (0 to 1), only as far as keeps it inside their range, so edges come back crisp without halos.
176
- const SHARPEN = `/* glsl */ vec3 sharpen(vec3 b, vec3 d, vec3 e, vec3 f, vec3 h, float sharp){
177
- vec3 mn = min(min(b, d), min(f, h)), mx = max(max(b, d), max(f, h));
178
- vec3 lobes = max(-min(mn, e) / (4.0 * mx + 1e-5), (1.0 - max(mx, e)) / (4.0 * mn - 4.0 - 1e-5));
180
+ const SHARPEN = `/* glsl */ vec3 sharpen(vec3 upperColor, vec3 leftColor, vec3 centerColor, vec3 rightColor, vec3 lowerColor, float sharp){
181
+ vec3 neighbourMin = min(min(upperColor, leftColor), min(rightColor, lowerColor)), neighbourMax = max(max(upperColor, leftColor), max(rightColor, lowerColor));
182
+ vec3 lobes = max(-min(neighbourMin, centerColor) / (4.0 * neighbourMax + 1e-5), (1.0 - max(neighbourMax, centerColor)) / (4.0 * neighbourMin - 4.0 - 1e-5));
179
183
  float lobe = max(-0.1875, min(max(lobes.r, max(lobes.g, lobes.b)), 0.0)) * sharp;
180
- return (lobe * (b + d + f + h) + e) / (4.0 * lobe + 1.0); }`;
184
+ return (lobe * (upperColor + leftColor + rightColor + lowerColor) + centerColor) / (4.0 * lobe + 1.0); }`;
181
185
  // The present pass, with temporal anti-aliasing: the running picture sharpened a little (a running picture is a little softer than one
182
186
  // frame; where the upscale follows, its own sharpening does this), tone-mapped, graded and encoded for the screen, with its noise and
183
187
  // the depth.
@@ -200,7 +204,7 @@ const PRESENT_FS = `/* glsl */ uniform sampler2D tSrc, tDepth; uniform vec2 uPx;
200
204
  // Works on the graded picture, where steps of light are as the eye sees them.
201
205
  const EASU_FS = `/* glsl */ uniform sampler2D tSrc; uniform vec2 uSrcSize; varying vec2 vUv;
202
206
  vec3 tap(vec2 p){ return texture2D(tSrc, (p + 0.5) / uSrcSize).rgb; }
203
- float luma(vec3 c){ return c.g + 0.5 * (c.r + c.b); }
207
+ float luma(vec3 color){ return color.g + 0.5 * (color.r + color.b); }
204
208
  // the edge at one of the four central texels, from its four neighbours, weighted by the sample's nearness to it: its direction, and how
205
209
  // much it is an edge (a step on one side only) rather than a thin line or noise (steps both ways)
206
210
  void edge(inout vec2 dir, inout float len, float w, float up, float left, float mid, float right, float down){
package/rendering/post.js CHANGED
@@ -113,25 +113,25 @@ export function createPostProcessing({
113
113
  const overlay = new THREE.Scene();
114
114
  // A scene of one quad that covers the screen, for a post-processing pass.
115
115
  function fullScreen(material) {
116
- const s = new THREE.Scene(),
117
- q = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), material);
118
- q.frustumCulled = false;
119
- s.add(q);
120
- return s;
116
+ const passScene = new THREE.Scene(),
117
+ fullscreenQuad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), material);
118
+ fullscreenQuad.frustumCulled = false;
119
+ passScene.add(fullscreenQuad);
120
+ return passScene;
121
121
  }
122
122
  // Depth of field while a scene's shot names a focus (dof.js): eased in over a few frames, and out when none is named.
123
- function focus(rn) {
123
+ function focus(passRenderer) {
124
124
  const named = dof.named >= getFrame() - 1;
125
125
  dof.weight = named ? Math.min(1, dof.weight + DOF_EASE) : Math.max(0, dof.weight - DOF_EASE);
126
- const d = dof.material.uniforms;
127
- d.uDof.value.x = dof.focus;
128
- d.uDof.value.w = dof.weight;
126
+ const dofUniforms = dof.material.uniforms;
127
+ dofUniforms.uDof.value.x = dof.focus;
128
+ dofUniforms.uDof.value.w = dof.weight;
129
129
  if (dof.weight <= 0) return;
130
- d.tScene.value = post.sceneRT.texture;
131
- d.tDepth.value = post.sceneRT.depthTexture;
132
- d.uNF.value.set(camera.near, camera.far);
133
- rn.setRenderTarget(dof.target);
134
- rn.render(post.dofScene, post.aoCam);
130
+ dofUniforms.tScene.value = post.sceneRT.texture;
131
+ dofUniforms.tDepth.value = post.sceneRT.depthTexture;
132
+ dofUniforms.uNF.value.set(camera.near, camera.far);
133
+ passRenderer.setRenderTarget(dof.target);
134
+ passRenderer.render(post.dofScene, post.aoCam);
135
135
  }
136
136
  // Whether any particle is alive (empty pools have their visibility turned off).
137
137
  function particlesShown() {
@@ -142,7 +142,7 @@ export function createPostProcessing({
142
142
  // Draws the particles over what is in `target` (null: the screen). With a target of one sample a pixel they fade by the depth the
143
143
  // occlusion pass has just kept (Medium and High); without post-processing, or over a multisampled target, they meet the scene hard
144
144
  // as before (its depth is not read: a multisampled target's colour is resolved again after them, its depth is not).
145
- function drawParticles(rn, target) {
145
+ function drawParticles(passRenderer, target) {
146
146
  if (!particlesShown()) return;
147
147
  const soft = target !== null && !post.samples;
148
148
  sceneDepth.uSoft.value = soft ? 1 : 0;
@@ -150,14 +150,14 @@ export function createPostProcessing({
150
150
  sceneDepth.uDepth.value = post.aoRT.texture;
151
151
  sceneDepth.uDepthPx.value.set(1 / post.aoRT.width, 1 / post.aoRT.height);
152
152
  }
153
- const clears = rn.autoClear,
153
+ const clears = passRenderer.autoClear,
154
154
  resolves = target?.resolveDepthBuffer;
155
- rn.autoClear = false;
155
+ passRenderer.autoClear = false;
156
156
  if (target) target.resolveDepthBuffer = false;
157
- rn.setRenderTarget(target);
158
- rn.render(fxScene, camera);
157
+ passRenderer.setRenderTarget(target);
158
+ passRenderer.render(fxScene, camera);
159
159
  if (target) target.resolveDepthBuffer = resolves;
160
- rn.autoClear = clears;
160
+ passRenderer.autoClear = clears;
161
161
  }
162
162
  // Builds the post-processing chain described at the top of this module, with samples of anti-aliasing, and temporal
163
163
  // anti-aliasing where taa is true.
@@ -236,45 +236,45 @@ export function createPostProcessing({
236
236
  renderToScreen: false,
237
237
  setSize(w, h) {
238
238
  sceneRT.setSize(w, h);
239
- for (const t of [post.aoRT, post.rayRT, post.maskRT, dof.target]) t.setSize(Math.ceil(w / 2), Math.ceil(h / 2));
239
+ for (const target of [post.aoRT, post.rayRT, post.maskRT, dof.target]) target.setSize(Math.ceil(w / 2), Math.ceil(h / 2));
240
240
  sizeHistory(w, h);
241
- const d = dof.material.uniforms;
242
- d.uPx.value.set(1 / w, 1 / h);
243
- d.uDof.value.y = DOF_BLUR * h;
244
- d.uDof.value.z = DOF_MOST * h;
241
+ const dofUniforms = dof.material.uniforms;
242
+ dofUniforms.uPx.value.set(1 / w, 1 / h);
243
+ dofUniforms.uDof.value.y = DOF_BLUR * h;
244
+ dofUniforms.uDof.value.z = DOF_MOST * h;
245
245
  mask.uPx.value.set(1 / post.maskRT.width, 1 / post.maskRT.height);
246
246
  },
247
- render(rn) {
247
+ render(passRenderer) {
248
248
  const u = post.final.uniforms;
249
- rn.setRenderTarget(sceneRT);
249
+ passRenderer.setRenderTarget(sceneRT);
250
250
  if (taa) jitterLens(sceneRT.width, sceneRT.height);
251
- rn.render(scene, camera);
251
+ passRenderer.render(scene, camera);
252
252
  u.uPx.value.set(1 / sceneRT.width, 1 / sceneRT.height);
253
253
  u.uHp.value.set(1 / post.aoRT.width, 1 / post.aoRT.height);
254
254
  {
255
- const a = post.aoMat.uniforms;
256
- a.uPx.value.copy(u.uPx.value);
257
- a.uTan.value.copy(u.uTan.value);
258
- a.uAspect.value = u.uAspect.value;
259
- a.uAO.value = u.uAO.value;
260
- a.uContact.value.y = contactStrength();
261
- rn.setRenderTarget(post.aoRT);
262
- rn.render(post.aoScene, post.aoCam);
255
+ const occlusionUniforms = post.aoMat.uniforms;
256
+ occlusionUniforms.uPx.value.copy(u.uPx.value);
257
+ occlusionUniforms.uTan.value.copy(u.uTan.value);
258
+ occlusionUniforms.uAspect.value = u.uAspect.value;
259
+ occlusionUniforms.uAO.value = u.uAO.value;
260
+ occlusionUniforms.uContact.value.y = contactStrength();
261
+ passRenderer.setRenderTarget(post.aoRT);
262
+ passRenderer.render(post.aoScene, post.aoCam);
263
263
  }
264
- drawParticles(rn, sceneRT);
264
+ drawParticles(passRenderer, sceneRT);
265
265
  if (taa) steadyLens();
266
- adaptEye(rn, sceneRT.texture);
266
+ adaptEye(passRenderer, sceneRT.texture);
267
267
  u.tEye.value = eye.level;
268
268
  u.uEye.value.x = expectedLogLuminance();
269
- focus(rn);
269
+ focus(passRenderer);
270
270
  if (u.uRay.value > 0.002) {
271
- rn.setRenderTarget(post.maskRT);
272
- rn.render(post.maskScene, camera);
273
- const a = post.rayMat.uniforms;
274
- a.uSun.value.copy(u.uSun.value);
275
- a.uAspect.value = u.uAspect.value;
276
- rn.setRenderTarget(post.rayRT);
277
- rn.render(post.rayScene, post.aoCam);
271
+ passRenderer.setRenderTarget(post.maskRT);
272
+ passRenderer.render(post.maskScene, camera);
273
+ const rayUniforms = post.rayMat.uniforms;
274
+ rayUniforms.uSun.value.copy(u.uSun.value);
275
+ rayUniforms.uAspect.value = u.uAspect.value;
276
+ passRenderer.setRenderTarget(post.rayRT);
277
+ passRenderer.render(post.rayScene, post.aoCam);
278
278
  }
279
279
  },
280
280
  dispose() {},
@@ -331,19 +331,19 @@ export function createPostProcessing({
331
331
  material: finalMat,
332
332
  uniforms: finalMat.uniforms,
333
333
  setSize() {}, // sized with the rest by sizePost
334
- render(rn) {
334
+ render(passRenderer) {
335
335
  if (taa) {
336
- rn.setRenderTarget(historyInto());
337
- rn.render(finalScene, post.aoCam);
336
+ passRenderer.setRenderTarget(historyInto());
337
+ passRenderer.render(finalScene, post.aoCam);
338
338
  present.uniforms.tSrc.value = historyNow().texture;
339
339
  }
340
- rn.setRenderTarget(upscale.low); // the screen, where the world is drawn at its size
341
- rn.render(taa ? presentScene : finalScene, post.aoCam);
340
+ passRenderer.setRenderTarget(upscale.low); // the screen, where the world is drawn at its size
341
+ passRenderer.render(taa ? presentScene : finalScene, post.aoCam);
342
342
  if (!upscale.low) return;
343
- rn.setRenderTarget(upscale.full);
344
- rn.render(easuScene, post.aoCam);
345
- rn.setRenderTarget(null);
346
- rn.render(rcasScene, post.aoCam);
343
+ passRenderer.setRenderTarget(upscale.full);
344
+ passRenderer.render(easuScene, post.aoCam);
345
+ passRenderer.setRenderTarget(null);
346
+ passRenderer.render(rcasScene, post.aoCam);
347
347
  },
348
348
  dispose() {},
349
349
  };
@@ -371,13 +371,13 @@ export function createPostProcessing({
371
371
  mesh = quad.children[0],
372
372
  cam = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
373
373
  const target = () => {
374
- const t = new THREE.WebGLRenderTarget(2, 2, { type: THREE.HalfFloatType, format: THREE.RGBFormat, depthBuffer: false });
375
- t.texture.internalFormat = 'R11F_G11F_B10F';
376
- return t;
374
+ const target = new THREE.WebGLRenderTarget(2, 2, { type: THREE.HalfFloatType, format: THREE.RGBFormat, depthBuffer: false });
375
+ target.texture.internalFormat = 'R11F_G11F_B10F';
376
+ return target;
377
377
  };
378
- const blur = (k, first) => {
378
+ const blur = (kernelSize, first) => {
379
379
  const coeff = [];
380
- for (let j = 0; j < k; j++) coeff.push((0.39894 * Math.exp((-0.5 * j * j) / (k * k))) / k);
380
+ for (let j = 0; j < kernelSize; j++) coeff.push((0.39894 * Math.exp((-0.5 * j * j) / (kernelSize * kernelSize))) / kernelSize);
381
381
  return new THREE.ShaderMaterial({
382
382
  depthTest: false,
383
383
  depthWrite: false,
@@ -387,19 +387,19 @@ export function createPostProcessing({
387
387
  tSrc: { value: null },
388
388
  uStep: { value: new THREE.Vector2() },
389
389
  uK: { value: coeff },
390
- uTaps: { value: k },
390
+ uTaps: { value: kernelSize },
391
391
  uBright: { value: first },
392
392
  },
393
393
  });
394
394
  };
395
395
  // each level is blurred across (hMat) into h, then down (vMat) into v; only the first blur across reads the scene and keeps its bright part
396
- const levels = BLOOM.kernels.map((k, i) => {
397
- const vMat = blur(k, false);
398
- return { h: target(), v: target(), hMat: i === 0 ? blur(k, true) : vMat, vMat };
396
+ const levels = BLOOM.kernels.map((kernelSize, i) => {
397
+ const vMat = blur(kernelSize, false);
398
+ return { h: target(), v: target(), hMat: i === 0 ? blur(kernelSize, true) : vMat, vMat };
399
399
  });
400
400
  // the levels' weights: strength, times the factor moved towards its mirror by the radius (as Three's composite does)
401
- const weights = BLOOM.factors.map(f => {
402
- const w = BLOOM.strength * THREE.MathUtils.lerp(f, 1.2 - f, BLOOM.radius);
401
+ const weights = BLOOM.factors.map(factor => {
402
+ const w = BLOOM.strength * THREE.MathUtils.lerp(factor, 1.2 - factor, BLOOM.radius);
403
403
  return new THREE.Vector3(w, w, w);
404
404
  });
405
405
  return {
@@ -420,21 +420,21 @@ export function createPostProcessing({
420
420
  y = Math.round(y / 2);
421
421
  }
422
422
  },
423
- render(rn) {
423
+ render(passRenderer) {
424
424
  let from = sceneRT.texture;
425
425
  for (const l of levels) {
426
426
  let u = l.hMat.uniforms;
427
427
  mesh.material = l.hMat;
428
428
  u.tSrc.value = from;
429
429
  u.uStep.value.set(1 / l.size[0], 0);
430
- rn.setRenderTarget(l.h);
431
- rn.render(quad, cam);
430
+ passRenderer.setRenderTarget(l.h);
431
+ passRenderer.render(quad, cam);
432
432
  u = l.vMat.uniforms;
433
433
  mesh.material = l.vMat;
434
434
  u.tSrc.value = l.h.texture;
435
435
  u.uStep.value.set(0, 1 / l.size[1]);
436
- rn.setRenderTarget(l.v);
437
- rn.render(quad, cam);
436
+ passRenderer.setRenderTarget(l.v);
437
+ passRenderer.render(quad, cam);
438
438
  from = l.v.texture;
439
439
  }
440
440
  },
@@ -0,0 +1,67 @@
1
+ import * as THREE from 'three';
2
+
3
+ // One camera-centred instanced draw. The shared wind velocity tilts the streaks,
4
+ // while its accumulated displacement carries them smoothly through changes of wind.
5
+ export function createRainStreaks({ capacity, windUniforms, random = Math.random }) {
6
+ if (!(Number.isSafeInteger(capacity) && capacity > 0)) throw new RangeError('Rain capacity must be a positive integer');
7
+ const geometry = new THREE.InstancedBufferGeometry();
8
+ geometry.setAttribute('position', new THREE.Float32BufferAttribute([-0.5, 0, 0, 0.5, 0, 0, 0.5, 1, 0, -0.5, 1, 0], 3));
9
+ geometry.setIndex([0, 1, 2, 0, 2, 3]);
10
+ {
11
+ const off = new Float32Array(capacity * 4);
12
+ for (let i = 0; i < off.length; i++) off[i] = random();
13
+ geometry.setAttribute('aOff', new THREE.InstancedBufferAttribute(off, 4));
14
+ }
15
+ geometry.instanceCount = capacity;
16
+ const rainU = {
17
+ uCam: { value: new THREE.Vector3() },
18
+ uTime: { value: 0 },
19
+ uRain: { value: 0 },
20
+ uCol: { value: new THREE.Color() },
21
+ uWind: windUniforms.uWind,
22
+ uWindDrift: windUniforms.uWindDrift,
23
+ };
24
+ const rainMat = new THREE.ShaderMaterial({
25
+ uniforms: rainU,
26
+ transparent: true,
27
+ depthWrite: false,
28
+ fog: false,
29
+ vertexShader: /* glsl */ `
30
+ uniform vec3 uCam; uniform float uTime, uRain; uniform vec3 uWind; uniform vec2 uWindDrift;
31
+ attribute vec4 aOff; varying float vA; varying vec2 vUv;
32
+ const vec3 B = vec3(52.0, 28.0, 52.0); // the box of falling rain round the eye, in metres
33
+ void main(){
34
+ float speed = 8.0 + 2.5 * aOff.w;
35
+ vec3 fall = vec3(uWind.x, -speed, uWind.y);
36
+ vec3 rel = mod(aOff.xyz * B + vec3(uWindDrift.x, -speed * uTime, uWindDrift.y) - uCam + B * 0.5, B) - B * 0.5; // where this drop is now, wrapped round the eye
37
+ vec3 c = uCam + rel, dir = normalize(fall);
38
+ vec3 side = normalize(cross(dir, normalize(-rel + vec3(0.0, 0.0, 0.001))));
39
+ float d = length(rel);
40
+ vec3 wp = c + side * position.x * (0.009 + d * 0.0006) + dir * position.y * (0.5 + 0.3 * aOff.w);
41
+ vA = step(fract(aOff.w * 7.31), uRain * 1.05) * (1.0 - smoothstep(14.0, 26.0, length(rel.xz))) * (1.0 - smoothstep(9.0, 13.5, abs(rel.y))) * smoothstep(0.5, 2.0, d);
42
+ vUv = position.xy + vec2(0.5, 0.0);
43
+ gl_Position = projectionMatrix * viewMatrix * vec4(wp, 1.0);
44
+ }`,
45
+ fragmentShader: /* glsl */ `
46
+ uniform vec3 uCol; varying float vA; varying vec2 vUv;
47
+ void main(){
48
+ float a = vA * (1.0 - abs(vUv.x * 2.0 - 1.0)) * smoothstep(0.0, 0.35, vUv.y) * (1.0 - smoothstep(0.6, 1.0, vUv.y));
49
+ if (a < 0.003) discard;
50
+ gl_FragColor = vec4(uCol, a * 0.34);
51
+ }`,
52
+ });
53
+ const mesh = new THREE.Mesh(geometry, rainMat);
54
+ mesh.frustumCulled = false;
55
+ mesh.visible = false;
56
+
57
+ // Camera position in world space, elapsed seconds, shower intensity and fraction of capacity.
58
+ function update(eye, seconds, intensity, density = 1) {
59
+ geometry.instanceCount = Math.round(capacity * THREE.MathUtils.clamp(density, 0, 1));
60
+ mesh.visible = intensity > 0 && geometry.instanceCount > 0;
61
+ if (!mesh.visible) return;
62
+ rainU.uCam.value.copy(eye);
63
+ rainU.uTime.value = seconds;
64
+ rainU.uRain.value = intensity;
65
+ }
66
+ return { mesh, color: rainU.uCol.value, update };
67
+ }
@@ -2,9 +2,9 @@ import * as THREE from 'three';
2
2
 
3
3
  // Packed earth, wheel ruts and rain-dependent puddles on a road strip.
4
4
  const ROAD_COMMON = `/* glsl */ varying vec4 vRoad; varying vec3 vRW; float gPud = 0.0;
5
- float rh(vec2 p){ vec3 q = fract(vec3(p.xyx) * .1031); q += dot(q, q.yzx + 33.33); return fract((q.x + q.y) * q.z); }
6
- float rn(vec2 p){ vec2 i = floor(p), f = fract(p); f = f * f * (3.0 - 2.0 * f);
7
- return mix(mix(rh(i), rh(i + vec2(1, 0)), f.x), mix(rh(i + vec2(0, 1)), rh(i + vec2(1, 1)), f.x), f.y); }
5
+ float rh(vec2 samplePosition){ vec3 mixed = fract(vec3(samplePosition.xyx) * .1031); mixed += dot(mixed, mixed.yzx + 33.33); return fract((mixed.x + mixed.y) * mixed.z); }
6
+ float rn(vec2 samplePosition){ vec2 cell = floor(samplePosition), blend = fract(samplePosition); blend = blend * blend * (3.0 - 2.0 * blend);
7
+ return mix(mix(rh(cell), rh(cell + vec2(1, 0)), blend.x), mix(rh(cell + vec2(0, 1)), rh(cell + vec2(1, 1)), blend.x), blend.y); }
8
8
  varying vec3 vVerge; uniform sampler2D uGrit; uniform float uRoadDamp;`;
9
9
  const ROAD_SURFACE = `/* glsl */
10
10
  float x = vRoad.x, s = vRoad.y, hw = vRoad.z, fine = smoothstep(160.0, 45.0, length(vViewPosition)); // fine grain fades out before it can shimmer
@@ -31,7 +31,7 @@ const ROAD_SHEEN = `/* glsl */
31
31
  #include <opaque_fragment>`;
32
32
 
33
33
  export function createRoadMaterial({ grit, dampness = { value: 0 } }) {
34
- const mat = new THREE.MeshStandardMaterial({
34
+ const material = new THREE.MeshStandardMaterial({
35
35
  transparent: true,
36
36
  depthWrite: false,
37
37
  vertexColors: true,
@@ -40,10 +40,10 @@ export function createRoadMaterial({ grit, dampness = { value: 0 } }) {
40
40
  polygonOffsetFactor: -2,
41
41
  polygonOffsetUnits: -2,
42
42
  });
43
- mat.onBeforeCompile = sh => {
44
- sh.uniforms.uGrit = { value: grit };
45
- sh.uniforms.uRoadDamp = dampness;
46
- sh.vertexShader = sh.vertexShader
43
+ material.onBeforeCompile = shader => {
44
+ shader.uniforms.uGrit = { value: grit };
45
+ shader.uniforms.uRoadDamp = dampness;
46
+ shader.vertexShader = shader.vertexShader
47
47
  .replace(
48
48
  '#include <common>',
49
49
  '#include <common>\nattribute vec4 road; attribute vec3 verge; varying vec4 vRoad; varying vec3 vRW, vVerge;',
@@ -52,12 +52,12 @@ export function createRoadMaterial({ grit, dampness = { value: 0 } }) {
52
52
  '#include <begin_vertex>',
53
53
  '#include <begin_vertex>\nvRoad = road; vVerge = verge; vRW = (modelMatrix * vec4(position, 1.0)).xyz;',
54
54
  );
55
- sh.fragmentShader = sh.fragmentShader
55
+ shader.fragmentShader = shader.fragmentShader
56
56
  .replace('#include <common>', '#include <common>\n' + ROAD_COMMON)
57
57
  .replace('#include <color_fragment>', '#include <color_fragment>\n' + ROAD_SURFACE)
58
58
  .replace('#include <roughnessmap_fragment>', 'float roughnessFactor = mix(roughness, 0.08, gPud);')
59
59
  .replace('#include <opaque_fragment>', ROAD_SHEEN);
60
60
  };
61
- mat.customProgramCacheKey = () => 'road-earth';
62
- return mat;
61
+ material.customProgramCacheKey = () => 'road-earth';
62
+ return material;
63
63
  }