@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
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
transformNormalToView,
|
|
40
40
|
uint,
|
|
41
41
|
uniform,
|
|
42
|
+
uvec2,
|
|
42
43
|
uvec4,
|
|
43
44
|
uv,
|
|
44
45
|
vec2,
|
|
@@ -146,9 +147,16 @@ export function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
146
147
|
mod(index, dimensions[0]).add(0.5).div(dimensions[0]),
|
|
147
148
|
index.div(dimensions[0]).floor().add(0.5).div(dimensions[1]),
|
|
148
149
|
);
|
|
150
|
+
// The ray march reads these atlases texel by texel. Explicit integer loads
|
|
151
|
+
// avoid a nearest-filtered sample's shared size lookup: before r187, Three
|
|
152
|
+
// computes it once inside the first trace loop, after the loop's early exit,
|
|
153
|
+
// and later traces read it unassigned when that first ray leaves early.
|
|
154
|
+
// Same texel a nearest sample selects: floor(uv * the texture's own size).
|
|
155
|
+
const loadTexel = (/** @type {THREE.Texture} */ map, /** @type {import('three/webgpu').Node<'vec2'>} */ atlasUv) =>
|
|
156
|
+
texture(map).load(uvec2(atlasUv.mul(vec2(Number(map.image.width), Number(map.image.height))).floor()));
|
|
149
157
|
const sparseUint = (/** @type {import('three/webgpu').Node<'float'>} */ texel) => {
|
|
150
158
|
if (!indexAtlas) throw new Error('Sparse pixel impostor requires an index atlas');
|
|
151
|
-
const bytes = uvec4(
|
|
159
|
+
const bytes = uvec4(loadTexel(indexAtlas, linearTextureUv(texel, indexAtlasSize)).mul(255).round());
|
|
152
160
|
return bytes.x
|
|
153
161
|
.bitOr(bytes.y.shiftLeft(8))
|
|
154
162
|
.bitOr(bytes.z.shiftLeft(16))
|
|
@@ -190,14 +198,17 @@ export function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
190
198
|
// its invalid slab entry into the voxel traversal (which drew box lines).
|
|
191
199
|
const cell = exitDistance.greaterThanEqual(nearestDistance)
|
|
192
200
|
.select(gridPoint.floor(), vec3(-1)).toVar();
|
|
193
|
-
|
|
201
|
+
// Declared before the loop: Three r186 caches a sub-expression shared by
|
|
202
|
+
// the per-axis branches below into a variable assigned only inside the
|
|
203
|
+
// first branch that uses it, so the z step read a stale value.
|
|
204
|
+
const directionStep = step(0, gridVelocity).mul(2).sub(1).toVar();
|
|
194
205
|
const absoluteVelocity = abs(gridVelocity).max(1e-6);
|
|
195
206
|
const cellFraction = gridPoint.sub(cell);
|
|
196
207
|
const positiveAxis = step(0, gridVelocity);
|
|
197
208
|
const nextDistance = cellFraction.mul(vec3(1).sub(positiveAxis))
|
|
198
209
|
.add(vec3(1).sub(cellFraction).mul(positiveAxis));
|
|
199
210
|
const nextCrossing = nextDistance.div(absoluteVelocity).toVar();
|
|
200
|
-
const crossingDelta = vec3(1).div(absoluteVelocity);
|
|
211
|
+
const crossingDelta = vec3(1).div(absoluteVelocity).toVar();
|
|
201
212
|
// xyz is the reconstructed local hit; w is the linear cell index + 1.
|
|
202
213
|
// Keeping both in one vec4 avoids rebuilding the camera ray after traversal.
|
|
203
214
|
const result = vec4(0, 0, 0, 0).toVar();
|
|
@@ -222,7 +233,7 @@ export function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
222
233
|
atlasColumn.mul(planar).add(cell.x).add(0.5).div(atlasColumns * planar),
|
|
223
234
|
atlasRow.mul(planar).add(cell.z).add(0.5).div(atlasRows * planar),
|
|
224
235
|
);
|
|
225
|
-
cellOccupied =
|
|
236
|
+
cellOccupied = loadTexel(atlas, atlasUv).a.greaterThan(0.5);
|
|
226
237
|
}
|
|
227
238
|
If(cellOccupied, () => {
|
|
228
239
|
result.assign(vec4(
|
|
@@ -307,8 +318,8 @@ export function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
307
318
|
hitAtlasRow.mul(planar).add(hitCell.z).add(0.5).div(atlasRows * planar),
|
|
308
319
|
);
|
|
309
320
|
}
|
|
310
|
-
const baseSample =
|
|
311
|
-
const ormSample = ormAtlas ?
|
|
321
|
+
const baseSample = loadTexel(atlas, hitAtlasUv);
|
|
322
|
+
const ormSample = ormAtlas ? loadTexel(ormAtlas, hitAtlasUv) : vec4(1, 1, 0, 1);
|
|
312
323
|
const hitPosition = hit.xyz;
|
|
313
324
|
const hitToCamera = modelWorldMatrixInverse.mul(vec4(cameraPosition, 1)).xyz.sub(hitPosition);
|
|
314
325
|
const faceSign = step(0, hitToCamera).mul(2).sub(1);
|
|
@@ -333,7 +344,7 @@ export function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
333
344
|
.select(vec3(faceSign.x, 0, 0), yFaceScore.greaterThanEqual(zFaceScore)
|
|
334
345
|
.select(vec3(0, faceSign.y, 0), vec3(0, 0, faceSign.z)));
|
|
335
346
|
const sampledNormal = normalAtlas
|
|
336
|
-
?
|
|
347
|
+
? loadTexel(normalAtlas, hitAtlasUv).xyz.mul(2).sub(1)
|
|
337
348
|
: geometricNormal;
|
|
338
349
|
const bakedNormal = sampledNormal.dot(sampledNormal).greaterThan(1e-8)
|
|
339
350
|
.select(sampledNormal.normalize(), geometricNormal);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Reports whether WebGLRenderer from a three revision can keep many node
|
|
5
|
+
* materials alive. Before r187 every uniform block holds one of a few binding
|
|
6
|
+
* points until its material is disposed, so node materials stop drawing after
|
|
7
|
+
* about a dozen. The Needle fork backports the fix from 0.186.2-alpha.2.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} revision three's `REVISION`, such as `'187'` or `'186.2-alpha.2'`
|
|
10
|
+
*/
|
|
11
|
+
export function classicWebGLSupportsNodeMaterials(revision) {
|
|
12
|
+
const fork = /^186\.2-alpha\.(\d+)$/.exec(revision);
|
|
13
|
+
if (fork) return Number(fork[1]) >= 2;
|
|
14
|
+
return Number.parseInt(revision, 10) >= 187;
|
|
15
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @ts-check
|
|
2
|
+
import {REVISION} from 'three';
|
|
2
3
|
import * as TSL from 'three/tsl';
|
|
4
|
+
import {classicWebGLSupportsNodeMaterials} from './classic-webgl-support.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @typedef {object} ImpostorRenderer
|
|
@@ -36,6 +38,9 @@ export async function enableRendererNodeMaterials(renderer) {
|
|
|
36
38
|
if (!setup) {
|
|
37
39
|
setup = import('three/addons/tsl/WebGLNodesHandler.js').then(({WebGLNodesHandler}) => {
|
|
38
40
|
if (rendererSupportsImpostorNodeMaterials(renderer)) return;
|
|
41
|
+
if (!classicWebGLSupportsNodeMaterials(REVISION)) {
|
|
42
|
+
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.`);
|
|
43
|
+
}
|
|
39
44
|
renderer.setNodesHandler?.(new WebGLNodesHandler());
|
|
40
45
|
renderer.capabilities ??= {};
|
|
41
46
|
renderer.capabilities.supportsNodeMaterials = true;
|