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/piece-batch.js
CHANGED
|
@@ -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
|
|
47
|
-
|
|
48
|
-
if (
|
|
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,
|
|
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
|
|
386
|
-
piece.depth = e[2] *
|
|
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
|
|
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[
|
|
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
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
if (
|
|
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
|
|
80
|
-
|
|
81
|
-
px0 = Math.floor(((part.x0 + 1) / 2) *
|
|
82
|
-
px1 = Math.ceil(((part.x1 + 1) / 2) *
|
|
83
|
-
py0 = Math.floor(((part.y0 + 1) / 2) *
|
|
84
|
-
py1 = Math.ceil(((part.y1 + 1) / 2) *
|
|
85
|
-
x0 = (2 * px0) /
|
|
86
|
-
x1 = (2 * px1) /
|
|
87
|
-
y0 = (2 * py0) /
|
|
88
|
-
y1 = (2 * py1) /
|
|
89
|
-
|
|
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
|
-
|
|
92
|
-
|
|
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 [
|
|
100
|
-
if (mirror.rt) mirror.rt.setSize(Math.max(minSize, Math.round(
|
|
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,
|
|
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
|
|
114
|
-
o = M.o.set(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
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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(
|
|
129
|
-
.multiply(
|
|
130
|
-
const whole = !findWaterPart(M.m.multiplyMatrices(
|
|
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,
|
|
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 =
|
|
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(
|
|
158
|
+
fitToPart(reflectionCamera.projectionMatrix, M.rt);
|
|
159
159
|
M.rt.scissorTest = true;
|
|
160
160
|
renderer.setRenderTarget(M.rt);
|
|
161
161
|
}
|
|
162
|
-
renderer.render(scene,
|
|
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
|
|
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
|
|
83
|
-
float l = dot(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
vec2 q = uv - 0.5; return
|
|
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
|
|
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
|
|
177
|
-
vec3
|
|
178
|
-
vec3 lobes = max(-min(
|
|
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 * (
|
|
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
|
|
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
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
return
|
|
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(
|
|
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
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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(
|
|
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 =
|
|
153
|
+
const clears = passRenderer.autoClear,
|
|
154
154
|
resolves = target?.resolveDepthBuffer;
|
|
155
|
-
|
|
155
|
+
passRenderer.autoClear = false;
|
|
156
156
|
if (target) target.resolveDepthBuffer = false;
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
passRenderer.setRenderTarget(target);
|
|
158
|
+
passRenderer.render(fxScene, camera);
|
|
159
159
|
if (target) target.resolveDepthBuffer = resolves;
|
|
160
|
-
|
|
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
|
|
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
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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(
|
|
247
|
+
render(passRenderer) {
|
|
248
248
|
const u = post.final.uniforms;
|
|
249
|
-
|
|
249
|
+
passRenderer.setRenderTarget(sceneRT);
|
|
250
250
|
if (taa) jitterLens(sceneRT.width, sceneRT.height);
|
|
251
|
-
|
|
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
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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(
|
|
264
|
+
drawParticles(passRenderer, sceneRT);
|
|
265
265
|
if (taa) steadyLens();
|
|
266
|
-
adaptEye(
|
|
266
|
+
adaptEye(passRenderer, sceneRT.texture);
|
|
267
267
|
u.tEye.value = eye.level;
|
|
268
268
|
u.uEye.value.x = expectedLogLuminance();
|
|
269
|
-
focus(
|
|
269
|
+
focus(passRenderer);
|
|
270
270
|
if (u.uRay.value > 0.002) {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
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(
|
|
334
|
+
render(passRenderer) {
|
|
335
335
|
if (taa) {
|
|
336
|
-
|
|
337
|
-
|
|
336
|
+
passRenderer.setRenderTarget(historyInto());
|
|
337
|
+
passRenderer.render(finalScene, post.aoCam);
|
|
338
338
|
present.uniforms.tSrc.value = historyNow().texture;
|
|
339
339
|
}
|
|
340
|
-
|
|
341
|
-
|
|
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
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
|
375
|
-
|
|
376
|
-
return
|
|
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 = (
|
|
378
|
+
const blur = (kernelSize, first) => {
|
|
379
379
|
const coeff = [];
|
|
380
|
-
for (let j = 0; j <
|
|
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:
|
|
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((
|
|
397
|
-
const vMat = blur(
|
|
398
|
-
return { h: target(), v: target(), hMat: i === 0 ? blur(
|
|
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(
|
|
402
|
-
const w = BLOOM.strength * THREE.MathUtils.lerp(
|
|
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(
|
|
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
|
-
|
|
431
|
-
|
|
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
|
-
|
|
437
|
-
|
|
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
|
|
6
|
-
float rn(vec2
|
|
7
|
-
return mix(mix(rh(
|
|
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
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
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
|
-
|
|
62
|
-
return
|
|
61
|
+
material.customProgramCacheKey = () => 'road-earth';
|
|
62
|
+
return material;
|
|
63
63
|
}
|