@needle-tools/three-mesh-effects 0.2.3 → 0.3.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/CHANGELOG.md +25 -8
- package/README.md +68 -1
- package/SKILL.md +9 -1
- package/build/box-impostor-runtime.js +1298 -0
- package/build/box-impostor-runtime.js.map +7 -0
- package/build/deformation-runtime.js +30 -19
- package/build/deformation-runtime.js.map +3 -3
- package/build/hull-effects.js +60 -28
- package/build/hull-effects.js.map +3 -3
- package/build/impostor-runtime.js +152 -87
- package/build/impostor-runtime.js.map +3 -3
- package/build/index.js +4 -0
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display-settings.js +50 -0
- package/build/internal/box-impostor/box-impostor-display-settings.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-display.js +1005 -0
- package/build/internal/box-impostor/box-impostor-display.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js +15 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-faces.js +125 -0
- package/build/internal/box-impostor/box-impostor-faces.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-geometry.js +230 -0
- package/build/internal/box-impostor/box-impostor-geometry.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-material.js +964 -0
- package/build/internal/box-impostor/box-impostor-material.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-metadata.js +108 -0
- package/build/internal/box-impostor/box-impostor-metadata.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-projection.js +256 -0
- package/build/internal/box-impostor/box-impostor-projection.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-runtime.js +1252 -0
- package/build/internal/box-impostor/box-impostor-runtime.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js +21 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js.map +7 -0
- package/build/internal/deformation/cloth-surface.js +23 -17
- package/build/internal/deformation/cloth-surface.js.map +3 -3
- package/build/internal/deformation/pin-cloth.js +7 -2
- package/build/internal/deformation/pin-cloth.js.map +2 -2
- package/build/internal/deformation/rig-runtime.js +30 -19
- package/build/internal/deformation/rig-runtime.js.map +3 -3
- package/build/internal/impostor/impostor-node-material.js +152 -87
- package/build/internal/impostor/impostor-node-material.js.map +3 -3
- package/build/internal/rendering/hull-effect-runtime.js +59 -27
- package/build/internal/rendering/hull-effect-runtime.js.map +3 -3
- package/build/internal/rendering/wireframe.js +41 -9
- package/build/internal/rendering/wireframe.js.map +2 -2
- package/build/internal/rendering/wrap-preview.js +59 -27
- package/build/internal/rendering/wrap-preview.js.map +3 -3
- package/build/types/box-impostor/box-impostor-display-settings.d.ts +30 -0
- package/build/types/box-impostor/box-impostor-display-settings.js +1 -0
- package/build/types/box-impostor/box-impostor-display.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-display.js +1 -0
- package/build/types/box-impostor/box-impostor-face-axes.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-face-axes.js +1 -0
- package/build/types/box-impostor/box-impostor-faces.d.ts +11 -0
- package/build/types/box-impostor/box-impostor-faces.js +1 -0
- package/build/types/box-impostor/box-impostor-geometry.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-geometry.js +1 -0
- package/build/types/box-impostor/box-impostor-material.d.ts +10 -0
- package/build/types/box-impostor/box-impostor-material.js +1 -0
- package/build/types/box-impostor/box-impostor-metadata.d.ts +31 -0
- package/build/types/box-impostor/box-impostor-metadata.js +1 -0
- package/build/types/box-impostor/box-impostor-projection.d.ts +19 -0
- package/build/types/box-impostor/box-impostor-projection.js +1 -0
- package/build/types/box-impostor/box-impostor-runtime.d.ts +25 -0
- package/build/types/box-impostor/box-impostor-runtime.js +1 -0
- package/build/types/box-impostor/box-impostor-surface-search.d.ts +13 -0
- package/build/types/box-impostor/box-impostor-surface-search.js +1 -0
- package/build/types/deformation/cloth-surface.d.ts +1 -0
- package/build/types/deformation/pin-cloth.d.ts +1 -0
- package/build/types/public/box-impostor-runtime.d.ts +6 -0
- package/build/types/public/box-impostor-runtime.js +1 -0
- package/build/types/public/hull-effects.d.ts +1 -0
- package/build/types/public/index.d.ts +1 -1
- package/build/types/rendering/wireframe.d.ts +2 -2
- package/package.json +27 -6
- package/src/box-impostor/box-impostor-display-settings.js +54 -0
- package/src/box-impostor/box-impostor-display.js +38 -0
- package/src/box-impostor/box-impostor-face-axes.js +11 -0
- package/src/box-impostor/box-impostor-faces.js +118 -0
- package/src/box-impostor/box-impostor-geometry.js +140 -0
- package/src/box-impostor/box-impostor-material.js +721 -0
- package/src/box-impostor/box-impostor-metadata.js +122 -0
- package/src/box-impostor/box-impostor-projection.js +287 -0
- package/src/box-impostor/box-impostor-runtime.js +122 -0
- package/src/box-impostor/box-impostor-surface-search.js +11 -0
- package/src/deformation/cloth-surface.ts +28 -17
- package/src/deformation/pin-cloth.ts +9 -3
- package/src/impostor/impostor-node-material.js +177 -117
- package/src/public/box-impostor-runtime.js +14 -0
- package/src/public/hull-effects.js +1 -0
- package/src/public/index.js +5 -1
- package/src/rendering/wireframe.js +51 -13
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
Fn,
|
|
20
20
|
If,
|
|
21
21
|
Loop,
|
|
22
|
+
Break,
|
|
22
23
|
abs,
|
|
23
24
|
any,
|
|
24
25
|
bool,
|
|
@@ -918,57 +919,161 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
918
919
|
const rootFound = bool(false).toVar();
|
|
919
920
|
const rootLower = float(0).toVar();
|
|
920
921
|
const rootUpper = float(1).toVar();
|
|
921
|
-
const
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
922
|
+
const safeRay = vec3(
|
|
923
|
+
nonZeroSign(rayDirection.x),
|
|
924
|
+
nonZeroSign(rayDirection.y),
|
|
925
|
+
nonZeroSign(rayDirection.z)
|
|
926
|
+
).mul(max(abs(rayDirection), vec3(1e-7)));
|
|
927
|
+
const boundsGuard = radius.mul(2).div(interiorResolution);
|
|
928
|
+
const boxT0 = vec3(...descriptor.boundsMin).sub(boundsGuard).sub(planePosition).div(safeRay);
|
|
929
|
+
const boxT1 = vec3(...descriptor.boundsMax).add(boundsGuard).sub(planePosition).div(safeRay);
|
|
930
|
+
const boxLow = min(boxT0, boxT1), boxHigh = max(boxT0, boxT1);
|
|
931
|
+
const boxStart = max(boxLow.x, max(boxLow.y, boxLow.z));
|
|
932
|
+
const boxEnd = min(boxHigh.x, min(boxHigh.y, boxHigh.z));
|
|
933
|
+
const intersectsBounds = boxStart.lessThanEqual(boxEnd);
|
|
934
|
+
const captureDepthAt = (t) => radius.sub(
|
|
935
|
+
dot(planePosition.add(rayDirection.mul(t)), frameDirection)
|
|
936
|
+
).div(radius.mul(2));
|
|
937
|
+
const depth0 = captureDepthAt(boxStart), depth1 = captureDepthAt(boxEnd);
|
|
938
|
+
const uvDepthSlope = vec2(dot(rayDirection, right), dot(rayDirection, up)).mul(radius.mul(-2).div(safeRayPlaneDenominator)).div(bounds.zw.sub(bounds.xy));
|
|
939
|
+
const safeSlope = vec2(
|
|
940
|
+
nonZeroSign(uvDepthSlope.x),
|
|
941
|
+
nonZeroSign(uvDepthSlope.y)
|
|
942
|
+
).mul(max(abs(uvDepthSlope), vec2(1e-7)));
|
|
943
|
+
const uvStart = projectedFrameUv.sub(uvDepthSlope.mul(0.5));
|
|
944
|
+
const t0 = vec2(minimumFrameUv).sub(uvStart).div(safeSlope);
|
|
945
|
+
const t1 = vec2(maximumFrameUv).sub(uvStart).div(safeSlope);
|
|
946
|
+
const lower = min(t0, t1), upper = max(t0, t1);
|
|
947
|
+
const searchStart = max(min(depth0, depth1), max(0, max(lower.x, lower.y)));
|
|
948
|
+
const searchEnd = min(max(depth0, depth1), min(1, min(upper.x, upper.y)));
|
|
949
|
+
const searchRange = max(searchEnd.sub(searchStart), 1e-6);
|
|
950
|
+
const coarseStep = searchRange.div(coarseSearchSteps);
|
|
951
|
+
const validateRoot = () => {
|
|
952
|
+
If(rootSolved, () => {
|
|
953
|
+
const at = atlasUv(frame, frameUv);
|
|
954
|
+
const surface = reconstructPosition(frameUv, bounds, frameDirection, right, up, sampleDepth16(at));
|
|
955
|
+
const closest = planePosition.add(rayDirection.mul(dot(surface.sub(planePosition), rayDirection)));
|
|
956
|
+
const footprint2 = max(bounds.z.sub(bounds.x), bounds.w.sub(bounds.y)).div(interiorResolution);
|
|
957
|
+
const nearestPixel = floor(at.mul(atlasResolution));
|
|
958
|
+
const nearestDepth = loadDepth16(nearestPixel);
|
|
959
|
+
const depthJump = abs(sampleDepth16(at).sub(nearestDepth)).mul(radius).mul(2);
|
|
960
|
+
const discontinuity = bool(false).toVar();
|
|
961
|
+
If(depthJump.greaterThan(footprint2.mul(4)), () => {
|
|
962
|
+
const neighbor = (offset) => loadDepth16(nearestPixel.add(offset).clamp(
|
|
963
|
+
frame.mul(frameResolution),
|
|
964
|
+
frame.add(1).mul(frameResolution).sub(1)
|
|
965
|
+
));
|
|
966
|
+
const curvature = max(
|
|
967
|
+
abs(neighbor(vec2(-1, 0)).add(neighbor(vec2(1, 0))).sub(nearestDepth.mul(2))),
|
|
968
|
+
abs(neighbor(vec2(0, -1)).add(neighbor(vec2(0, 1))).sub(nearestDepth.mul(2)))
|
|
969
|
+
).mul(radius).mul(2);
|
|
970
|
+
discontinuity.assign(curvature.greaterThan(footprint2.mul(4)));
|
|
971
|
+
});
|
|
972
|
+
If(surface.sub(closest).length().greaterThan(footprint2.mul(4)).or(discontinuity).or(sampleCapturedAlpha(at).lessThan(reprojectionSurfaceCutoff)), () => {
|
|
973
|
+
rootFound.assign(false);
|
|
974
|
+
rootSolved.assign(false);
|
|
975
|
+
strictRootSolved.assign(false);
|
|
976
|
+
});
|
|
938
977
|
});
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
()
|
|
953
|
-
|
|
978
|
+
};
|
|
979
|
+
const refineRoot = () => {
|
|
980
|
+
If(rootFound, () => {
|
|
981
|
+
Loop(profile.depthSamples, () => {
|
|
982
|
+
const searchDepth = rootLower.add(rootUpper).mul(0.5);
|
|
983
|
+
const searchPlaneDepth = radius.sub(searchDepth.mul(radius).mul(2));
|
|
984
|
+
const searchRayPosition = planePosition.add(rayDirection.mul(
|
|
985
|
+
searchPlaneDepth.sub(dot(planePosition, frameDirection)).div(safeRayPlaneDenominator)
|
|
986
|
+
));
|
|
987
|
+
const searchUv = vec2(
|
|
988
|
+
dot(searchRayPosition, right),
|
|
989
|
+
dot(searchRayPosition, up)
|
|
990
|
+
).sub(bounds.xy).div(bounds.zw.sub(bounds.xy));
|
|
991
|
+
const searchOutOfBounds = any(searchUv.lessThan(vec2(minimumFrameUv))).or(any(searchUv.greaterThan(vec2(maximumFrameUv))));
|
|
992
|
+
const midpointIsUpper = bool(false).toVar();
|
|
993
|
+
If(searchOutOfBounds.not(), () => {
|
|
994
|
+
const searchAtlasUv = atlasUv(frame, searchUv);
|
|
995
|
+
const searchCoverage = sampleCapturedAlpha(searchAtlasUv);
|
|
996
|
+
const searchSurfaceDepth = sampleDepth16(searchAtlasUv);
|
|
997
|
+
midpointIsUpper.assign(
|
|
998
|
+
searchCoverage.greaterThanEqual(reprojectionSurfaceCutoff).and(searchDepth.greaterThanEqual(searchSurfaceDepth))
|
|
999
|
+
);
|
|
1000
|
+
});
|
|
1001
|
+
If(midpointIsUpper, () => {
|
|
954
1002
|
rootUpper.assign(searchDepth);
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
}
|
|
959
|
-
);
|
|
960
|
-
If(rootFound.not().and(hasSurface), () => {
|
|
961
|
-
previousHasSurface.assign(true);
|
|
962
|
-
previousSearchDepth.assign(searchDepth);
|
|
963
|
-
previousSurfaceDepth.assign(searchSurfaceDepth);
|
|
1003
|
+
});
|
|
1004
|
+
If(midpointIsUpper.not(), () => {
|
|
1005
|
+
rootLower.assign(searchDepth);
|
|
1006
|
+
});
|
|
964
1007
|
});
|
|
965
|
-
|
|
966
|
-
|
|
1008
|
+
const residualAt = (depth) => {
|
|
1009
|
+
const planeDepth = radius.sub(depth.mul(radius).mul(2));
|
|
1010
|
+
const position = planePosition.add(rayDirection.mul(
|
|
1011
|
+
planeDepth.sub(dot(planePosition, frameDirection)).div(safeRayPlaneDenominator)
|
|
1012
|
+
));
|
|
1013
|
+
const address = vec2(dot(position, right), dot(position, up)).sub(bounds.xy).div(bounds.zw.sub(bounds.xy));
|
|
1014
|
+
return depth.sub(sampleDepth16(atlasUv(frame, address)));
|
|
1015
|
+
};
|
|
1016
|
+
const lowResidual = residualAt(rootLower), highResidual = residualAt(rootUpper);
|
|
1017
|
+
const difference = lowResidual.sub(highResidual);
|
|
1018
|
+
const fraction = lowResidual.div(
|
|
1019
|
+
nonZeroSign(difference).mul(max(abs(difference), 1e-8))
|
|
1020
|
+
).clamp(0, 1);
|
|
1021
|
+
const rootDepth = mix(rootLower, rootUpper, fraction);
|
|
1022
|
+
const rootPlaneDepth = radius.sub(rootDepth.mul(radius).mul(2));
|
|
1023
|
+
const rootRayPosition = planePosition.add(rayDirection.mul(
|
|
1024
|
+
rootPlaneDepth.sub(dot(planePosition, frameDirection)).div(safeRayPlaneDenominator)
|
|
1025
|
+
));
|
|
1026
|
+
frameUv.assign(vec2(
|
|
1027
|
+
dot(rootRayPosition, right),
|
|
1028
|
+
dot(rootRayPosition, up)
|
|
1029
|
+
).sub(bounds.xy).div(bounds.zw.sub(bounds.xy)).clamp(
|
|
1030
|
+
minimumFrameUv,
|
|
1031
|
+
maximumFrameUv
|
|
1032
|
+
));
|
|
1033
|
+
});
|
|
1034
|
+
};
|
|
1035
|
+
const traceInterval = (steps, start = searchStart, end = searchEnd) => {
|
|
1036
|
+
const coarseStep2 = max(end.sub(start), 1e-6).div(float(steps));
|
|
1037
|
+
Loop({ start: 0, end: steps, type: "int" }, ({ i }) => {
|
|
1038
|
+
If(rootFound.or(intersectsBounds.not()).or(end.lessThan(start)), () => {
|
|
1039
|
+
Break();
|
|
1040
|
+
});
|
|
1041
|
+
const searchDepth = start.add(float(i).add(1).mul(coarseStep2));
|
|
1042
|
+
const searchPlaneDepth = radius.sub(searchDepth.mul(radius).mul(2));
|
|
1043
|
+
const searchRayPosition = planePosition.add(rayDirection.mul(
|
|
1044
|
+
searchPlaneDepth.sub(dot(planePosition, frameDirection)).div(safeRayPlaneDenominator)
|
|
1045
|
+
));
|
|
1046
|
+
const searchUv = vec2(
|
|
1047
|
+
dot(searchRayPosition, right),
|
|
1048
|
+
dot(searchRayPosition, up)
|
|
1049
|
+
).sub(bounds.xy).div(bounds.zw.sub(bounds.xy));
|
|
1050
|
+
const searchOutOfBounds = any(searchUv.lessThan(vec2(minimumFrameUv))).or(any(searchUv.greaterThan(vec2(maximumFrameUv))));
|
|
1051
|
+
If(searchOutOfBounds.not(), () => {
|
|
1052
|
+
const searchAtlasUv = atlasUv(frame, searchUv);
|
|
1053
|
+
const searchCoverage = sampleCapturedAlpha(searchAtlasUv);
|
|
1054
|
+
const hasSurface = searchCoverage.greaterThanEqual(reprojectionSurfaceCutoff);
|
|
1055
|
+
If(hasSurface, () => {
|
|
1056
|
+
const searchSurfaceDepth = sampleDepth16(searchAtlasUv);
|
|
1057
|
+
const depthDelta = searchDepth.sub(searchSurfaceDepth);
|
|
1058
|
+
If(
|
|
1059
|
+
rootFound.not().and(hasSurface).and(depthDelta.greaterThanEqual(0)),
|
|
1060
|
+
() => {
|
|
1061
|
+
rootLower.assign(max(searchDepth.sub(coarseStep2), 0));
|
|
1062
|
+
rootUpper.assign(searchDepth);
|
|
1063
|
+
rootFound.assign(true);
|
|
1064
|
+
rootSolved.assign(true);
|
|
1065
|
+
strictRootSolved.assign(true);
|
|
1066
|
+
refineRoot();
|
|
1067
|
+
if (features.boundedReprojection) validateRoot();
|
|
1068
|
+
}
|
|
1069
|
+
);
|
|
1070
|
+
});
|
|
967
1071
|
});
|
|
968
1072
|
});
|
|
969
|
-
}
|
|
970
|
-
|
|
971
|
-
|
|
1073
|
+
};
|
|
1074
|
+
traceInterval(int(coarseSearchSteps));
|
|
1075
|
+
If(rootFound.not().and(intersectsBounds), () => {
|
|
1076
|
+
const iterativeUv = projectedFrameUv.clamp(minimumFrameUv, maximumFrameUv).toVar();
|
|
972
1077
|
const iterativeDepth = sampleDepth16(atlasUv(frame, iterativeUv)).toVar();
|
|
973
1078
|
const iterationResidual = float(1).toVar();
|
|
974
1079
|
const iterationValid = bool(true).toVar();
|
|
@@ -1004,50 +1109,10 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
|
|
|
1004
1109
|
() => {
|
|
1005
1110
|
frameUv.assign(iterativeUv);
|
|
1006
1111
|
rootSolved.assign(true);
|
|
1112
|
+
if (features.boundedReprojection) validateRoot();
|
|
1007
1113
|
}
|
|
1008
1114
|
);
|
|
1009
1115
|
});
|
|
1010
|
-
If(rootFound, () => {
|
|
1011
|
-
Loop(profile.depthSamples, () => {
|
|
1012
|
-
const searchDepth = rootLower.add(rootUpper).mul(0.5);
|
|
1013
|
-
const searchPlaneDepth = radius.sub(searchDepth.mul(radius).mul(2));
|
|
1014
|
-
const searchRayPosition = planePosition.add(rayDirection.mul(
|
|
1015
|
-
searchPlaneDepth.sub(dot(planePosition, frameDirection)).div(safeRayPlaneDenominator)
|
|
1016
|
-
));
|
|
1017
|
-
const searchUv = vec2(
|
|
1018
|
-
dot(searchRayPosition, right),
|
|
1019
|
-
dot(searchRayPosition, up)
|
|
1020
|
-
).sub(bounds.xy).div(bounds.zw.sub(bounds.xy));
|
|
1021
|
-
const searchOutOfBounds = any(searchUv.lessThan(vec2(minimumFrameUv))).or(any(searchUv.greaterThan(vec2(maximumFrameUv))));
|
|
1022
|
-
const midpointIsUpper = bool(false).toVar();
|
|
1023
|
-
If(searchOutOfBounds.not(), () => {
|
|
1024
|
-
const searchAtlasUv = atlasUv(frame, searchUv);
|
|
1025
|
-
const searchCoverage = sampleCapturedAlpha(searchAtlasUv);
|
|
1026
|
-
const searchSurfaceDepth = sampleDepth16(searchAtlasUv);
|
|
1027
|
-
midpointIsUpper.assign(
|
|
1028
|
-
searchCoverage.greaterThanEqual(reprojectionSurfaceCutoff).and(searchDepth.greaterThanEqual(searchSurfaceDepth))
|
|
1029
|
-
);
|
|
1030
|
-
});
|
|
1031
|
-
If(midpointIsUpper, () => {
|
|
1032
|
-
rootUpper.assign(searchDepth);
|
|
1033
|
-
});
|
|
1034
|
-
If(midpointIsUpper.not(), () => {
|
|
1035
|
-
rootLower.assign(searchDepth);
|
|
1036
|
-
});
|
|
1037
|
-
});
|
|
1038
|
-
const rootDepth = rootLower.add(rootUpper).mul(0.5);
|
|
1039
|
-
const rootPlaneDepth = radius.sub(rootDepth.mul(radius).mul(2));
|
|
1040
|
-
const rootRayPosition = planePosition.add(rayDirection.mul(
|
|
1041
|
-
rootPlaneDepth.sub(dot(planePosition, frameDirection)).div(safeRayPlaneDenominator)
|
|
1042
|
-
));
|
|
1043
|
-
frameUv.assign(vec2(
|
|
1044
|
-
dot(rootRayPosition, right),
|
|
1045
|
-
dot(rootRayPosition, up)
|
|
1046
|
-
).sub(bounds.xy).div(bounds.zw.sub(bounds.xy)).clamp(
|
|
1047
|
-
minimumFrameUv,
|
|
1048
|
-
maximumFrameUv
|
|
1049
|
-
));
|
|
1050
|
-
});
|
|
1051
1116
|
}
|
|
1052
1117
|
const uvNode = atlasUv(frame, frameUv);
|
|
1053
1118
|
reconstructed.assign(reconstructPosition(
|