@needle-tools/three-mesh-effects 0.3.1 → 0.3.2
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/CHANGELOG.md +9 -0
- package/README.md +22 -6
- package/SKILL.md +7 -5
- package/build/box-impostor-runtime.js +212 -87
- package/build/box-impostor-runtime.js.map +4 -4
- package/build/impostor-runtime.js +112 -46
- package/build/impostor-runtime.js.map +4 -4
- package/build/index.js +4 -0
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display.js +178 -81
- package/build/internal/box-impostor/box-impostor-display.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-material.js +163 -71
- package/build/internal/box-impostor/box-impostor-material.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-projection.js +38 -18
- package/build/internal/box-impostor/box-impostor-projection.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-runtime.js +193 -76
- package/build/internal/box-impostor/box-impostor-runtime.js.map +4 -4
- package/build/internal/impostor/impostor-node-material.js +112 -46
- package/build/internal/impostor/impostor-node-material.js.map +4 -4
- package/build/internal/pixel-impostor/pixel-impostor-display.js +84 -38
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +4 -4
- package/build/internal/rendering/captured-surface-depth.js +35 -0
- package/build/internal/rendering/captured-surface-depth.js.map +7 -0
- package/build/internal/rendering/captured-surface-material.js +28 -0
- package/build/internal/rendering/captured-surface-material.js.map +7 -0
- package/build/internal/rendering/renderer-support.js +31 -0
- package/build/internal/rendering/renderer-support.js.map +7 -0
- package/build/pixel-impostor-runtime.js +84 -38
- package/build/pixel-impostor-runtime.js.map +4 -4
- package/build/types/box-impostor/box-impostor-display.d.ts +9 -1
- package/build/types/box-impostor/box-impostor-material.d.ts +4 -0
- package/build/types/box-impostor/box-impostor-runtime.d.ts +5 -11
- package/build/types/impostor/impostor-node-material.d.ts +2 -15
- package/build/types/rendering/captured-surface-depth.d.ts +5 -0
- package/build/types/rendering/captured-surface-depth.js +1 -0
- package/build/types/rendering/captured-surface-material.d.ts +8 -0
- package/build/types/rendering/captured-surface-material.js +1 -0
- package/build/types/rendering/renderer-support.d.ts +27 -0
- package/build/types/rendering/renderer-support.js +1 -0
- package/package.json +3 -3
- package/src/box-impostor/box-impostor-display.js +23 -11
- package/src/box-impostor/box-impostor-material.js +94 -44
- package/src/box-impostor/box-impostor-projection.js +3 -14
- package/src/box-impostor/box-impostor-runtime.js +6 -4
- package/src/impostor/impostor-node-material.js +11 -40
- package/src/pixel-impostor/pixel-impostor-display.js +5 -13
- package/src/public/index.js +5 -0
- package/src/rendering/captured-surface-depth.js +55 -0
- package/src/rendering/captured-surface-material.js +27 -0
- package/src/rendering/renderer-support.js +50 -0
|
@@ -1,5 +1,83 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
|
|
3
|
+
// src/rendering/renderer-support.js
|
|
4
|
+
import * as TSL from "three/tsl";
|
|
5
|
+
function rendererSupportsImpostorNodeMaterials(renderer) {
|
|
6
|
+
if (typeof Reflect.get(TSL, "struct") !== "function") return false;
|
|
7
|
+
return renderer?.isWebGPURenderer === true || renderer?.capabilities?.supportsNodeMaterials === true;
|
|
8
|
+
}
|
|
9
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
async function enableRendererNodeMaterials(renderer) {
|
|
11
|
+
if (rendererSupportsImpostorNodeMaterials(renderer) || !renderer?.isWebGLRenderer || !renderer.setNodesHandler || typeof Reflect.get(TSL, "struct") !== "function") return;
|
|
12
|
+
let setup = pending.get(renderer);
|
|
13
|
+
if (!setup) {
|
|
14
|
+
setup = import("three/addons/tsl/WebGLNodesHandler.js").then(({ WebGLNodesHandler }) => {
|
|
15
|
+
if (rendererSupportsImpostorNodeMaterials(renderer)) return;
|
|
16
|
+
renderer.setNodesHandler?.(new WebGLNodesHandler());
|
|
17
|
+
renderer.capabilities ??= {};
|
|
18
|
+
renderer.capabilities.supportsNodeMaterials = true;
|
|
19
|
+
}).catch((error) => {
|
|
20
|
+
pending.delete(renderer);
|
|
21
|
+
throw error;
|
|
22
|
+
});
|
|
23
|
+
pending.set(renderer, setup);
|
|
24
|
+
}
|
|
25
|
+
await setup;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// src/rendering/captured-surface-material.js
|
|
29
|
+
import { MeshStandardNodeMaterial } from "three/webgpu";
|
|
30
|
+
import { context, modelViewMatrix, modelWorldMatrix, vec4 } from "three/tsl";
|
|
31
|
+
var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
|
|
32
|
+
/** @type {import('three/webgpu').Node<'vec3'> | null} */
|
|
33
|
+
capturedPositionNode = null;
|
|
34
|
+
/**
|
|
35
|
+
* @override
|
|
36
|
+
* @param {import('three/webgpu').NodeBuilder} builder
|
|
37
|
+
*/
|
|
38
|
+
setupLighting(builder) {
|
|
39
|
+
const lighting = super.setupLighting(builder);
|
|
40
|
+
if (!this.capturedPositionNode) return lighting;
|
|
41
|
+
const world = modelWorldMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;
|
|
42
|
+
const view = modelViewMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;
|
|
43
|
+
return context(lighting, {
|
|
44
|
+
positionView: view,
|
|
45
|
+
positionWorld: world,
|
|
46
|
+
shadowPositionWorld: world
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
// src/rendering/captured-surface-depth.js
|
|
52
|
+
import {
|
|
53
|
+
Fn,
|
|
54
|
+
cameraFar,
|
|
55
|
+
cameraNear,
|
|
56
|
+
cameraProjectionMatrix,
|
|
57
|
+
modelViewMatrix as modelViewMatrix2,
|
|
58
|
+
vec4 as vec42,
|
|
59
|
+
viewZToLogarithmicDepth,
|
|
60
|
+
viewZToOrthographicDepth,
|
|
61
|
+
viewZToPerspectiveDepth,
|
|
62
|
+
viewZToReversedOrthographicDepth,
|
|
63
|
+
viewZToReversedPerspectiveDepth
|
|
64
|
+
} from "three/tsl";
|
|
65
|
+
function capturedSurfaceDepth(position, shadowBias = 0) {
|
|
66
|
+
return Fn(
|
|
67
|
+
(_, builder) => {
|
|
68
|
+
const z = modelViewMatrix2.mul(vec42(position, 1)).z.toVar("capturedSurfaceViewZ");
|
|
69
|
+
const reversed = builder.renderer.reversedDepthBuffer === true;
|
|
70
|
+
const perspective = cameraProjectionMatrix.mul(vec42(0, 0, 0, 1)).w.equal(0);
|
|
71
|
+
const perspectiveDepth = builder.renderer.logarithmicDepthBuffer === true ? viewZToLogarithmicDepth(z, cameraNear, cameraFar) : (reversed ? viewZToReversedPerspectiveDepth : viewZToPerspectiveDepth)(z, cameraNear, cameraFar);
|
|
72
|
+
const result = perspective.select(
|
|
73
|
+
perspectiveDepth,
|
|
74
|
+
(reversed ? viewZToReversedOrthographicDepth : viewZToOrthographicDepth)(z, cameraNear, cameraFar)
|
|
75
|
+
);
|
|
76
|
+
return shadowBias && "isShadowPassMaterial" in builder.material && builder.material.isShadowPassMaterial ? result.add(reversed ? -shadowBias : shadowBias).clamp(0, 1) : result;
|
|
77
|
+
}
|
|
78
|
+
)();
|
|
79
|
+
}
|
|
80
|
+
|
|
3
81
|
// src/impostor/impostor-node-material.js
|
|
4
82
|
import {
|
|
5
83
|
ClampToEdgeWrapping,
|
|
@@ -7,24 +85,22 @@ import {
|
|
|
7
85
|
GLSL3,
|
|
8
86
|
LinearFilter,
|
|
9
87
|
LinearMipmapLinearFilter,
|
|
10
|
-
MeshStandardNodeMaterial,
|
|
88
|
+
MeshStandardNodeMaterial as MeshStandardNodeMaterial2,
|
|
11
89
|
NoColorSpace,
|
|
12
90
|
SRGBColorSpace,
|
|
13
91
|
ShaderMaterial,
|
|
14
92
|
Vector3,
|
|
15
93
|
Vector4
|
|
16
94
|
} from "three/webgpu";
|
|
17
|
-
import * as
|
|
95
|
+
import * as TSL2 from "three/tsl";
|
|
18
96
|
import {
|
|
19
|
-
Fn,
|
|
97
|
+
Fn as Fn2,
|
|
20
98
|
If,
|
|
21
99
|
Loop,
|
|
22
100
|
Break,
|
|
23
101
|
abs,
|
|
24
102
|
any,
|
|
25
103
|
bool,
|
|
26
|
-
cameraFar,
|
|
27
|
-
cameraNear,
|
|
28
104
|
cameraPosition,
|
|
29
105
|
cameraWorldMatrix,
|
|
30
106
|
cross,
|
|
@@ -39,8 +115,7 @@ import {
|
|
|
39
115
|
max,
|
|
40
116
|
min,
|
|
41
117
|
mix,
|
|
42
|
-
|
|
43
|
-
modelWorldMatrix,
|
|
118
|
+
modelWorldMatrix as modelWorldMatrix2,
|
|
44
119
|
modelWorldMatrixInverse,
|
|
45
120
|
positionGeometry,
|
|
46
121
|
smoothstep,
|
|
@@ -51,9 +126,7 @@ import {
|
|
|
51
126
|
uniformArray,
|
|
52
127
|
vec2,
|
|
53
128
|
vec3,
|
|
54
|
-
vec4
|
|
55
|
-
viewZToOrthographicDepth,
|
|
56
|
-
viewZToPerspectiveDepth
|
|
129
|
+
vec4 as vec43
|
|
57
130
|
} from "three/tsl";
|
|
58
131
|
|
|
59
132
|
// src/impostor/impostor-metadata.js
|
|
@@ -183,7 +256,7 @@ function createImpostorViewBoundsTexture(descriptor) {
|
|
|
183
256
|
}
|
|
184
257
|
|
|
185
258
|
// src/impostor/impostor-node-material.js
|
|
186
|
-
var NAMED_STRUCT_FACTORY = Reflect.get(
|
|
259
|
+
var NAMED_STRUCT_FACTORY = Reflect.get(TSL2, "struct");
|
|
187
260
|
var RUNTIME_FEATURE_NAMES = (
|
|
188
261
|
/** @type {const} */
|
|
189
262
|
[
|
|
@@ -209,10 +282,6 @@ var IMPOSTOR_RUNTIME_SAMPLE_LIMITS = Object.freeze({
|
|
|
209
282
|
});
|
|
210
283
|
var IMPOSTOR_SHADOW_CASTER_DEPTH_BIAS = 2e-3;
|
|
211
284
|
var HEMISPHERE_HORIZON_TRANSITION_SINE = Math.sin(Math.PI / 180);
|
|
212
|
-
function rendererSupportsImpostorNodeMaterials(renderer) {
|
|
213
|
-
if (typeof NAMED_STRUCT_FACTORY !== "function") return false;
|
|
214
|
-
return renderer?.isWebGPURenderer === true || renderer?.capabilities?.supportsNodeMaterials === true;
|
|
215
|
-
}
|
|
216
285
|
function resolveImpostorRuntimeFeatures(descriptor, input = {}) {
|
|
217
286
|
const requested = {
|
|
218
287
|
...DEFAULT_IMPOSTOR_RUNTIME_FEATURES,
|
|
@@ -406,6 +475,7 @@ var NeedleImpostorLoaderPlugin = class {
|
|
|
406
475
|
}
|
|
407
476
|
/** @param {import('three/addons/loaders/GLTFLoader.js').GLTF} result */
|
|
408
477
|
async afterRoot(result) {
|
|
478
|
+
await enableRendererNodeMaterials(this.options.renderer);
|
|
409
479
|
const parser = (
|
|
410
480
|
/** @type {{
|
|
411
481
|
* json: {meshes?: Array<{primitives: Array<{extensions?: Record<string, unknown>}>}>},
|
|
@@ -421,7 +491,7 @@ var NeedleImpostorLoaderPlugin = class {
|
|
|
421
491
|
for (const root of roots) {
|
|
422
492
|
if (!root || visited.has(root)) continue;
|
|
423
493
|
visited.add(root);
|
|
424
|
-
const
|
|
494
|
+
const pending2 = [];
|
|
425
495
|
root.traverse((object) => {
|
|
426
496
|
if (!("isMesh" in object) || object.isMesh !== true) return;
|
|
427
497
|
const association = parser.associations.get(object);
|
|
@@ -440,7 +510,7 @@ var NeedleImpostorLoaderPlugin = class {
|
|
|
440
510
|
if (!rawTextures || typeof rawTextures !== "object") {
|
|
441
511
|
throw new Error("NEEDLE_mesh_impostor has no texture bindings.");
|
|
442
512
|
}
|
|
443
|
-
|
|
513
|
+
pending2.push((async () => {
|
|
444
514
|
const maps = (
|
|
445
515
|
/** @type {Record<string, import('three').Texture>} */
|
|
446
516
|
{}
|
|
@@ -463,7 +533,7 @@ var NeedleImpostorLoaderPlugin = class {
|
|
|
463
533
|
});
|
|
464
534
|
})());
|
|
465
535
|
});
|
|
466
|
-
await Promise.all(
|
|
536
|
+
await Promise.all(pending2);
|
|
467
537
|
upgraded += upgradeImpostorScene(
|
|
468
538
|
root,
|
|
469
539
|
bindings,
|
|
@@ -774,14 +844,14 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
774
844
|
const basisMember = (value, name) => value.get(name);
|
|
775
845
|
const frameMember = (value, name) => value.get(name);
|
|
776
846
|
const blendedMember = (value, name) => value.get(name);
|
|
777
|
-
const nonZeroSign =
|
|
847
|
+
const nonZeroSign = Fn2(([value]) => value.lessThan(0).select(float(-1), float(1)), "float");
|
|
778
848
|
const buildFrameBasis = ([direction]) => {
|
|
779
849
|
const referenceUp = abs(direction.y).greaterThan(0.999).select(vec3(0, 0, -1), vec3(0, 1, 0));
|
|
780
850
|
const right = referenceUp.cross(direction).normalize();
|
|
781
851
|
return FrameBasis(right, direction.cross(right).normalize());
|
|
782
852
|
};
|
|
783
|
-
const frameBasis =
|
|
784
|
-
const gridToDirection =
|
|
853
|
+
const frameBasis = Fn2(buildFrameBasis);
|
|
854
|
+
const gridToDirection = Fn2(([coordinate]) => {
|
|
785
855
|
const hemisphere = vec3(
|
|
786
856
|
coordinate.x.sub(coordinate.y),
|
|
787
857
|
float(1).sub(abs(coordinate.x.sub(coordinate.y))).sub(abs(float(-1).add(coordinate.x).add(coordinate.y))),
|
|
@@ -795,7 +865,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
795
865
|
const full = fullY.lessThan(0).select(vec3(foldedX, fullY, foldedZ), vec3(fullX, fullY, fullZ)).normalize();
|
|
796
866
|
return fullSphere ? full : hemisphere;
|
|
797
867
|
}, "vec3");
|
|
798
|
-
const directionToGrid =
|
|
868
|
+
const directionToGrid = Fn2(([inputDirection]) => {
|
|
799
869
|
const direction = inputDirection.normalize().toVar();
|
|
800
870
|
if (!fullSphere) {
|
|
801
871
|
direction.y.assign(max(direction.y, 1e-6));
|
|
@@ -809,7 +879,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
809
879
|
const full = direction.y.lessThan(0).select(folded, direction.xz);
|
|
810
880
|
return (fullSphere ? full : hemisphere).mul(0.5).add(0.5).clamp(0, 1);
|
|
811
881
|
}, "vec2");
|
|
812
|
-
const atlasUv =
|
|
882
|
+
const atlasUv = Fn2(([frame, frameUv]) => {
|
|
813
883
|
const interiorPixels = max(frameResolution.sub(padding.mul(2)), 1);
|
|
814
884
|
const interiorScale = interiorPixels.div(frameResolution);
|
|
815
885
|
const gutterUv = padding.div(interiorPixels);
|
|
@@ -819,7 +889,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
819
889
|
const halfTexel = float(0.5001).div(frameResolution);
|
|
820
890
|
return frame.add(insideCell.clamp(halfTexel, float(1).sub(halfTexel))).div(frames);
|
|
821
891
|
}, "vec2");
|
|
822
|
-
const decodeDepth16 =
|
|
892
|
+
const decodeDepth16 = Fn2(([packed]) => {
|
|
823
893
|
if (descriptor.compression?.depthEncoding === "lossless-geometry10-rgba") {
|
|
824
894
|
const bytes2 = floor(packed.rg.mul(255).add(0.5));
|
|
825
895
|
return bytes2.x.mul(4).add(floor(bytes2.y.div(85).add(0.5))).div(1023);
|
|
@@ -827,11 +897,11 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
827
897
|
const bytes = floor(packed.ba.mul(255).add(0.5));
|
|
828
898
|
return bytes.x.mul(256).add(bytes.y).div(65535);
|
|
829
899
|
}, "float");
|
|
830
|
-
const loadDepth16 =
|
|
900
|
+
const loadDepth16 = Fn2(([texel]) => decodeDepth16(textureLoad(
|
|
831
901
|
geometryAtlas,
|
|
832
902
|
ivec2(texel).clamp(ivec2(0), ivec2(atlasResolution.sub(1)))
|
|
833
903
|
)), "float");
|
|
834
|
-
const sampleDepth16 =
|
|
904
|
+
const sampleDepth16 = Fn2(([uvNode]) => {
|
|
835
905
|
const pixel = uvNode.mul(atlasResolution).sub(0.5);
|
|
836
906
|
const base = floor(pixel);
|
|
837
907
|
const fraction = fract(pixel);
|
|
@@ -847,7 +917,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
847
917
|
);
|
|
848
918
|
return mix(lower, upper, fraction.y);
|
|
849
919
|
}, "float");
|
|
850
|
-
const decodeOctahedral =
|
|
920
|
+
const decodeOctahedral = Fn2(([encoded]) => {
|
|
851
921
|
const f = encoded.mul(2).sub(1).toVar();
|
|
852
922
|
const value = vec3(f, float(1).sub(abs(f.x)).sub(abs(f.y))).toVar();
|
|
853
923
|
const folded = vec2(
|
|
@@ -859,15 +929,15 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
859
929
|
});
|
|
860
930
|
return value.normalize();
|
|
861
931
|
}, "vec3");
|
|
862
|
-
const reconstructPosition =
|
|
932
|
+
const reconstructPosition = Fn2(([frameUv, bounds, frameDirection, right, up, depthValue]) => {
|
|
863
933
|
const plane = mix(bounds.xy, bounds.zw, frameUv);
|
|
864
934
|
return right.mul(plane.x).add(up.mul(plane.y)).add(frameDirection.mul(radius.sub(depthValue.mul(radius).mul(2))));
|
|
865
935
|
}, "vec3");
|
|
866
|
-
const cameraLocal = modelWorldMatrixInverse.mul(
|
|
867
|
-
const cameraRightLocal = modelWorldMatrixInverse.mul(
|
|
868
|
-
const cameraUpLocal = modelWorldMatrixInverse.mul(
|
|
869
|
-
const cameraOutLocal = modelWorldMatrixInverse.mul(
|
|
870
|
-
const projectionCameraDirection =
|
|
936
|
+
const cameraLocal = modelWorldMatrixInverse.mul(vec43(cameraPosition, 1)).xyz;
|
|
937
|
+
const cameraRightLocal = modelWorldMatrixInverse.mul(vec43(cameraWorldMatrix[0].xyz, 0)).xyz.normalize();
|
|
938
|
+
const cameraUpLocal = modelWorldMatrixInverse.mul(vec43(cameraWorldMatrix[1].xyz, 0)).xyz.normalize();
|
|
939
|
+
const cameraOutLocal = modelWorldMatrixInverse.mul(vec43(cameraWorldMatrix[2].xyz, 0)).xyz.normalize();
|
|
940
|
+
const projectionCameraDirection = Fn2(([], builder) => builder.camera.isPerspectiveCamera ? cameraLocal.normalize() : cameraOutLocal, "vec3")();
|
|
871
941
|
const horizontalCamera = vec3(
|
|
872
942
|
projectionCameraDirection.x,
|
|
873
943
|
0,
|
|
@@ -1159,7 +1229,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
1159
1229
|
const colorUv = colorAtlasUv(uvNode);
|
|
1160
1230
|
const baseColor = sampleAtlas(baseColorAtlas, colorUv, mapLod(baseColorAtlas, colorUv), colorColumns);
|
|
1161
1231
|
const capturedAlpha = sampleCapturedAlpha(uvNode);
|
|
1162
|
-
const orm = compactLayout ?
|
|
1232
|
+
const orm = compactLayout ? vec43(geometrySample.b, shadingSample.b, shadingSample.a, 1) : ormAtlas ? sampleAtlas(ormAtlas, uvNode, mapLod(ormAtlas, uvNode)) : vec43(
|
|
1163
1233
|
descriptor.material.occlusion,
|
|
1164
1234
|
descriptor.material.roughness,
|
|
1165
1235
|
descriptor.material.metalness,
|
|
@@ -1172,7 +1242,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
1172
1242
|
// sampled color/alpha here and the frame weight below applied crop
|
|
1173
1243
|
// confidence twice; low-confidence crop-edge samples consequently
|
|
1174
1244
|
// rendered as black outlines instead of fading away.
|
|
1175
|
-
|
|
1245
|
+
vec43(baseColor.rgb, coverage),
|
|
1176
1246
|
capturedAlpha,
|
|
1177
1247
|
faceForwardNormal,
|
|
1178
1248
|
reconstructed,
|
|
@@ -1185,7 +1255,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
1185
1255
|
footprint
|
|
1186
1256
|
);
|
|
1187
1257
|
};
|
|
1188
|
-
return
|
|
1258
|
+
return Fn2(buildFrameSample);
|
|
1189
1259
|
};
|
|
1190
1260
|
const samplePlanarFrame = createFrameSampler(false);
|
|
1191
1261
|
const sampleReprojectedFrame = features.reprojection ? createFrameSampler(true) : null;
|
|
@@ -1369,15 +1439,10 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
1369
1439
|
transition
|
|
1370
1440
|
);
|
|
1371
1441
|
};
|
|
1372
|
-
const blendImpostor =
|
|
1442
|
+
const blendImpostor = Fn2(buildBlendedSample);
|
|
1373
1443
|
const sample = blendImpostor().toVar("impostorSample");
|
|
1374
|
-
const reconstructedWorldPosition =
|
|
1375
|
-
const
|
|
1376
|
-
const viewZ = modelViewMatrix.mul(vec4(localPosition, 1)).z;
|
|
1377
|
-
const resolvedDepth = builder.camera.isPerspectiveCamera ? viewZToPerspectiveDepth(viewZ, cameraNear, cameraFar) : viewZToOrthographicDepth(viewZ, cameraNear, cameraFar);
|
|
1378
|
-
return builder.material.isShadowPassMaterial ? min(1, resolvedDepth.add(IMPOSTOR_SHADOW_CASTER_DEPTH_BIAS)) : resolvedDepth;
|
|
1379
|
-
}, "float");
|
|
1380
|
-
const material = new MeshStandardNodeMaterial({
|
|
1444
|
+
const reconstructedWorldPosition = modelWorldMatrix2.mul(vec43(blendedMember(sample, "positionLocal"), 1)).xyz;
|
|
1445
|
+
const material = new CapturedSurfaceMaterial({
|
|
1381
1446
|
name: "Needle PBR impostor TSL",
|
|
1382
1447
|
side: DoubleSide,
|
|
1383
1448
|
transparent: false,
|
|
@@ -1397,7 +1462,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
1397
1462
|
const screenCoverage = screenDistanceCoverage.mul(mappingVisibility);
|
|
1398
1463
|
material.positionNode = displayBillboardPosition;
|
|
1399
1464
|
material.castShadowPositionNode = displayBillboardPosition;
|
|
1400
|
-
material.colorNode =
|
|
1465
|
+
material.colorNode = vec43(blendedMember(sample, "base").rgb, screenCoverage);
|
|
1401
1466
|
material.normalNode = transformNormalToView(blendedMember(sample, "normalLocal"));
|
|
1402
1467
|
material.aoNode = blendedMember(sample, "orm").r;
|
|
1403
1468
|
material.roughnessNode = blendedMember(sample, "orm").g;
|
|
@@ -1409,7 +1474,8 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
1409
1474
|
);
|
|
1410
1475
|
material.maskShadowNode = distanceCoverage.mul(mappingVisibility).greaterThanEqual(0.5);
|
|
1411
1476
|
material.alphaToCoverage = true;
|
|
1412
|
-
material.
|
|
1477
|
+
material.capturedPositionNode = blendedMember(sample, "positionLocal");
|
|
1478
|
+
material.depthNode = capturedSurfaceDepth(material.capturedPositionNode, IMPOSTOR_SHADOW_CASTER_DEPTH_BIAS);
|
|
1413
1479
|
material.receivedShadowPositionNode = reconstructedWorldPosition;
|
|
1414
1480
|
material.toneMapped = true;
|
|
1415
1481
|
material.userData.impostorShaderProfile = profile;
|