@needle-tools/three-mesh-effects 0.3.2 → 0.3.4
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 +2 -1
- package/build/box-impostor-runtime.js +13 -0
- package/build/box-impostor-runtime.js.map +3 -3
- package/build/deformation-runtime.js +11 -9
- package/build/deformation-runtime.js.map +2 -2
- package/build/impostor-runtime.js +42 -6
- package/build/impostor-runtime.js.map +3 -3
- package/build/internal/box-impostor/box-impostor-runtime.js +13 -0
- package/build/internal/box-impostor/box-impostor-runtime.js.map +3 -3
- package/build/internal/deformation/pin-ik.js +11 -9
- package/build/internal/deformation/pin-ik.js.map +2 -2
- package/build/internal/deformation/pin-wiggle.js.map +1 -1
- package/build/internal/deformation/rig-extension.js.map +1 -1
- package/build/internal/deformation/rig-runtime.js +11 -9
- package/build/internal/deformation/rig-runtime.js.map +2 -2
- package/build/internal/impostor/impostor-node-material.js +42 -6
- package/build/internal/impostor/impostor-node-material.js.map +3 -3
- package/build/internal/pixel-impostor/pixel-impostor-display.js +9 -7
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +2 -2
- package/build/internal/rendering/classic-webgl-support.js +12 -0
- package/build/internal/rendering/classic-webgl-support.js.map +7 -0
- package/build/internal/rendering/renderer-support.js +13 -0
- package/build/internal/rendering/renderer-support.js.map +3 -3
- package/build/pixel-impostor-runtime.js +9 -7
- package/build/pixel-impostor-runtime.js.map +2 -2
- package/build/types/rendering/classic-webgl-support.d.ts +9 -0
- package/build/types/rendering/classic-webgl-support.js +1 -0
- package/package.json +2 -2
- package/src/deformation/pin-ik.ts +13 -9
- package/src/impostor/impostor-node-material.js +34 -6
- package/src/pixel-impostor/pixel-impostor-display.js +18 -7
- package/src/rendering/classic-webgl-support.js +15 -0
- package/src/rendering/renderer-support.js +5 -0
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
|
|
3
3
|
// src/rendering/renderer-support.js
|
|
4
|
+
import { REVISION } from "three";
|
|
4
5
|
import * as TSL from "three/tsl";
|
|
6
|
+
|
|
7
|
+
// src/rendering/classic-webgl-support.js
|
|
8
|
+
function classicWebGLSupportsNodeMaterials(revision) {
|
|
9
|
+
const fork = /^186\.2-alpha\.(\d+)$/.exec(revision);
|
|
10
|
+
if (fork) return Number(fork[1]) >= 2;
|
|
11
|
+
return Number.parseInt(revision, 10) >= 187;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// src/rendering/renderer-support.js
|
|
5
15
|
function rendererSupportsImpostorNodeMaterials(renderer) {
|
|
6
16
|
if (typeof Reflect.get(TSL, "struct") !== "function") return false;
|
|
7
17
|
return renderer?.isWebGPURenderer === true || renderer?.capabilities?.supportsNodeMaterials === true;
|
|
@@ -13,6 +23,9 @@ async function enableRendererNodeMaterials(renderer) {
|
|
|
13
23
|
if (!setup) {
|
|
14
24
|
setup = import("three/addons/tsl/WebGLNodesHandler.js").then(({ WebGLNodesHandler }) => {
|
|
15
25
|
if (rendererSupportsImpostorNodeMaterials(renderer)) return;
|
|
26
|
+
if (!classicWebGLSupportsNodeMaterials(REVISION)) {
|
|
27
|
+
console.warn(`Mesh Effects: WebGLRenderer from three r${REVISION} stops drawing node materials after about a dozen are in use. Use three r187 or later, or WebGPURenderer.`);
|
|
28
|
+
}
|
|
16
29
|
renderer.setNodesHandler?.(new WebGLNodesHandler());
|
|
17
30
|
renderer.capabilities ??= {};
|
|
18
31
|
renderer.capabilities.supportsNodeMaterials = true;
|
|
@@ -766,7 +779,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
766
779
|
const padding = float(descriptor.padding);
|
|
767
780
|
const radius = float(descriptor.radius);
|
|
768
781
|
const captureAlphaCutoff = float(descriptor.captureAlphaCutoff);
|
|
769
|
-
const reprojectionSurfaceCutoff = descriptor.coverageEncoding === "sdf-base-alpha" ? float(0.5) : min(captureAlphaCutoff,
|
|
782
|
+
const reprojectionSurfaceCutoff = descriptor.coverageEncoding === "sdf-base-alpha" ? float(0.5) : float(Math.min(Number(descriptor.captureAlphaCutoff), 0.25));
|
|
770
783
|
const blendCutoff = float((1 - profile.blendZone) * 0.5);
|
|
771
784
|
const coarseSearchSteps = profile.raySamples;
|
|
772
785
|
const fullSphere = descriptor.mapping === "full";
|
|
@@ -962,12 +975,11 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
962
975
|
const displayBillboardPosition = cameraRightLocal.mul(positionGeometry.x).add(cameraUpLocal.mul(positionGeometry.y));
|
|
963
976
|
const planeLocal = samplingBillboardPosition.toVarying("vImpostorPlaneLocal");
|
|
964
977
|
const createFrameSampler = (withReprojection) => {
|
|
965
|
-
const buildFrameSample = ([frame, planePosition, rayDirection]) => {
|
|
978
|
+
const buildFrameSample = ([frame, planePosition, rayDirection, bounds]) => {
|
|
966
979
|
const frameDirection = singleView ? singleCaptureDirection : gridToDirection(frame.div(frames.sub(1)));
|
|
967
980
|
const basis = frameBasis(frameDirection);
|
|
968
981
|
const right = basisMember(basis, "right");
|
|
969
982
|
const up = basisMember(basis, "up");
|
|
970
|
-
const bounds = viewBounds.element(int(frame.y.mul(frames).add(frame.x)));
|
|
971
983
|
const rayPlaneDenominator = dot(rayDirection, frameDirection);
|
|
972
984
|
const safeRayPlaneDenominator = nonZeroSign(rayPlaneDenominator).mul(max(abs(rayPlaneDenominator), 0.05));
|
|
973
985
|
const framePlanePosition = planePosition.sub(rayDirection.mul(
|
|
@@ -1255,11 +1267,35 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
1255
1267
|
footprint
|
|
1256
1268
|
);
|
|
1257
1269
|
};
|
|
1258
|
-
|
|
1270
|
+
const functions = /* @__PURE__ */ new WeakMap();
|
|
1271
|
+
return (builder) => {
|
|
1272
|
+
let sampleFrame = functions.get(builder);
|
|
1273
|
+
if (!sampleFrame) {
|
|
1274
|
+
sampleFrame = Fn2(buildFrameSample).setLayout({
|
|
1275
|
+
name: withReprojection ? "sampleReprojectedImpostorFrame" : "samplePlanarImpostorFrame",
|
|
1276
|
+
type: "ImpostorFrameSample",
|
|
1277
|
+
inputs: [
|
|
1278
|
+
{ name: "frame", type: "vec2" },
|
|
1279
|
+
{ name: "planePosition", type: "vec3" },
|
|
1280
|
+
{ name: "rayDirection", type: "vec3" },
|
|
1281
|
+
{ name: "bounds", type: "vec4" }
|
|
1282
|
+
]
|
|
1283
|
+
});
|
|
1284
|
+
functions.set(builder, sampleFrame);
|
|
1285
|
+
}
|
|
1286
|
+
return (frame, planePosition, rayDirection) => sampleFrame(
|
|
1287
|
+
frame,
|
|
1288
|
+
planePosition,
|
|
1289
|
+
rayDirection,
|
|
1290
|
+
viewBounds.element(int(frame.y.mul(frames).add(frame.x)))
|
|
1291
|
+
);
|
|
1292
|
+
};
|
|
1259
1293
|
};
|
|
1260
|
-
const
|
|
1261
|
-
const
|
|
1294
|
+
const planarFrameSamplers = createFrameSampler(false);
|
|
1295
|
+
const reprojectedFrameSamplers = features.reprojection ? createFrameSampler(true) : null;
|
|
1262
1296
|
const buildBlendedSample = ([], builder) => {
|
|
1297
|
+
const samplePlanarFrame = planarFrameSamplers(builder);
|
|
1298
|
+
const sampleReprojectedFrame = reprojectedFrameSamplers ? reprojectedFrameSamplers(builder) : null;
|
|
1263
1299
|
const samplingCameraLocal = samplingCamera;
|
|
1264
1300
|
const centerViewDirection = samplingCameraLocal.normalize();
|
|
1265
1301
|
const usePerspectiveCorrection = features.perspectiveCorrection && builder.camera.isPerspectiveCamera;
|