@needle-tools/three-mesh-effects 0.3.3 → 0.3.5
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 +3 -2
- package/build/box-impostor-runtime.js +27 -2
- 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 +41 -19
- package/build/impostor-runtime.js.map +3 -3
- package/build/internal/box-impostor/box-impostor-display.js +10 -2
- package/build/internal/box-impostor/box-impostor-display.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-faces.js.map +1 -1
- package/build/internal/box-impostor/box-impostor-geometry.js +4 -0
- package/build/internal/box-impostor/box-impostor-geometry.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-material.js +10 -2
- package/build/internal/box-impostor/box-impostor-material.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-metadata.js +4 -0
- package/build/internal/box-impostor/box-impostor-metadata.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-projection.js.map +1 -1
- package/build/internal/box-impostor/box-impostor-runtime.js +27 -2
- 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 +41 -19
- 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/box-impostor/box-impostor-metadata.d.ts +3 -1
- 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/box-impostor/box-impostor-material.js +10 -2
- package/src/box-impostor/box-impostor-metadata.js +5 -1
- package/src/deformation/pin-ik.ts +13 -9
- package/src/impostor/impostor-node-material.js +31 -15
- 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
|
@@ -92,6 +92,7 @@ import {
|
|
|
92
92
|
transformNormalToView,
|
|
93
93
|
uint,
|
|
94
94
|
uniform,
|
|
95
|
+
uvec2,
|
|
95
96
|
uvec4,
|
|
96
97
|
uv,
|
|
97
98
|
vec2,
|
|
@@ -183,9 +184,10 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
183
184
|
mod(index, dimensions2[0]).add(0.5).div(dimensions2[0]),
|
|
184
185
|
index.div(dimensions2[0]).floor().add(0.5).div(dimensions2[1])
|
|
185
186
|
);
|
|
187
|
+
const loadTexel = (map, atlasUv) => texture(map).load(uvec2(atlasUv.mul(vec2(Number(map.image.width), Number(map.image.height))).floor()));
|
|
186
188
|
const sparseUint = (texel) => {
|
|
187
189
|
if (!indexAtlas) throw new Error("Sparse pixel impostor requires an index atlas");
|
|
188
|
-
const bytes = uvec4(
|
|
190
|
+
const bytes = uvec4(loadTexel(indexAtlas, linearTextureUv(texel, indexAtlasSize)).mul(255).round());
|
|
189
191
|
return bytes.x.bitOr(bytes.y.shiftLeft(8)).bitOr(bytes.z.shiftLeft(16)).bitOr(bytes.w.shiftLeft(24));
|
|
190
192
|
};
|
|
191
193
|
const traceVolumeNode = Fn2(([sampleOffset]) => {
|
|
@@ -215,13 +217,13 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
215
217
|
const gridVelocity = rayDirection.div(sizeNode).mul(volumeDimensions);
|
|
216
218
|
const gridPoint = entry.add(raycastOffsetNode).div(sizeNode).add(0.5).mul(volumeDimensions).add(gridVelocity.mul(minimumCellSize * 1e-3));
|
|
217
219
|
const cell = exitDistance.greaterThanEqual(nearestDistance).select(gridPoint.floor(), vec3(-1)).toVar();
|
|
218
|
-
const directionStep = step(0, gridVelocity).mul(2).sub(1);
|
|
220
|
+
const directionStep = step(0, gridVelocity).mul(2).sub(1).toVar();
|
|
219
221
|
const absoluteVelocity = abs(gridVelocity).max(1e-6);
|
|
220
222
|
const cellFraction = gridPoint.sub(cell);
|
|
221
223
|
const positiveAxis = step(0, gridVelocity);
|
|
222
224
|
const nextDistance = cellFraction.mul(vec3(1).sub(positiveAxis)).add(vec3(1).sub(cellFraction).mul(positiveAxis));
|
|
223
225
|
const nextCrossing = nextDistance.div(absoluteVelocity).toVar();
|
|
224
|
-
const crossingDelta = vec3(1).div(absoluteVelocity);
|
|
226
|
+
const crossingDelta = vec3(1).div(absoluteVelocity).toVar();
|
|
225
227
|
const result = vec43(0, 0, 0, 0).toVar();
|
|
226
228
|
const travelled = nearestDistance.toVar();
|
|
227
229
|
Loop(maximumSteps, () => {
|
|
@@ -243,7 +245,7 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
243
245
|
atlasColumn.mul(planar).add(cell.x).add(0.5).div(atlasColumns * planar),
|
|
244
246
|
atlasRow.mul(planar).add(cell.z).add(0.5).div(atlasRows * planar)
|
|
245
247
|
);
|
|
246
|
-
cellOccupied =
|
|
248
|
+
cellOccupied = loadTexel(atlas, atlasUv).a.greaterThan(0.5);
|
|
247
249
|
}
|
|
248
250
|
If(cellOccupied, () => {
|
|
249
251
|
result.assign(vec43(
|
|
@@ -314,8 +316,8 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
314
316
|
hitAtlasRow.mul(planar).add(hitCell.z).add(0.5).div(atlasRows * planar)
|
|
315
317
|
);
|
|
316
318
|
}
|
|
317
|
-
const baseSample =
|
|
318
|
-
const ormSample = ormAtlas ?
|
|
319
|
+
const baseSample = loadTexel(atlas, hitAtlasUv);
|
|
320
|
+
const ormSample = ormAtlas ? loadTexel(ormAtlas, hitAtlasUv) : vec43(1, 1, 0, 1);
|
|
319
321
|
const hitPosition = hit.xyz;
|
|
320
322
|
const hitToCamera = modelWorldMatrixInverse.mul(vec43(cameraPosition, 1)).xyz.sub(hitPosition);
|
|
321
323
|
const faceSign = step(0, hitToCamera).mul(2).sub(1);
|
|
@@ -331,7 +333,7 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
331
333
|
const yFaceScore = absoluteCellDelta.y.greaterThanEqual(boundaryDistance.sub(1e-4)).select(faceDirection.y, -1);
|
|
332
334
|
const zFaceScore = absoluteCellDelta.z.greaterThanEqual(boundaryDistance.sub(1e-4)).select(faceDirection.z, -1);
|
|
333
335
|
const geometricNormal = xFaceScore.greaterThanEqual(yFaceScore).and(xFaceScore.greaterThanEqual(zFaceScore)).select(vec3(faceSign.x, 0, 0), yFaceScore.greaterThanEqual(zFaceScore).select(vec3(0, faceSign.y, 0), vec3(0, 0, faceSign.z)));
|
|
334
|
-
const sampledNormal = normalAtlas ?
|
|
336
|
+
const sampledNormal = normalAtlas ? loadTexel(normalAtlas, hitAtlasUv).xyz.mul(2).sub(1) : geometricNormal;
|
|
335
337
|
const bakedNormal = sampledNormal.dot(sampledNormal).greaterThan(1e-8).select(sampledNormal.normalize(), geometricNormal);
|
|
336
338
|
const projectedNormal = bakedNormal.dot(geometricNormal).lessThan(0).select(bakedNormal.negate(), bakedNormal);
|
|
337
339
|
const shadingNormal = mix(geometricNormal, projectedNormal, projectedNormalMix).normalize();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/rendering/captured-surface-material.js", "../../../src/rendering/captured-surface-depth.js", "../../../src/pixel-impostor/pixel-impostor-display.js"],
|
|
4
|
-
"sourcesContent": ["// @ts-check\nimport { MeshStandardNodeMaterial } from 'three/webgpu';\nimport { context, modelViewMatrix, modelWorldMatrix, vec4 } from 'three/tsl';\n\n/** Light reconstructed surfaces at their hit position, not the carrier face.\n * View directions stay on the same ray; local lights also need the hit distance.\n */\nexport class CapturedSurfaceMaterial extends MeshStandardNodeMaterial {\n /** @type {import('three/webgpu').Node<'vec3'> | null} */\n capturedPositionNode = null;\n\n /**\n * @override\n * @param {import('three/webgpu').NodeBuilder} builder\n */\n setupLighting(builder) {\n const lighting = super.setupLighting(builder);\n if (!this.capturedPositionNode) return lighting;\n const world = modelWorldMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;\n const view = modelViewMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;\n return context(lighting, {\n positionView: view,\n positionWorld: world,\n shadowPositionWorld: world,\n });\n }\n}\n", "// @ts-check\nimport {\n Fn,\n cameraFar,\n cameraNear,\n cameraProjectionMatrix,\n modelViewMatrix,\n vec4,\n viewZToLogarithmicDepth,\n viewZToOrthographicDepth,\n viewZToPerspectiveDepth,\n viewZToReversedOrthographicDepth,\n viewZToReversedPerspectiveDepth,\n} from 'three/tsl';\n\n/** Match the renderer's depth convention after reconstructing a local hit.\n * @param {import('three/webgpu').Node<'vec3'>} position\n * @param {number} [shadowBias]\n */\nexport function capturedSurfaceDepth(position, shadowBias = 0) {\n return Fn(\n (\n /** @type {unknown} */ _,\n /** @type {import('three/webgpu').NodeBuilder} */ builder,\n ) => {\n // Resolve the shared hit before either projection branch consumes it.\n const z = modelViewMatrix\n .mul(vec4(position, 1))\n .z.toVar('capturedSurfaceViewZ');\n const reversed = builder.renderer.reversedDepthBuffer === true;\n // One material can alternate between a perspective view and orthographic\n // shadow cameras without a new pipeline; select using the active projection.\n const perspective = cameraProjectionMatrix\n .mul(vec4(0, 0, 0, 1))\n .w.equal(0);\n const perspectiveDepth =\n builder.renderer.logarithmicDepthBuffer === true\n ? viewZToLogarithmicDepth(z, cameraNear, cameraFar)\n : (reversed\n ? viewZToReversedPerspectiveDepth\n : viewZToPerspectiveDepth)(z, cameraNear, cameraFar);\n const result = perspective.select(\n perspectiveDepth,\n (reversed\n ? viewZToReversedOrthographicDepth\n : viewZToOrthographicDepth)(z, cameraNear, cameraFar),\n );\n return shadowBias &&\n 'isShadowPassMaterial' in builder.material &&\n builder.material.isShadowPassMaterial\n ? result.add(reversed ? -shadowBias : shadowBias).clamp(0, 1)\n : result;\n },\n )();\n}\n", "// @ts-check\nimport { CapturedSurfaceMaterial } from '../rendering/captured-surface-material.js';\nimport { capturedSurfaceDepth } from '../rendering/captured-surface-depth.js';\nimport * as THREE from 'three';\nimport { MeshBasicNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';\nimport {\n Break,\n Fn,\n If,\n Loop,\n abs,\n attribute,\n cameraProjectionMatrix,\n cameraProjectionMatrixInverse,\n cameraPosition,\n cameraWorldMatrix,\n ceil,\n clamp,\n countOneBits,\n float,\n fwidth,\n getViewPosition,\n max,\n min,\n mix,\n modelViewMatrix,\n modelWorldMatrix,\n modelWorldMatrixInverse,\n mod,\n normalMap as normalMapNode,\n normalView,\n smoothstep,\n step,\n sRGBTransferEOTF,\n positionLocal,\n screenCoordinate,\n screenSize,\n texture,\n transformNormalToView,\n uint,\n uniform,\n uvec4,\n uv,\n vec2,\n vec3,\n vec4,\n vertexColor,\n} from 'three/tsl';\n\n/**\n * Builds the shader alternative to the exported voxel shell. The box supplies\n * interpolated ray-entry positions; the fragment node walks the packed solid\n * volume and returns the first occupied cell in a single draw/pass.\n *\n * @param {THREE.Object3D} asset\n * @param {THREE.Box3} bounds\n * @param {Record<string, unknown>} descriptor\n */\nexport function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {\n const binding = descriptor;\n descriptor = binding.descriptor && typeof binding.descriptor === 'object'\n ? /** @type {Record<string, unknown>} */ (binding.descriptor)\n : descriptor;\n const dimensions = Array.isArray(descriptor.dimensions)\n ? descriptor.dimensions.map(Number)\n : [];\n const planar = Math.round(dimensions[0] ?? 0);\n const layers = Math.round(dimensions[1] ?? 0);\n if (!(planar > 0) || !(layers > 0) || Math.round(dimensions[2] ?? 0) !== planar) return null;\n const atlasTextures = /** @type {THREE.Texture[]} */ ([]);\n if (binding.atlas instanceof THREE.Texture) atlasTextures.push(binding.atlas);\n asset.traverse((object) => {\n if (atlasTextures.length > 0 || !(object instanceof THREE.Mesh)) return;\n const materials = Array.isArray(object.material) ? object.material : [object.material];\n for (const material of materials) {\n const map = /** @type {THREE.MeshBasicMaterial} */ (material).map;\n if (map) { atlasTextures.push(map); break; }\n }\n });\n const atlas = atlasTextures[0];\n if (!atlas) return null;\n atlas.magFilter = THREE.NearestFilter;\n atlas.minFilter = THREE.NearestFilter;\n atlas.generateMipmaps = false;\n atlas.needsUpdate = true;\n const normalAtlas = binding.normalAtlas instanceof THREE.Texture ? binding.normalAtlas : null;\n const ormAtlas = binding.ormAtlas instanceof THREE.Texture ? binding.ormAtlas : null;\n const indexAtlas = binding.indexAtlas instanceof THREE.Texture ? binding.indexAtlas : null;\n const sparse = descriptor.version === 3 && descriptor.storage === 'sparse';\n if (sparse && !indexAtlas) return null;\n for (const map of [normalAtlas, ormAtlas, indexAtlas]) {\n if (!map) continue;\n map.colorSpace = THREE.NoColorSpace;\n map.magFilter = THREE.NearestFilter;\n map.minFilter = THREE.NearestFilter;\n map.generateMipmaps = false;\n map.needsUpdate = true;\n }\n\n const authoredMin = Array.isArray(descriptor.volumeMin) ? descriptor.volumeMin.map(Number) : null;\n const authoredSize = Array.isArray(descriptor.volumeSize) ? descriptor.volumeSize.map(Number) : null;\n const size = authoredSize?.length === 3 && authoredSize.every((value) => value > 0)\n ? new THREE.Vector3().fromArray(authoredSize)\n : bounds.getSize(new THREE.Vector3());\n const center = authoredMin?.length === 3\n ? new THREE.Vector3().fromArray(authoredMin).addScaledVector(size, 0.5)\n : bounds.getCenter(new THREE.Vector3());\n const authoredOccupiedMin = Array.isArray(descriptor.occupiedMin)\n ? descriptor.occupiedMin.map(Number) : null;\n const authoredOccupiedSize = Array.isArray(descriptor.occupiedSize)\n ? descriptor.occupiedSize.map(Number) : null;\n const raycastSize = authoredOccupiedSize?.length === 3\n && authoredOccupiedSize.every((value) => value > 0)\n ? new THREE.Vector3().fromArray(authoredOccupiedSize)\n : size.clone();\n const raycastCenter = authoredOccupiedMin?.length === 3\n ? new THREE.Vector3().fromArray(authoredOccupiedMin).addScaledVector(raycastSize, 0.5)\n : center.clone();\n const raycastOffset = raycastCenter.clone().sub(center);\n const atlasColumns = Math.max(1, Math.round(Number(descriptor.atlasColumns) || Math.ceil(Math.sqrt(layers))));\n const atlasRows = Math.max(1, Math.round(Number(descriptor.atlasRows) || Math.ceil(layers / atlasColumns)));\n const surfaceAtlasSize = Array.isArray(descriptor.surfaceAtlasSize)\n ? descriptor.surfaceAtlasSize.map(Number) : [atlas.image.width, atlas.image.height];\n const indexAtlasSize = Array.isArray(descriptor.indexAtlasSize)\n ? descriptor.indexAtlasSize.map(Number) : [1, 1];\n const sizeNode = uniform(size.clone());\n const raycastHalfSize = uniform(raycastSize.clone().multiplyScalar(0.5));\n const raycastOffsetNode = uniform(raycastOffset);\n const screenPixelSize = uniform(1);\n const splatPixelSize = uniform(5);\n const splatScale = uniform(1);\n const projectedNormalMix = uniform(1);\n const unlitMix = uniform(0);\n const snapMode = uniform(0);\n const viewportSize = uniform(new THREE.Vector2(1, 1));\n const dpr = uniform(1);\n const volumeDimensions = vec3(planar, layers, planar);\n const voxelHalfExtents = vec3(\n size.x / planar * 0.5,\n size.y / layers * 0.5,\n size.z / planar * 0.5,\n );\n const minimumCellSize = Math.min(size.x / planar, size.y / layers, size.z / planar);\n const maximumSteps = planar * 2 + layers + 3;\n const linearTextureUv = (/** @type {import('three/webgpu').Node<'float'>} */ index, /** @type {number[]} */ dimensions) => vec2(\n mod(index, dimensions[0]).add(0.5).div(dimensions[0]),\n index.div(dimensions[0]).floor().add(0.5).div(dimensions[1]),\n );\n const sparseUint = (/** @type {import('three/webgpu').Node<'float'>} */ texel) => {\n if (!indexAtlas) throw new Error('Sparse pixel impostor requires an index atlas');\n const bytes = uvec4(texture(indexAtlas, linearTextureUv(texel, indexAtlasSize)).mul(255).round());\n return bytes.x\n .bitOr(bytes.y.shiftLeft(8))\n .bitOr(bytes.z.shiftLeft(16))\n .bitOr(bytes.w.shiftLeft(24));\n };\n // @ts-ignore -- TSL's Fn declaration exposes NodeBuilder instead of its shader parameters.\n const traceVolumeNode = Fn(([sampleOffset]) => {\n // Reconstructing the ray from the snapped screen coordinate avoids the\n // derivative discontinuity along the two triangles of each box face.\n const rasterPixelSize = screenPixelSize.mul(dpr);\n const sampleCoordinate = screenCoordinate.div(rasterPixelSize).floor()\n .mul(rasterPixelSize).add(\n rasterPixelSize.mul(vec2(0.5).add(sampleOffset)),\n );\n const sampleUv = sampleCoordinate.div(screenSize);\n const nearView = getViewPosition(sampleUv, float(0), cameraProjectionMatrixInverse);\n const farView = getViewPosition(sampleUv, float(1), cameraProjectionMatrixInverse);\n const nearWorld = cameraWorldMatrix.mul(vec4(nearView, 1));\n const farWorld = cameraWorldMatrix.mul(vec4(farView, 1));\n const rayOrigin = modelWorldMatrixInverse.mul(nearWorld).xyz;\n const rayFar = modelWorldMatrixInverse.mul(farWorld).xyz;\n const rayDirection = rayFar.sub(rayOrigin).normalize();\n const distanceA = raycastHalfSize.negate().sub(rayOrigin).div(rayDirection);\n const distanceB = raycastHalfSize.sub(rayOrigin).div(rayDirection);\n const nearestDistance = max(\n max(min(distanceA.x, distanceB.x), min(distanceA.y, distanceB.y)),\n min(distanceA.z, distanceB.z),\n ).max(0);\n const exitDistance = min(\n min(max(distanceA.x, distanceB.x), max(distanceA.y, distanceB.y)),\n max(distanceA.z, distanceB.z),\n );\n const entry = rayOrigin.add(rayDirection.mul(nearestDistance));\n const gridVelocity = rayDirection.div(sizeNode).mul(volumeDimensions);\n const gridPoint = entry.add(raycastOffsetNode).div(sizeNode).add(0.5).mul(volumeDimensions)\n .add(gridVelocity.mul(minimumCellSize * 0.001));\n // Rasterization only guarantees that the center ray intersects the proxy.\n // An AA sub-sample can lie outside it; reject that ray instead of feeding\n // its invalid slab entry into the voxel traversal (which drew box lines).\n const cell = exitDistance.greaterThanEqual(nearestDistance)\n .select(gridPoint.floor(), vec3(-1)).toVar();\n const directionStep = step(0, gridVelocity).mul(2).sub(1);\n const absoluteVelocity = abs(gridVelocity).max(1e-6);\n const cellFraction = gridPoint.sub(cell);\n const positiveAxis = step(0, gridVelocity);\n const nextDistance = cellFraction.mul(vec3(1).sub(positiveAxis))\n .add(vec3(1).sub(cellFraction).mul(positiveAxis));\n const nextCrossing = nextDistance.div(absoluteVelocity).toVar();\n const crossingDelta = vec3(1).div(absoluteVelocity);\n // xyz is the reconstructed local hit; w is the linear cell index + 1.\n // Keeping both in one vec4 avoids rebuilding the camera ray after traversal.\n const result = vec4(0, 0, 0, 0).toVar();\n const travelled = nearestDistance.toVar();\n Loop(maximumSteps, () => {\n const outside = cell.x.lessThan(0).or(cell.y.lessThan(0)).or(cell.z.lessThan(0))\n .or(cell.x.greaterThanEqual(planar)).or(cell.y.greaterThanEqual(layers)).or(cell.z.greaterThanEqual(planar));\n If(outside, () => { Break(); });\n // Keep every operation in the TSL graph. JavaScript arithmetic coerces\n // node expressions to NaN, which then produces invalid WGSL (`NaN.0`).\n const linearCell = cell.x.add(cell.z.add(cell.y.mul(planar)).mul(planar));\n let cellOccupied;\n if (sparse) {\n const wordIndex = linearCell.div(32).floor();\n const word = sparseUint(wordIndex.mul(2));\n const bit = uint(mod(linearCell, 32));\n cellOccupied = word.shiftRight(bit).bitAnd(1).equal(1);\n } else {\n const atlasColumn = mod(cell.y, atlasColumns);\n const atlasRow = cell.y.div(atlasColumns).floor();\n const atlasUv = vec2(\n atlasColumn.mul(planar).add(cell.x).add(0.5).div(atlasColumns * planar),\n atlasRow.mul(planar).add(cell.z).add(0.5).div(atlasRows * planar),\n );\n cellOccupied = texture(atlas, atlasUv).a.greaterThan(0.5);\n }\n If(cellOccupied, () => {\n result.assign(vec4(\n rayOrigin.add(rayDirection.mul(travelled)),\n linearCell.add(1),\n ));\n Break();\n });\n const nearestCrossing = min(nextCrossing.x, min(nextCrossing.y, nextCrossing.z));\n travelled.assign(nearestDistance.add(nearestCrossing));\n // Independent branches intentionally advance two or three axes for an\n // exact edge/corner crossing; that avoids revisiting zero-width cells.\n If(nextCrossing.x.lessThanEqual(nearestCrossing.add(1e-6)), () => {\n cell.x.addAssign(directionStep.x);\n nextCrossing.x.addAssign(crossingDelta.x);\n });\n If(nextCrossing.y.lessThanEqual(nearestCrossing.add(1e-6)), () => {\n cell.y.addAssign(directionStep.y);\n nextCrossing.y.addAssign(crossingDelta.y);\n });\n If(nextCrossing.z.lessThanEqual(nearestCrossing.add(1e-6)), () => {\n cell.z.addAssign(directionStep.z);\n nextCrossing.z.addAssign(crossingDelta.z);\n });\n });\n return result;\n });\n const traceVolume = /** @type {(sampleOffset: import('three/webgpu').Node<'vec2'>) => import('three/webgpu').Node<'vec4'>} */ (\n /** @type {unknown} */ (traceVolumeNode)\n );\n const createRaycastMaterial = (\n /** @type {boolean} */ antialias,\n /** @type {boolean} */ pbr,\n ) => {\n // Baked material maps are a cached graph variant, not a uniform branch:\n // the plain lit graph retains lighting and projected normals but contains\n // no voxel ORM sampling or AO/roughness/metalness nodes.\n const centerHit = traceVolume(vec2(0));\n const occupied = centerHit.w.greaterThan(0);\n /** @type {import('three/webgpu').Node<'float'>} */\n let coverage = float(1);\n if (antialias) {\n // This JavaScript branch specializes the TSL graph: the fast material\n // contains one DDA trace, while the AA material contains five. There is\n // no runtime AA branch or dormant extra tracing in the fast pipeline.\n const sampleHits = [\n traceVolume(vec2(-0.125, -0.375)),\n traceVolume(vec2(0.375, -0.125)),\n traceVolume(vec2(-0.375, 0.125)),\n traceVolume(vec2(0.125, 0.375)),\n ];\n const sampleOccupancy = sampleHits.map((sampleHit) => sampleHit.w.greaterThan(0));\n coverage = sampleOccupancy[0].select(1, 0)\n .add(sampleOccupancy[1].select(1, 0))\n .add(sampleOccupancy[2].select(1, 0))\n .add(sampleOccupancy[3].select(1, 0))\n .mul(0.25).mul(occupied.select(1, 0));\n }\n const hit = centerHit.toVar(antialias ? 'pixelImpostorAaHit' : 'pixelImpostorFastHit');\n const linearHitCell = hit.w.sub(1).max(0);\n const hitLayer = linearHitCell.div(planar * planar).floor();\n const hitSliceCell = mod(linearHitCell, planar * planar);\n const hitCell = vec3(mod(hitSliceCell, planar), hitLayer, hitSliceCell.div(planar).floor());\n let hitAtlasUv;\n if (sparse) {\n const wordIndex = linearHitCell.div(32).floor();\n const word = sparseUint(wordIndex.mul(2));\n const prefixRank = sparseUint(wordIndex.mul(2).add(1));\n const bit = uint(mod(linearHitCell, 32));\n const precedingMask = uint(1).shiftLeft(bit).sub(1);\n // Three's nodeProxyIntent returns a typed TSL node; @types/three\n // currently declares the bare BitcountNode class instead. A uint input\n // produces uint output (WGSL countOneBits preserves its input type).\n const precedingCount = /** @type {ReturnType<typeof countOneBits> & import('three/webgpu').Node<'uint'>} */ (countOneBits(word.bitAnd(precedingMask)));\n const record = prefixRank.add(precedingCount);\n hitAtlasUv = linearTextureUv(float(record), surfaceAtlasSize);\n } else {\n const hitAtlasColumn = mod(hitCell.y, atlasColumns);\n const hitAtlasRow = hitCell.y.div(atlasColumns).floor();\n hitAtlasUv = vec2(\n hitAtlasColumn.mul(planar).add(hitCell.x).add(0.5).div(atlasColumns * planar),\n hitAtlasRow.mul(planar).add(hitCell.z).add(0.5).div(atlasRows * planar),\n );\n }\n const baseSample = texture(atlas, hitAtlasUv);\n const ormSample = ormAtlas ? texture(ormAtlas, hitAtlasUv) : vec4(1, 1, 0, 1);\n const hitPosition = hit.xyz;\n const hitToCamera = modelWorldMatrixInverse.mul(vec4(cameraPosition, 1)).xyz.sub(hitPosition);\n const faceSign = step(0, hitToCamera).mul(2).sub(1);\n const hitCellCenter = hitCell.add(0.5).div(volumeDimensions).sub(0.5)\n .mul(sizeNode).sub(raycastOffsetNode);\n const cellDelta = hitPosition.sub(hitCellCenter).div(sizeNode).mul(volumeDimensions);\n const absoluteCellDelta = cellDelta.abs();\n const boundaryDistance = max(absoluteCellDelta.x,\n max(absoluteCellDelta.y, absoluteCellDelta.z));\n const faceDirection = hitToCamera.abs().normalize();\n // At an edge/corner more than one face is a valid entry face. Floating\n // error used to make the largest coordinate flicker between them. Treat\n // near-ties as the same boundary and choose the most camera-facing face.\n const xFaceScore = absoluteCellDelta.x.greaterThanEqual(boundaryDistance.sub(1e-4))\n .select(faceDirection.x, -1);\n const yFaceScore = absoluteCellDelta.y.greaterThanEqual(boundaryDistance.sub(1e-4))\n .select(faceDirection.y, -1);\n const zFaceScore = absoluteCellDelta.z.greaterThanEqual(boundaryDistance.sub(1e-4))\n .select(faceDirection.z, -1);\n const geometricNormal = xFaceScore.greaterThanEqual(yFaceScore)\n .and(xFaceScore.greaterThanEqual(zFaceScore))\n .select(vec3(faceSign.x, 0, 0), yFaceScore.greaterThanEqual(zFaceScore)\n .select(vec3(0, faceSign.y, 0), vec3(0, 0, faceSign.z)));\n const sampledNormal = normalAtlas\n ? texture(normalAtlas, hitAtlasUv).xyz.mul(2).sub(1)\n : geometricNormal;\n const bakedNormal = sampledNormal.dot(sampledNormal).greaterThan(1e-8)\n .select(sampledNormal.normalize(), geometricNormal);\n const projectedNormal = bakedNormal.dot(geometricNormal).lessThan(0)\n .select(bakedNormal.negate(), bakedNormal);\n const shadingNormal = mix(geometricNormal, projectedNormal, projectedNormalMix).normalize();\n const materialName = `Pixel impostor \u00B7 volume raycast \u00B7 ${antialias ? 'AA' : 'fast'} \u00B7 ${pbr ? 'PBR maps' : 'plain lit'}`;\n const material = new CapturedSurfaceMaterial({\n name: materialName,\n side: THREE.FrontSide,\n depthTest: true,\n depthWrite: true,\n });\n material.colorNode = vec4(baseSample.rgb.mul(float(1).sub(unlitMix)),\n antialias ? baseSample.a.mul(coverage) : baseSample.a);\n material.emissiveNode = baseSample.rgb.mul(pbr ? ormSample.r : 1).mul(unlitMix);\n material.normalNode = transformNormalToView(shadingNormal);\n if (pbr) {\n material.aoNode = ormSample.r;\n material.roughnessNode = ormSample.g.max(0.04);\n material.metalnessNode = ormSample.b;\n }\n material.receivedShadowPositionNode = modelWorldMatrix.mul(vec4(hitPosition, 1)).xyz;\n material.maskNode = occupied.and(\n baseSample.a.greaterThan(Number(descriptor.alphaCutoff) || 0.5),\n );\n material.maskShadowNode = antialias ? coverage.greaterThanEqual(0.5) : occupied;\n material.alphaToCoverage = antialias;\n material.capturedPositionNode = hitPosition;\n material.depthNode = capturedSurfaceDepth(hitPosition);\n material.toneMapped = true;\n material.userData.screenPixelSize = screenPixelSize;\n material.userData.pixelImpostorRaycastAntialias = antialias;\n material.userData.pixelImpostorRaySamples = antialias ? 5 : 1;\n material.userData.pixelImpostorPbr = pbr;\n return material;\n };\n const raycastMaterials = {\n mapped: {\n fast: createRaycastMaterial(false, true),\n antialias: createRaycastMaterial(true, true),\n },\n plain: {\n fast: createRaycastMaterial(false, false),\n antialias: createRaycastMaterial(true, false),\n },\n };\n const raycast = new THREE.Mesh(new THREE.BoxGeometry(\n raycastSize.x,\n raycastSize.y,\n raycastSize.z,\n ), raycastMaterials.mapped.antialias);\n raycast.name = 'Pixel impostor \u00B7 volume raycast';\n raycast.position.copy(raycastCenter);\n raycast.castShadow = true;\n raycast.receiveShadow = true;\n raycast.userData.previewPixelImpostor = true;\n raycast.userData.pixelImpostorDisplayMode = 'raycast';\n raycast.userData.pixelImpostorAlternateMaterials = [\n ...Object.values(raycastMaterials.mapped),\n ...Object.values(raycastMaterials.plain),\n ];\n\n const surfacePoints = binding.surfacePoints instanceof THREE.BufferAttribute\n || binding.surfacePoints instanceof THREE.InterleavedBufferAttribute\n ? binding.surfacePoints : null;\n // Keep the portable face-culled shell as one ordinary draw. Each vertex is\n // marked with its source voxel center, so every corner from one voxel gets\n // exactly the same screen-space displacement and the cell remains coherent.\n /** @type {THREE.Mesh | null} */\n let shell = null;\n asset.traverse((object) => {\n if (!shell && object instanceof THREE.Mesh\n && (object.geometry.getAttribute('_voxel_center') || surfacePoints)) {\n shell = object;\n }\n });\n if (!shell) return null;\n const voxelShell = /** @type {THREE.Mesh} */ (shell);\n const geometryBaseSample = texture(atlas, uv());\n const geometryOrmSample = ormAtlas ? texture(ormAtlas, uv()) : vec4(1, 1, 0, 1);\n const geometryNormal = attribute('normal', /** @type {const} */ ('vec3')).normalize();\n const geometryProjectedNormal = normalAtlas\n ? texture(normalAtlas, uv()).xyz.mul(2).sub(1).normalize()\n : geometryNormal;\n const geometryAlignedNormal = geometryProjectedNormal.dot(geometryNormal).lessThan(0)\n .select(geometryProjectedNormal.negate(), geometryProjectedNormal);\n const createGeometryMaterial = (/** @type {boolean} */ pbr) => {\n const material = new MeshStandardNodeMaterial({\n name: `Pixel impostor \u00B7 voxel geometry \u00B7 ${pbr ? 'mapped' : 'plain'}`,\n side: THREE.FrontSide,\n depthTest: true,\n depthWrite: true,\n });\n material.colorNode = vec4(geometryBaseSample.rgb.mul(float(1).sub(unlitMix)),\n geometryBaseSample.a);\n material.emissiveNode = geometryBaseSample.rgb.mul(pbr ? geometryOrmSample.r : 1).mul(unlitMix);\n material.normalNode = transformNormalToView(\n mix(geometryNormal, geometryAlignedNormal, projectedNormalMix).normalize(),\n );\n if (pbr) {\n material.aoNode = geometryOrmSample.r;\n material.roughnessNode = geometryOrmSample.g.max(0.04);\n material.metalnessNode = geometryOrmSample.b;\n }\n material.maskNode = geometryBaseSample.a.greaterThan(\n Number(descriptor.alphaCutoff) || 0.5,\n );\n material.toneMapped = true;\n material.userData.pixelImpostorPbr = pbr;\n return material;\n };\n const geometryMaterials = {\n mapped: createGeometryMaterial(true),\n plain: createGeometryMaterial(false),\n };\n const previousGeometryMaterial = voxelShell.material;\n voxelShell.material = geometryMaterials.mapped;\n voxelShell.userData.pixelImpostorAlternateMaterials = Object.values(geometryMaterials);\n const skinnedSplats = voxelShell instanceof THREE.SkinnedMesh;\n // Sparse instancing deliberately omits the carrier mesh's per-vertex data.\n // Animated exports retain that data, so use their dense carriers and let\n // standard Three.js skinning deform each voxel center before screen-aligning\n // its quad. Static sparse files keep the smaller instanced path.\n const useSurfacePoints = surfacePoints && !skinnedSplats;\n let splatGeometry = skinnedSplats ? voxelShell.geometry.clone() : voxelShell.geometry;\n if (skinnedSplats) {\n const centers = voxelShell.geometry.getAttribute('_voxel_center');\n if (!centers) throw new Error('Animated voxel splats require retained voxel centers.');\n splatGeometry.setAttribute('position', centers.clone());\n }\n if (useSurfacePoints) {\n const count = surfacePoints.count;\n const coordinates = new Float32Array(count * 3);\n const records = new Float32Array(count);\n for (let index = 0; index < count; index++) {\n coordinates[index * 3] = surfacePoints.getX(index);\n coordinates[index * 3 + 1] = surfacePoints.getY(index);\n coordinates[index * 3 + 2] = surfacePoints.getZ(index);\n records[index] = index;\n }\n const instancedGeometry = new THREE.InstancedBufferGeometry();\n instancedGeometry.instanceCount = count;\n splatGeometry = instancedGeometry;\n splatGeometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(12), 3));\n splatGeometry.setAttribute('_voxel_corner', new THREE.BufferAttribute(new Float32Array([\n -1, -1, 1, -1, 1, 1, -1, 1,\n ]), 2));\n splatGeometry.setAttribute('_voxel_coord', new THREE.InstancedBufferAttribute(coordinates, 3));\n splatGeometry.setAttribute('_voxel_record', new THREE.InstancedBufferAttribute(records, 1));\n splatGeometry.setIndex([0, 1, 2, 0, 2, 3]);\n splatGeometry.boundingBox = voxelShell.geometry.boundingBox?.clone() ?? bounds.clone();\n splatGeometry.boundingSphere = voxelShell.geometry.boundingSphere?.clone()\n ?? splatGeometry.boundingBox.getBoundingSphere(new THREE.Sphere());\n }\n const voxelCoordinate = attribute('_voxel_coord', /** @type {const} */ ('vec3'));\n const voxelCenter = skinnedSplats\n ? positionLocal\n : useSurfacePoints\n ? voxelCoordinate.add(0.5).div(volumeDimensions)\n .sub(0.5).mul(sizeNode).add(uniform(center.clone()))\n : attribute('_voxel_center', /** @type {const} */ ('vec3'));\n const voxelCorner = attribute('_voxel_corner', /** @type {const} */ ('vec2'));\n const centerView = modelViewMatrix.mul(vec4(voxelCenter, 1));\n const centerClip = cameraProjectionMatrix.mul(centerView);\n const centerNdc = centerClip.xy.div(centerClip.w);\n const cssViewport = viewportSize;\n const centerCss = centerNdc.mul(0.5).add(0.5).mul(cssViewport);\n const projectVoxelPoint = (/** @type {import('three/webgpu').Node<'vec3'>} */ point) => {\n const projected = cameraProjectionMatrix.mul(modelViewMatrix.mul(vec4(point, 1)));\n return projected.xy.div(projected.w).mul(0.5).add(0.5).mul(cssViewport);\n };\n const projectedX = projectVoxelPoint(voxelCenter.add(vec3(voxelHalfExtents.x, 0, 0)));\n const projectedY = projectVoxelPoint(voxelCenter.add(vec3(0, voxelHalfExtents.y, 0)));\n const projectedZ = projectVoxelPoint(voxelCenter.add(vec3(0, 0, voxelHalfExtents.z)));\n const projectedHalfFootprint = projectedX.sub(centerCss).abs()\n .add(projectedY.sub(centerCss).abs())\n .add(projectedZ.sub(centerCss).abs());\n const projectedVoxelSize = max(projectedHalfFootprint.x, projectedHalfFootprint.y).mul(2);\n const projectedCellSpan = projectedVoxelSize.div(splatPixelSize);\n // `floor()` in this vertex-node graph causes pathological WebGPU pipeline\n // compilation on current Chrome/Metal. Inputs are positive, so this is the\n // same nearest-integer quantization with half values biased downward.\n const nearestCellSpan = ceil(projectedCellSpan.sub(0.5)).max(1);\n const singleCell = snapMode.equal(1);\n const centerOnly = snapMode.equal(2);\n const cellSpan = singleCell.select(1, nearestCellSpan);\n const cellCenter = centerCss.div(splatPixelSize).floor()\n .mul(splatPixelSize).add(splatPixelSize.mul(0.5));\n const gridIntersection = centerCss.div(splatPixelSize).add(0.5).floor().mul(splatPixelSize);\n const oddCellSpan = mod(cellSpan, 2);\n const parityAlignedCenter = oddCellSpan.greaterThan(0.5).select(cellCenter, gridIntersection);\n const snappedCss = centerOnly.select(cellCenter, parityAlignedCenter);\n const splatSize = cellSpan.mul(splatPixelSize).mul(splatScale);\n // The original exposed face is only a carrier. Replace its four positions\n // with a camera-facing square centered on the voxel. A small overlap avoids\n // pinholes between neighboring screen pixels under perspective projection.\n const quadCss = snappedCss.add(voxelCorner.mul(splatSize.mul(0.52)));\n const quadNdc = quadCss.div(cssViewport).mul(2).sub(1);\n const quadClip = vec4(quadNdc.mul(centerClip.w), centerClip.z, centerClip.w);\n const quadViewHomogeneous = cameraProjectionMatrixInverse.mul(quadClip);\n const quadView = quadViewHomogeneous.xyz.div(quadViewHomogeneous.w);\n const quadWorld = cameraWorldMatrix.mul(vec4(quadView, 1));\n const quadLocalHomogeneous = modelWorldMatrixInverse.mul(quadWorld);\n const quadLocal = quadLocalHomogeneous.xyz.div(quadLocalHomogeneous.w);\n\n const splatUv = useSurfacePoints\n ? linearTextureUv(attribute('_voxel_record', /** @type {const} */ ('float')), surfaceAtlasSize)\n : uv();\n const splatColor = texture(atlas, splatUv);\n const splatOrm = ormAtlas ? texture(ormAtlas, splatUv) : vec4(1, 1, 0, 1);\n const cameraLocal = modelWorldMatrixInverse.mul(vec4(cameraPosition, 1)).xyz;\n const viewDirection = cameraLocal.sub(voxelCenter).normalize();\n const splatBakedNormal = normalAtlas\n ? texture(normalAtlas, splatUv).xyz.mul(2).sub(1).normalize()\n : viewDirection;\n const splatProjectedNormal = splatBakedNormal.dot(viewDirection).lessThan(0)\n .select(splatBakedNormal.negate(), splatBakedNormal);\n const splatShadingNormal = mix(\n viewDirection,\n splatProjectedNormal,\n projectedNormalMix,\n ).normalize();\n let splatMask;\n if (useSurfacePoints) {\n splatMask = splatColor.a.greaterThan(0.5);\n } else {\n // Legacy v3 files duplicate a voxel once per exposed face. Select exactly\n // one carrier before rotating it into the screen-aligned square.\n const voxelFaceMask = float(attribute('_voxel_face_mask', /** @type {const} */ ('float')));\n const faceScores = [\n viewDirection.x.negate(), viewDirection.x,\n viewDirection.z.negate(), viewDirection.z,\n viewDirection.y.negate(), viewDirection.y,\n ];\n const exposedScore = (/** @type {number} */ face) => {\n const exposed = mod(voxelFaceMask.div(2 ** face).floor(), 2);\n return mix(-2, faceScores[face], exposed);\n };\n const bestFaceScore = max(\n max(max(exposedScore(0), exposedScore(1)), max(exposedScore(2), exposedScore(3))),\n max(exposedScore(4), exposedScore(5)),\n );\n const sourceFaceNormal = attribute('normal', /** @type {const} */ ('vec3'));\n splatMask = sourceFaceNormal.dot(viewDirection)\n .greaterThanEqual(bestFaceScore.sub(1e-5)).and(splatColor.a.greaterThan(0.5));\n }\n const createSnappedMaterial = (/** @type {boolean} */ pbr) => {\n const material = new MeshStandardNodeMaterial({\n name: `Pixel impostor \u00B7 vertex-snapped shell \u00B7 ${pbr ? 'mapped' : 'plain'}`,\n side: THREE.FrontSide,\n depthTest: true,\n depthWrite: true,\n });\n material.positionNode = quadLocal;\n material.colorNode = vec4(splatColor.rgb.mul(float(1).sub(unlitMix)), splatColor.a);\n material.emissiveNode = splatColor.rgb.mul(pbr ? splatOrm.r : 1).mul(unlitMix);\n material.normalNode = transformNormalToView(splatShadingNormal);\n if (pbr) {\n material.aoNode = splatOrm.r;\n material.roughnessNode = splatOrm.g.max(0.04);\n material.metalnessNode = splatOrm.b;\n }\n material.maskNode = splatMask;\n material.toneMapped = true;\n material.userData.pixelImpostorPbr = pbr;\n return material;\n };\n const snappedMaterials = {\n mapped: createSnappedMaterial(true),\n plain: createSnappedMaterial(false),\n };\n const snappedShell = skinnedSplats\n ? new THREE.SkinnedMesh(splatGeometry, snappedMaterials.mapped)\n : new THREE.Mesh(splatGeometry, snappedMaterials.mapped);\n if (snappedShell instanceof THREE.SkinnedMesh && voxelShell instanceof THREE.SkinnedMesh) {\n snappedShell.bindMode = voxelShell.bindMode;\n snappedShell.bind(voxelShell.skeleton, voxelShell.bindMatrix);\n snappedShell.bindMatrixInverse.copy(voxelShell.bindMatrixInverse);\n }\n asset.updateWorldMatrix(true, true);\n voxelShell.updateWorldMatrix(true, false);\n if (!useSurfacePoints) {\n snappedShell.matrix.copy(asset.matrixWorld).invert().multiply(voxelShell.matrixWorld);\n snappedShell.matrixAutoUpdate = false;\n }\n snappedShell.name = 'Pixel impostor \u00B7 vertex-snapped shell';\n snappedShell.castShadow = false;\n snappedShell.receiveShadow = false;\n snappedShell.userData.previewPixelImpostor = true;\n snappedShell.userData.pixelImpostorDisplayMode = 'vertex-snap';\n snappedShell.userData.pixelImpostorAlternateMaterials = Object.values(snappedMaterials);\n\n const preview = new THREE.Group();\n preview.name = 'Pixel impostor shader previews';\n preview.visible = false;\n preview.userData.screenPixelSize = screenPixelSize;\n preview.userData.splatPixelSize = splatPixelSize;\n preview.userData.splatScale = splatScale;\n preview.userData.projectedNormalMix = projectedNormalMix;\n preview.userData.projectedNormalMixValue = 1;\n preview.userData.unlitMix = unlitMix;\n preview.userData.raycastMesh = raycast;\n preview.userData.raycastMaterials = raycastMaterials;\n preview.userData.geometryMesh = voxelShell;\n preview.userData.previousGeometryMaterial = previousGeometryMaterial;\n preview.userData.geometryMaterials = geometryMaterials;\n preview.userData.snappedMesh = snappedShell;\n preview.userData.snappedMaterials = snappedMaterials;\n preview.userData.raycastAntialiasEnabled = true;\n preview.userData.snapMode = snapMode;\n preview.userData.viewportSize = viewportSize;\n preview.userData.dpr = dpr;\n preview.userData.pixelSizeValue = 5;\n preview.add(raycast, snappedShell);\n const textureBytes = textureFootprintBytes(atlas)\n + (normalAtlas ? textureFootprintBytes(normalAtlas) : 0)\n + (ormAtlas ? textureFootprintBytes(ormAtlas) : 0)\n + (indexAtlas ? textureFootprintBytes(indexAtlas) : 0);\n const shellStats = pixelDisplayMeshStats(voxelShell, textureBytes);\n const splatStats = pixelDisplayMeshStats(snappedShell, textureFootprintBytes(atlas));\n const raycastStats = pixelDisplayMeshStats(raycast, textureBytes);\n preview.userData.displayStats = {\n geometry: shellStats,\n 'vertex-snap': splatStats,\n raycast: raycastStats,\n 'screen-pixels': raycastStats,\n };\n return preview;\n}\n\n/** @param {THREE.Mesh} mesh @param {number} textureBytes */\nfunction pixelDisplayMeshStats(mesh, textureBytes) {\n const position = mesh.geometry.getAttribute('position');\n const geometryBytes = bufferGeometryFootprintBytes(mesh.geometry);\n const instances = mesh.geometry instanceof THREE.InstancedBufferGeometry\n ? mesh.geometry.instanceCount : 1;\n return {\n triangles: (mesh.geometry.getIndex()?.count ?? position?.count ?? 0) / 3 * instances,\n vertices: (position?.count ?? 0) * instances,\n drawCalls: 1,\n geometryBytes,\n textureBytes,\n gpuBytes: geometryBytes + textureBytes,\n };\n}\n\n/** @param {THREE.BufferGeometry} geometry */\nfunction bufferGeometryFootprintBytes(geometry) {\n const buffers = new Set();\n let bytes = 0;\n const add = (/** @type {THREE.BufferAttribute | THREE.InterleavedBufferAttribute | null | undefined} */ attribute) => {\n if (!attribute) return;\n const storage = attribute instanceof THREE.InterleavedBufferAttribute ? attribute.data : attribute;\n if (buffers.has(storage)) return;\n buffers.add(storage);\n bytes += storage.array?.byteLength ?? 0;\n };\n add(geometry.getIndex());\n for (const attribute of Object.values(geometry.attributes)) add(attribute);\n return bytes;\n}\n\n/** @param {THREE.Texture} atlas */\nfunction textureFootprintBytes(atlas) {\n const image = /** @type {{width?:number,height?:number,data?:{byteLength?:number}} | null} */ (atlas.image);\n if (image?.data?.byteLength !== undefined) return image.data.byteLength;\n const width = Number(image?.width ?? 0);\n const height = Number(image?.height ?? 0);\n return Number.isFinite(width) && Number.isFinite(height) ? width * height * 4 : 0;\n}\n\n/**\n * Install the same voxel, screen-snap, and raycast TSL display used by the\n * workbench. Register the pixel glTF loader before loading the GLB. Call\n * `updateViewport()` after a resize and `dispose()` before discarding the scene.\n *\n * @param {THREE.Object3D} asset Loaded glTF scene.\n * @param {{mode?: 'geometry'|'vertex-snap'|'raycast'|'screen-pixels',\n * binding?:Record<string,unknown>, attach?:boolean,\n * renderer?: {getPixelRatio?: () => number, domElement?: HTMLCanvasElement},\n * pixelSize?: number, snapMode?: 'nearest-grid'|'single-cell'|'center-only',\n * splatScale?: number, antialias?: boolean, pbr?: boolean,\n * projectedNormalMix?: number}=} options\n */\nexport function createPixelImpostorDisplay(asset, options = {}) {\n /** @type {Record<string, unknown> | null} */\n let binding = options.binding ?? null;\n asset.traverse(object => { if (!binding && object.userData.pixelImpostor) binding = object.userData.pixelImpostor; });\n if (!binding) throw new Error('Load a NEEDLE_pixel_impostor GLB with registerNeedlePixelImpostorLoader first.');\n const preview = createPixelImpostorRaycastPreview(asset, new THREE.Box3().setFromObject(asset), binding);\n if (!preview) throw new Error('The pixel impostor has no supported shader atlas.');\n const originals = new Map();\n asset.traverse(object => {\n if (object instanceof THREE.Mesh) originals.set(object, object.visible);\n });\n if (options.attach !== false) asset.add(preview);\n let mode = options.mode ?? 'geometry';\n let pbr = options.pbr ?? true;\n let antialias = options.antialias ?? true;\n const setMode = (/** @type {typeof mode} */ next) => {\n if (!['geometry', 'vertex-snap', 'raycast', 'screen-pixels'].includes(next)) throw new Error(`Unknown pixel display mode: ${next}`);\n mode = next;\n preview.userData.displayMode = next;\n for (const [mesh, visible] of originals) mesh.visible = next === 'geometry' && visible;\n preview.visible = next !== 'geometry';\n for (const child of preview.children) child.visible = child.userData.pixelImpostorDisplayMode === next\n || (next === 'screen-pixels' && child.userData.pixelImpostorDisplayMode === 'raycast');\n preview.userData.screenPixelSize.value = next === 'screen-pixels' ? (options.pixelSize ?? 5) : 1;\n const raycast = preview.userData.raycastMesh;\n const raycastMaterials = preview.userData.raycastMaterials;\n if (raycast instanceof THREE.Mesh) raycast.material = raycastMaterials[pbr ? 'mapped' : 'plain'][next === 'raycast' && antialias ? 'antialias' : 'fast'];\n const snapped = preview.userData.snappedMesh;\n if (snapped instanceof THREE.Mesh) snapped.material = preview.userData.snappedMaterials[pbr ? 'mapped' : 'plain'];\n const shell = preview.userData.geometryMesh;\n if (shell instanceof THREE.Mesh) shell.material = preview.userData.geometryMaterials[pbr ? 'mapped' : 'plain'];\n return preview.userData.displayStats?.[next] ?? null;\n };\n const updateViewport = () => {\n const canvas = options.renderer?.domElement;\n const viewport = preview.userData.viewportSize.value;\n if (viewport instanceof THREE.Vector2) viewport.set(Math.max(1, canvas?.clientWidth ?? 1), Math.max(1, canvas?.clientHeight ?? 1));\n preview.userData.dpr.value = options.renderer?.getPixelRatio?.() ?? 1;\n };\n preview.userData.splatPixelSize.value = options.pixelSize ?? 5;\n preview.userData.splatScale.value = options.splatScale ?? 1;\n preview.userData.projectedNormalMix.value = options.projectedNormalMix ?? 1;\n preview.userData.snapMode.value = options.snapMode === 'single-cell' ? 1 : options.snapMode === 'center-only' ? 2 : 0;\n setMode(mode);\n updateViewport();\n return {\n preview,\n setMode,\n updateViewport,\n /** @param {boolean} enabled */\n setPbr(enabled) { pbr = Boolean(enabled); setMode(mode); },\n /** @param {boolean} enabled */\n setAntialias(enabled) { antialias = Boolean(enabled); setMode(mode); },\n dispose() {\n preview.removeFromParent();\n for (const [mesh, visible] of originals) mesh.visible = visible;\n const shell = preview.userData.geometryMesh;\n if (shell instanceof THREE.Mesh) shell.material = preview.userData.previousGeometryMaterial;\n for (const child of preview.children) if (child instanceof THREE.Mesh && child.geometry !== preview.userData.geometryMesh?.geometry) child.geometry.dispose();\n for (const materials of [preview.userData.raycastMaterials?.mapped, preview.userData.raycastMaterials?.plain, preview.userData.snappedMaterials, preview.userData.geometryMaterials]) {\n if (materials) for (const material of Object.values(materials)) material.dispose();\n }\n },\n };\n}\n"],
|
|
5
|
-
"mappings": ";;;AACA,SAAS,gCAAgC;AACzC,SAAS,SAAS,iBAAiB,kBAAkB,YAAY;AAK1D,IAAM,0BAAN,cAAsC,yBAAyB;AAAA;AAAA,EAEpE,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,cAAc,SAAS;AACrB,UAAM,WAAW,MAAM,cAAc,OAAO;AAC5C,QAAI,CAAC,KAAK,qBAAsB,QAAO;AACvC,UAAM,QAAQ,iBAAiB,IAAI,KAAK,KAAK,sBAAsB,CAAC,CAAC,EAAE;AACvE,UAAM,OAAO,gBA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AI,QAAQ,aAAa,gBAAgB,IAAI;AACpH,UAAQ,IAAI;AACZ,iBAAe;AACf,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA;AAAA,IAEA,OAAO,SAAS;AAAE,YAAM,QAAQ,OAAO;AAAG,cAAQ,IAAI;AAAA,IAAG;AAAA;AAAA,IAEzD,aAAa,SAAS;AAAE,kBAAY,QAAQ,OAAO;AAAG,cAAQ,IAAI;AAAA,IAAG;AAAA,IACrE,UAAU;AACR,cAAQ,iBAAiB;AACzB,iBAAW,CAAC,MAAM,OAAO,KAAK,UAAW,MAAK,UAAU;AACxD,YAAM,QAAQ,QAAQ,SAAS;AAC/B,UAAI,iBAAuB,WAAM,OAAM,WAAW,QAAQ,SAAS;AACnE,iBAAW,SAAS,QAAQ,SAAU,KAAI,iBAAuB,cAAQ,MAAM,aAAa,QAAQ,SAAS,cAAc,SAAU,OAAM,SAAS,QAAQ;AAC5J,iBAAW,aAAa,CAAC,QAAQ,SAAS,kBAAkB,QAAQ,QAAQ,SAAS,kBAAkB,OAAO,QAAQ,SAAS,kBAAkB,QAAQ,SAAS,iBAAiB,GAAG;AACpL,YAAI,UAAW,YAAW,YAAY,OAAO,OAAO,SAAS,EAAG,UAAS,QAAQ;AAAA,MACnF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["// @ts-check\nimport { MeshStandardNodeMaterial } from 'three/webgpu';\nimport { context, modelViewMatrix, modelWorldMatrix, vec4 } from 'three/tsl';\n\n/** Light reconstructed surfaces at their hit position, not the carrier face.\n * View directions stay on the same ray; local lights also need the hit distance.\n */\nexport class CapturedSurfaceMaterial extends MeshStandardNodeMaterial {\n /** @type {import('three/webgpu').Node<'vec3'> | null} */\n capturedPositionNode = null;\n\n /**\n * @override\n * @param {import('three/webgpu').NodeBuilder} builder\n */\n setupLighting(builder) {\n const lighting = super.setupLighting(builder);\n if (!this.capturedPositionNode) return lighting;\n const world = modelWorldMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;\n const view = modelViewMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;\n return context(lighting, {\n positionView: view,\n positionWorld: world,\n shadowPositionWorld: world,\n });\n }\n}\n", "// @ts-check\nimport {\n Fn,\n cameraFar,\n cameraNear,\n cameraProjectionMatrix,\n modelViewMatrix,\n vec4,\n viewZToLogarithmicDepth,\n viewZToOrthographicDepth,\n viewZToPerspectiveDepth,\n viewZToReversedOrthographicDepth,\n viewZToReversedPerspectiveDepth,\n} from 'three/tsl';\n\n/** Match the renderer's depth convention after reconstructing a local hit.\n * @param {import('three/webgpu').Node<'vec3'>} position\n * @param {number} [shadowBias]\n */\nexport function capturedSurfaceDepth(position, shadowBias = 0) {\n return Fn(\n (\n /** @type {unknown} */ _,\n /** @type {import('three/webgpu').NodeBuilder} */ builder,\n ) => {\n // Resolve the shared hit before either projection branch consumes it.\n const z = modelViewMatrix\n .mul(vec4(position, 1))\n .z.toVar('capturedSurfaceViewZ');\n const reversed = builder.renderer.reversedDepthBuffer === true;\n // One material can alternate between a perspective view and orthographic\n // shadow cameras without a new pipeline; select using the active projection.\n const perspective = cameraProjectionMatrix\n .mul(vec4(0, 0, 0, 1))\n .w.equal(0);\n const perspectiveDepth =\n builder.renderer.logarithmicDepthBuffer === true\n ? viewZToLogarithmicDepth(z, cameraNear, cameraFar)\n : (reversed\n ? viewZToReversedPerspectiveDepth\n : viewZToPerspectiveDepth)(z, cameraNear, cameraFar);\n const result = perspective.select(\n perspectiveDepth,\n (reversed\n ? viewZToReversedOrthographicDepth\n : viewZToOrthographicDepth)(z, cameraNear, cameraFar),\n );\n return shadowBias &&\n 'isShadowPassMaterial' in builder.material &&\n builder.material.isShadowPassMaterial\n ? result.add(reversed ? -shadowBias : shadowBias).clamp(0, 1)\n : result;\n },\n )();\n}\n", "// @ts-check\nimport { CapturedSurfaceMaterial } from '../rendering/captured-surface-material.js';\nimport { capturedSurfaceDepth } from '../rendering/captured-surface-depth.js';\nimport * as THREE from 'three';\nimport { MeshBasicNodeMaterial, MeshStandardNodeMaterial } from 'three/webgpu';\nimport {\n Break,\n Fn,\n If,\n Loop,\n abs,\n attribute,\n cameraProjectionMatrix,\n cameraProjectionMatrixInverse,\n cameraPosition,\n cameraWorldMatrix,\n ceil,\n clamp,\n countOneBits,\n float,\n fwidth,\n getViewPosition,\n max,\n min,\n mix,\n modelViewMatrix,\n modelWorldMatrix,\n modelWorldMatrixInverse,\n mod,\n normalMap as normalMapNode,\n normalView,\n smoothstep,\n step,\n sRGBTransferEOTF,\n positionLocal,\n screenCoordinate,\n screenSize,\n texture,\n transformNormalToView,\n uint,\n uniform,\n uvec2,\n uvec4,\n uv,\n vec2,\n vec3,\n vec4,\n vertexColor,\n} from 'three/tsl';\n\n/**\n * Builds the shader alternative to the exported voxel shell. The box supplies\n * interpolated ray-entry positions; the fragment node walks the packed solid\n * volume and returns the first occupied cell in a single draw/pass.\n *\n * @param {THREE.Object3D} asset\n * @param {THREE.Box3} bounds\n * @param {Record<string, unknown>} descriptor\n */\nexport function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {\n const binding = descriptor;\n descriptor = binding.descriptor && typeof binding.descriptor === 'object'\n ? /** @type {Record<string, unknown>} */ (binding.descriptor)\n : descriptor;\n const dimensions = Array.isArray(descriptor.dimensions)\n ? descriptor.dimensions.map(Number)\n : [];\n const planar = Math.round(dimensions[0] ?? 0);\n const layers = Math.round(dimensions[1] ?? 0);\n if (!(planar > 0) || !(layers > 0) || Math.round(dimensions[2] ?? 0) !== planar) return null;\n const atlasTextures = /** @type {THREE.Texture[]} */ ([]);\n if (binding.atlas instanceof THREE.Texture) atlasTextures.push(binding.atlas);\n asset.traverse((object) => {\n if (atlasTextures.length > 0 || !(object instanceof THREE.Mesh)) return;\n const materials = Array.isArray(object.material) ? object.material : [object.material];\n for (const material of materials) {\n const map = /** @type {THREE.MeshBasicMaterial} */ (material).map;\n if (map) { atlasTextures.push(map); break; }\n }\n });\n const atlas = atlasTextures[0];\n if (!atlas) return null;\n atlas.magFilter = THREE.NearestFilter;\n atlas.minFilter = THREE.NearestFilter;\n atlas.generateMipmaps = false;\n atlas.needsUpdate = true;\n const normalAtlas = binding.normalAtlas instanceof THREE.Texture ? binding.normalAtlas : null;\n const ormAtlas = binding.ormAtlas instanceof THREE.Texture ? binding.ormAtlas : null;\n const indexAtlas = binding.indexAtlas instanceof THREE.Texture ? binding.indexAtlas : null;\n const sparse = descriptor.version === 3 && descriptor.storage === 'sparse';\n if (sparse && !indexAtlas) return null;\n for (const map of [normalAtlas, ormAtlas, indexAtlas]) {\n if (!map) continue;\n map.colorSpace = THREE.NoColorSpace;\n map.magFilter = THREE.NearestFilter;\n map.minFilter = THREE.NearestFilter;\n map.generateMipmaps = false;\n map.needsUpdate = true;\n }\n\n const authoredMin = Array.isArray(descriptor.volumeMin) ? descriptor.volumeMin.map(Number) : null;\n const authoredSize = Array.isArray(descriptor.volumeSize) ? descriptor.volumeSize.map(Number) : null;\n const size = authoredSize?.length === 3 && authoredSize.every((value) => value > 0)\n ? new THREE.Vector3().fromArray(authoredSize)\n : bounds.getSize(new THREE.Vector3());\n const center = authoredMin?.length === 3\n ? new THREE.Vector3().fromArray(authoredMin).addScaledVector(size, 0.5)\n : bounds.getCenter(new THREE.Vector3());\n const authoredOccupiedMin = Array.isArray(descriptor.occupiedMin)\n ? descriptor.occupiedMin.map(Number) : null;\n const authoredOccupiedSize = Array.isArray(descriptor.occupiedSize)\n ? descriptor.occupiedSize.map(Number) : null;\n const raycastSize = authoredOccupiedSize?.length === 3\n && authoredOccupiedSize.every((value) => value > 0)\n ? new THREE.Vector3().fromArray(authoredOccupiedSize)\n : size.clone();\n const raycastCenter = authoredOccupiedMin?.length === 3\n ? new THREE.Vector3().fromArray(authoredOccupiedMin).addScaledVector(raycastSize, 0.5)\n : center.clone();\n const raycastOffset = raycastCenter.clone().sub(center);\n const atlasColumns = Math.max(1, Math.round(Number(descriptor.atlasColumns) || Math.ceil(Math.sqrt(layers))));\n const atlasRows = Math.max(1, Math.round(Number(descriptor.atlasRows) || Math.ceil(layers / atlasColumns)));\n const surfaceAtlasSize = Array.isArray(descriptor.surfaceAtlasSize)\n ? descriptor.surfaceAtlasSize.map(Number) : [atlas.image.width, atlas.image.height];\n const indexAtlasSize = Array.isArray(descriptor.indexAtlasSize)\n ? descriptor.indexAtlasSize.map(Number) : [1, 1];\n const sizeNode = uniform(size.clone());\n const raycastHalfSize = uniform(raycastSize.clone().multiplyScalar(0.5));\n const raycastOffsetNode = uniform(raycastOffset);\n const screenPixelSize = uniform(1);\n const splatPixelSize = uniform(5);\n const splatScale = uniform(1);\n const projectedNormalMix = uniform(1);\n const unlitMix = uniform(0);\n const snapMode = uniform(0);\n const viewportSize = uniform(new THREE.Vector2(1, 1));\n const dpr = uniform(1);\n const volumeDimensions = vec3(planar, layers, planar);\n const voxelHalfExtents = vec3(\n size.x / planar * 0.5,\n size.y / layers * 0.5,\n size.z / planar * 0.5,\n );\n const minimumCellSize = Math.min(size.x / planar, size.y / layers, size.z / planar);\n const maximumSteps = planar * 2 + layers + 3;\n const linearTextureUv = (/** @type {import('three/webgpu').Node<'float'>} */ index, /** @type {number[]} */ dimensions) => vec2(\n mod(index, dimensions[0]).add(0.5).div(dimensions[0]),\n index.div(dimensions[0]).floor().add(0.5).div(dimensions[1]),\n );\n // The ray march reads these atlases texel by texel. Explicit integer loads\n // avoid a nearest-filtered sample's shared size lookup: before r187, Three\n // computes it once inside the first trace loop, after the loop's early exit,\n // and later traces read it unassigned when that first ray leaves early.\n // Same texel a nearest sample selects: floor(uv * the texture's own size).\n const loadTexel = (/** @type {THREE.Texture} */ map, /** @type {import('three/webgpu').Node<'vec2'>} */ atlasUv) =>\n texture(map).load(uvec2(atlasUv.mul(vec2(Number(map.image.width), Number(map.image.height))).floor()));\n const sparseUint = (/** @type {import('three/webgpu').Node<'float'>} */ texel) => {\n if (!indexAtlas) throw new Error('Sparse pixel impostor requires an index atlas');\n const bytes = uvec4(loadTexel(indexAtlas, linearTextureUv(texel, indexAtlasSize)).mul(255).round());\n return bytes.x\n .bitOr(bytes.y.shiftLeft(8))\n .bitOr(bytes.z.shiftLeft(16))\n .bitOr(bytes.w.shiftLeft(24));\n };\n // @ts-ignore -- TSL's Fn declaration exposes NodeBuilder instead of its shader parameters.\n const traceVolumeNode = Fn(([sampleOffset]) => {\n // Reconstructing the ray from the snapped screen coordinate avoids the\n // derivative discontinuity along the two triangles of each box face.\n const rasterPixelSize = screenPixelSize.mul(dpr);\n const sampleCoordinate = screenCoordinate.div(rasterPixelSize).floor()\n .mul(rasterPixelSize).add(\n rasterPixelSize.mul(vec2(0.5).add(sampleOffset)),\n );\n const sampleUv = sampleCoordinate.div(screenSize);\n const nearView = getViewPosition(sampleUv, float(0), cameraProjectionMatrixInverse);\n const farView = getViewPosition(sampleUv, float(1), cameraProjectionMatrixInverse);\n const nearWorld = cameraWorldMatrix.mul(vec4(nearView, 1));\n const farWorld = cameraWorldMatrix.mul(vec4(farView, 1));\n const rayOrigin = modelWorldMatrixInverse.mul(nearWorld).xyz;\n const rayFar = modelWorldMatrixInverse.mul(farWorld).xyz;\n const rayDirection = rayFar.sub(rayOrigin).normalize();\n const distanceA = raycastHalfSize.negate().sub(rayOrigin).div(rayDirection);\n const distanceB = raycastHalfSize.sub(rayOrigin).div(rayDirection);\n const nearestDistance = max(\n max(min(distanceA.x, distanceB.x), min(distanceA.y, distanceB.y)),\n min(distanceA.z, distanceB.z),\n ).max(0);\n const exitDistance = min(\n min(max(distanceA.x, distanceB.x), max(distanceA.y, distanceB.y)),\n max(distanceA.z, distanceB.z),\n );\n const entry = rayOrigin.add(rayDirection.mul(nearestDistance));\n const gridVelocity = rayDirection.div(sizeNode).mul(volumeDimensions);\n const gridPoint = entry.add(raycastOffsetNode).div(sizeNode).add(0.5).mul(volumeDimensions)\n .add(gridVelocity.mul(minimumCellSize * 0.001));\n // Rasterization only guarantees that the center ray intersects the proxy.\n // An AA sub-sample can lie outside it; reject that ray instead of feeding\n // its invalid slab entry into the voxel traversal (which drew box lines).\n const cell = exitDistance.greaterThanEqual(nearestDistance)\n .select(gridPoint.floor(), vec3(-1)).toVar();\n // Declared before the loop: Three r186 caches a sub-expression shared by\n // the per-axis branches below into a variable assigned only inside the\n // first branch that uses it, so the z step read a stale value.\n const directionStep = step(0, gridVelocity).mul(2).sub(1).toVar();\n const absoluteVelocity = abs(gridVelocity).max(1e-6);\n const cellFraction = gridPoint.sub(cell);\n const positiveAxis = step(0, gridVelocity);\n const nextDistance = cellFraction.mul(vec3(1).sub(positiveAxis))\n .add(vec3(1).sub(cellFraction).mul(positiveAxis));\n const nextCrossing = nextDistance.div(absoluteVelocity).toVar();\n const crossingDelta = vec3(1).div(absoluteVelocity).toVar();\n // xyz is the reconstructed local hit; w is the linear cell index + 1.\n // Keeping both in one vec4 avoids rebuilding the camera ray after traversal.\n const result = vec4(0, 0, 0, 0).toVar();\n const travelled = nearestDistance.toVar();\n Loop(maximumSteps, () => {\n const outside = cell.x.lessThan(0).or(cell.y.lessThan(0)).or(cell.z.lessThan(0))\n .or(cell.x.greaterThanEqual(planar)).or(cell.y.greaterThanEqual(layers)).or(cell.z.greaterThanEqual(planar));\n If(outside, () => { Break(); });\n // Keep every operation in the TSL graph. JavaScript arithmetic coerces\n // node expressions to NaN, which then produces invalid WGSL (`NaN.0`).\n const linearCell = cell.x.add(cell.z.add(cell.y.mul(planar)).mul(planar));\n let cellOccupied;\n if (sparse) {\n const wordIndex = linearCell.div(32).floor();\n const word = sparseUint(wordIndex.mul(2));\n const bit = uint(mod(linearCell, 32));\n cellOccupied = word.shiftRight(bit).bitAnd(1).equal(1);\n } else {\n const atlasColumn = mod(cell.y, atlasColumns);\n const atlasRow = cell.y.div(atlasColumns).floor();\n const atlasUv = vec2(\n atlasColumn.mul(planar).add(cell.x).add(0.5).div(atlasColumns * planar),\n atlasRow.mul(planar).add(cell.z).add(0.5).div(atlasRows * planar),\n );\n cellOccupied = loadTexel(atlas, atlasUv).a.greaterThan(0.5);\n }\n If(cellOccupied, () => {\n result.assign(vec4(\n rayOrigin.add(rayDirection.mul(travelled)),\n linearCell.add(1),\n ));\n Break();\n });\n const nearestCrossing = min(nextCrossing.x, min(nextCrossing.y, nextCrossing.z));\n travelled.assign(nearestDistance.add(nearestCrossing));\n // Independent branches intentionally advance two or three axes for an\n // exact edge/corner crossing; that avoids revisiting zero-width cells.\n If(nextCrossing.x.lessThanEqual(nearestCrossing.add(1e-6)), () => {\n cell.x.addAssign(directionStep.x);\n nextCrossing.x.addAssign(crossingDelta.x);\n });\n If(nextCrossing.y.lessThanEqual(nearestCrossing.add(1e-6)), () => {\n cell.y.addAssign(directionStep.y);\n nextCrossing.y.addAssign(crossingDelta.y);\n });\n If(nextCrossing.z.lessThanEqual(nearestCrossing.add(1e-6)), () => {\n cell.z.addAssign(directionStep.z);\n nextCrossing.z.addAssign(crossingDelta.z);\n });\n });\n return result;\n });\n const traceVolume = /** @type {(sampleOffset: import('three/webgpu').Node<'vec2'>) => import('three/webgpu').Node<'vec4'>} */ (\n /** @type {unknown} */ (traceVolumeNode)\n );\n const createRaycastMaterial = (\n /** @type {boolean} */ antialias,\n /** @type {boolean} */ pbr,\n ) => {\n // Baked material maps are a cached graph variant, not a uniform branch:\n // the plain lit graph retains lighting and projected normals but contains\n // no voxel ORM sampling or AO/roughness/metalness nodes.\n const centerHit = traceVolume(vec2(0));\n const occupied = centerHit.w.greaterThan(0);\n /** @type {import('three/webgpu').Node<'float'>} */\n let coverage = float(1);\n if (antialias) {\n // This JavaScript branch specializes the TSL graph: the fast material\n // contains one DDA trace, while the AA material contains five. There is\n // no runtime AA branch or dormant extra tracing in the fast pipeline.\n const sampleHits = [\n traceVolume(vec2(-0.125, -0.375)),\n traceVolume(vec2(0.375, -0.125)),\n traceVolume(vec2(-0.375, 0.125)),\n traceVolume(vec2(0.125, 0.375)),\n ];\n const sampleOccupancy = sampleHits.map((sampleHit) => sampleHit.w.greaterThan(0));\n coverage = sampleOccupancy[0].select(1, 0)\n .add(sampleOccupancy[1].select(1, 0))\n .add(sampleOccupancy[2].select(1, 0))\n .add(sampleOccupancy[3].select(1, 0))\n .mul(0.25).mul(occupied.select(1, 0));\n }\n const hit = centerHit.toVar(antialias ? 'pixelImpostorAaHit' : 'pixelImpostorFastHit');\n const linearHitCell = hit.w.sub(1).max(0);\n const hitLayer = linearHitCell.div(planar * planar).floor();\n const hitSliceCell = mod(linearHitCell, planar * planar);\n const hitCell = vec3(mod(hitSliceCell, planar), hitLayer, hitSliceCell.div(planar).floor());\n let hitAtlasUv;\n if (sparse) {\n const wordIndex = linearHitCell.div(32).floor();\n const word = sparseUint(wordIndex.mul(2));\n const prefixRank = sparseUint(wordIndex.mul(2).add(1));\n const bit = uint(mod(linearHitCell, 32));\n const precedingMask = uint(1).shiftLeft(bit).sub(1);\n // Three's nodeProxyIntent returns a typed TSL node; @types/three\n // currently declares the bare BitcountNode class instead. A uint input\n // produces uint output (WGSL countOneBits preserves its input type).\n const precedingCount = /** @type {ReturnType<typeof countOneBits> & import('three/webgpu').Node<'uint'>} */ (countOneBits(word.bitAnd(precedingMask)));\n const record = prefixRank.add(precedingCount);\n hitAtlasUv = linearTextureUv(float(record), surfaceAtlasSize);\n } else {\n const hitAtlasColumn = mod(hitCell.y, atlasColumns);\n const hitAtlasRow = hitCell.y.div(atlasColumns).floor();\n hitAtlasUv = vec2(\n hitAtlasColumn.mul(planar).add(hitCell.x).add(0.5).div(atlasColumns * planar),\n hitAtlasRow.mul(planar).add(hitCell.z).add(0.5).div(atlasRows * planar),\n );\n }\n const baseSample = loadTexel(atlas, hitAtlasUv);\n const ormSample = ormAtlas ? loadTexel(ormAtlas, hitAtlasUv) : vec4(1, 1, 0, 1);\n const hitPosition = hit.xyz;\n const hitToCamera = modelWorldMatrixInverse.mul(vec4(cameraPosition, 1)).xyz.sub(hitPosition);\n const faceSign = step(0, hitToCamera).mul(2).sub(1);\n const hitCellCenter = hitCell.add(0.5).div(volumeDimensions).sub(0.5)\n .mul(sizeNode).sub(raycastOffsetNode);\n const cellDelta = hitPosition.sub(hitCellCenter).div(sizeNode).mul(volumeDimensions);\n const absoluteCellDelta = cellDelta.abs();\n const boundaryDistance = max(absoluteCellDelta.x,\n max(absoluteCellDelta.y, absoluteCellDelta.z));\n const faceDirection = hitToCamera.abs().normalize();\n // At an edge/corner more than one face is a valid entry face. Floating\n // error used to make the largest coordinate flicker between them. Treat\n // near-ties as the same boundary and choose the most camera-facing face.\n const xFaceScore = absoluteCellDelta.x.greaterThanEqual(boundaryDistance.sub(1e-4))\n .select(faceDirection.x, -1);\n const yFaceScore = absoluteCellDelta.y.greaterThanEqual(boundaryDistance.sub(1e-4))\n .select(faceDirection.y, -1);\n const zFaceScore = absoluteCellDelta.z.greaterThanEqual(boundaryDistance.sub(1e-4))\n .select(faceDirection.z, -1);\n const geometricNormal = xFaceScore.greaterThanEqual(yFaceScore)\n .and(xFaceScore.greaterThanEqual(zFaceScore))\n .select(vec3(faceSign.x, 0, 0), yFaceScore.greaterThanEqual(zFaceScore)\n .select(vec3(0, faceSign.y, 0), vec3(0, 0, faceSign.z)));\n const sampledNormal = normalAtlas\n ? loadTexel(normalAtlas, hitAtlasUv).xyz.mul(2).sub(1)\n : geometricNormal;\n const bakedNormal = sampledNormal.dot(sampledNormal).greaterThan(1e-8)\n .select(sampledNormal.normalize(), geometricNormal);\n const projectedNormal = bakedNormal.dot(geometricNormal).lessThan(0)\n .select(bakedNormal.negate(), bakedNormal);\n const shadingNormal = mix(geometricNormal, projectedNormal, projectedNormalMix).normalize();\n const materialName = `Pixel impostor \u00B7 volume raycast \u00B7 ${antialias ? 'AA' : 'fast'} \u00B7 ${pbr ? 'PBR maps' : 'plain lit'}`;\n const material = new CapturedSurfaceMaterial({\n name: materialName,\n side: THREE.FrontSide,\n depthTest: true,\n depthWrite: true,\n });\n material.colorNode = vec4(baseSample.rgb.mul(float(1).sub(unlitMix)),\n antialias ? baseSample.a.mul(coverage) : baseSample.a);\n material.emissiveNode = baseSample.rgb.mul(pbr ? ormSample.r : 1).mul(unlitMix);\n material.normalNode = transformNormalToView(shadingNormal);\n if (pbr) {\n material.aoNode = ormSample.r;\n material.roughnessNode = ormSample.g.max(0.04);\n material.metalnessNode = ormSample.b;\n }\n material.receivedShadowPositionNode = modelWorldMatrix.mul(vec4(hitPosition, 1)).xyz;\n material.maskNode = occupied.and(\n baseSample.a.greaterThan(Number(descriptor.alphaCutoff) || 0.5),\n );\n material.maskShadowNode = antialias ? coverage.greaterThanEqual(0.5) : occupied;\n material.alphaToCoverage = antialias;\n material.capturedPositionNode = hitPosition;\n material.depthNode = capturedSurfaceDepth(hitPosition);\n material.toneMapped = true;\n material.userData.screenPixelSize = screenPixelSize;\n material.userData.pixelImpostorRaycastAntialias = antialias;\n material.userData.pixelImpostorRaySamples = antialias ? 5 : 1;\n material.userData.pixelImpostorPbr = pbr;\n return material;\n };\n const raycastMaterials = {\n mapped: {\n fast: createRaycastMaterial(false, true),\n antialias: createRaycastMaterial(true, true),\n },\n plain: {\n fast: createRaycastMaterial(false, false),\n antialias: createRaycastMaterial(true, false),\n },\n };\n const raycast = new THREE.Mesh(new THREE.BoxGeometry(\n raycastSize.x,\n raycastSize.y,\n raycastSize.z,\n ), raycastMaterials.mapped.antialias);\n raycast.name = 'Pixel impostor \u00B7 volume raycast';\n raycast.position.copy(raycastCenter);\n raycast.castShadow = true;\n raycast.receiveShadow = true;\n raycast.userData.previewPixelImpostor = true;\n raycast.userData.pixelImpostorDisplayMode = 'raycast';\n raycast.userData.pixelImpostorAlternateMaterials = [\n ...Object.values(raycastMaterials.mapped),\n ...Object.values(raycastMaterials.plain),\n ];\n\n const surfacePoints = binding.surfacePoints instanceof THREE.BufferAttribute\n || binding.surfacePoints instanceof THREE.InterleavedBufferAttribute\n ? binding.surfacePoints : null;\n // Keep the portable face-culled shell as one ordinary draw. Each vertex is\n // marked with its source voxel center, so every corner from one voxel gets\n // exactly the same screen-space displacement and the cell remains coherent.\n /** @type {THREE.Mesh | null} */\n let shell = null;\n asset.traverse((object) => {\n if (!shell && object instanceof THREE.Mesh\n && (object.geometry.getAttribute('_voxel_center') || surfacePoints)) {\n shell = object;\n }\n });\n if (!shell) return null;\n const voxelShell = /** @type {THREE.Mesh} */ (shell);\n const geometryBaseSample = texture(atlas, uv());\n const geometryOrmSample = ormAtlas ? texture(ormAtlas, uv()) : vec4(1, 1, 0, 1);\n const geometryNormal = attribute('normal', /** @type {const} */ ('vec3')).normalize();\n const geometryProjectedNormal = normalAtlas\n ? texture(normalAtlas, uv()).xyz.mul(2).sub(1).normalize()\n : geometryNormal;\n const geometryAlignedNormal = geometryProjectedNormal.dot(geometryNormal).lessThan(0)\n .select(geometryProjectedNormal.negate(), geometryProjectedNormal);\n const createGeometryMaterial = (/** @type {boolean} */ pbr) => {\n const material = new MeshStandardNodeMaterial({\n name: `Pixel impostor \u00B7 voxel geometry \u00B7 ${pbr ? 'mapped' : 'plain'}`,\n side: THREE.FrontSide,\n depthTest: true,\n depthWrite: true,\n });\n material.colorNode = vec4(geometryBaseSample.rgb.mul(float(1).sub(unlitMix)),\n geometryBaseSample.a);\n material.emissiveNode = geometryBaseSample.rgb.mul(pbr ? geometryOrmSample.r : 1).mul(unlitMix);\n material.normalNode = transformNormalToView(\n mix(geometryNormal, geometryAlignedNormal, projectedNormalMix).normalize(),\n );\n if (pbr) {\n material.aoNode = geometryOrmSample.r;\n material.roughnessNode = geometryOrmSample.g.max(0.04);\n material.metalnessNode = geometryOrmSample.b;\n }\n material.maskNode = geometryBaseSample.a.greaterThan(\n Number(descriptor.alphaCutoff) || 0.5,\n );\n material.toneMapped = true;\n material.userData.pixelImpostorPbr = pbr;\n return material;\n };\n const geometryMaterials = {\n mapped: createGeometryMaterial(true),\n plain: createGeometryMaterial(false),\n };\n const previousGeometryMaterial = voxelShell.material;\n voxelShell.material = geometryMaterials.mapped;\n voxelShell.userData.pixelImpostorAlternateMaterials = Object.values(geometryMaterials);\n const skinnedSplats = voxelShell instanceof THREE.SkinnedMesh;\n // Sparse instancing deliberately omits the carrier mesh's per-vertex data.\n // Animated exports retain that data, so use their dense carriers and let\n // standard Three.js skinning deform each voxel center before screen-aligning\n // its quad. Static sparse files keep the smaller instanced path.\n const useSurfacePoints = surfacePoints && !skinnedSplats;\n let splatGeometry = skinnedSplats ? voxelShell.geometry.clone() : voxelShell.geometry;\n if (skinnedSplats) {\n const centers = voxelShell.geometry.getAttribute('_voxel_center');\n if (!centers) throw new Error('Animated voxel splats require retained voxel centers.');\n splatGeometry.setAttribute('position', centers.clone());\n }\n if (useSurfacePoints) {\n const count = surfacePoints.count;\n const coordinates = new Float32Array(count * 3);\n const records = new Float32Array(count);\n for (let index = 0; index < count; index++) {\n coordinates[index * 3] = surfacePoints.getX(index);\n coordinates[index * 3 + 1] = surfacePoints.getY(index);\n coordinates[index * 3 + 2] = surfacePoints.getZ(index);\n records[index] = index;\n }\n const instancedGeometry = new THREE.InstancedBufferGeometry();\n instancedGeometry.instanceCount = count;\n splatGeometry = instancedGeometry;\n splatGeometry.setAttribute('position', new THREE.BufferAttribute(new Float32Array(12), 3));\n splatGeometry.setAttribute('_voxel_corner', new THREE.BufferAttribute(new Float32Array([\n -1, -1, 1, -1, 1, 1, -1, 1,\n ]), 2));\n splatGeometry.setAttribute('_voxel_coord', new THREE.InstancedBufferAttribute(coordinates, 3));\n splatGeometry.setAttribute('_voxel_record', new THREE.InstancedBufferAttribute(records, 1));\n splatGeometry.setIndex([0, 1, 2, 0, 2, 3]);\n splatGeometry.boundingBox = voxelShell.geometry.boundingBox?.clone() ?? bounds.clone();\n splatGeometry.boundingSphere = voxelShell.geometry.boundingSphere?.clone()\n ?? splatGeometry.boundingBox.getBoundingSphere(new THREE.Sphere());\n }\n const voxelCoordinate = attribute('_voxel_coord', /** @type {const} */ ('vec3'));\n const voxelCenter = skinnedSplats\n ? positionLocal\n : useSurfacePoints\n ? voxelCoordinate.add(0.5).div(volumeDimensions)\n .sub(0.5).mul(sizeNode).add(uniform(center.clone()))\n : attribute('_voxel_center', /** @type {const} */ ('vec3'));\n const voxelCorner = attribute('_voxel_corner', /** @type {const} */ ('vec2'));\n const centerView = modelViewMatrix.mul(vec4(voxelCenter, 1));\n const centerClip = cameraProjectionMatrix.mul(centerView);\n const centerNdc = centerClip.xy.div(centerClip.w);\n const cssViewport = viewportSize;\n const centerCss = centerNdc.mul(0.5).add(0.5).mul(cssViewport);\n const projectVoxelPoint = (/** @type {import('three/webgpu').Node<'vec3'>} */ point) => {\n const projected = cameraProjectionMatrix.mul(modelViewMatrix.mul(vec4(point, 1)));\n return projected.xy.div(projected.w).mul(0.5).add(0.5).mul(cssViewport);\n };\n const projectedX = projectVoxelPoint(voxelCenter.add(vec3(voxelHalfExtents.x, 0, 0)));\n const projectedY = projectVoxelPoint(voxelCenter.add(vec3(0, voxelHalfExtents.y, 0)));\n const projectedZ = projectVoxelPoint(voxelCenter.add(vec3(0, 0, voxelHalfExtents.z)));\n const projectedHalfFootprint = projectedX.sub(centerCss).abs()\n .add(projectedY.sub(centerCss).abs())\n .add(projectedZ.sub(centerCss).abs());\n const projectedVoxelSize = max(projectedHalfFootprint.x, projectedHalfFootprint.y).mul(2);\n const projectedCellSpan = projectedVoxelSize.div(splatPixelSize);\n // `floor()` in this vertex-node graph causes pathological WebGPU pipeline\n // compilation on current Chrome/Metal. Inputs are positive, so this is the\n // same nearest-integer quantization with half values biased downward.\n const nearestCellSpan = ceil(projectedCellSpan.sub(0.5)).max(1);\n const singleCell = snapMode.equal(1);\n const centerOnly = snapMode.equal(2);\n const cellSpan = singleCell.select(1, nearestCellSpan);\n const cellCenter = centerCss.div(splatPixelSize).floor()\n .mul(splatPixelSize).add(splatPixelSize.mul(0.5));\n const gridIntersection = centerCss.div(splatPixelSize).add(0.5).floor().mul(splatPixelSize);\n const oddCellSpan = mod(cellSpan, 2);\n const parityAlignedCenter = oddCellSpan.greaterThan(0.5).select(cellCenter, gridIntersection);\n const snappedCss = centerOnly.select(cellCenter, parityAlignedCenter);\n const splatSize = cellSpan.mul(splatPixelSize).mul(splatScale);\n // The original exposed face is only a carrier. Replace its four positions\n // with a camera-facing square centered on the voxel. A small overlap avoids\n // pinholes between neighboring screen pixels under perspective projection.\n const quadCss = snappedCss.add(voxelCorner.mul(splatSize.mul(0.52)));\n const quadNdc = quadCss.div(cssViewport).mul(2).sub(1);\n const quadClip = vec4(quadNdc.mul(centerClip.w), centerClip.z, centerClip.w);\n const quadViewHomogeneous = cameraProjectionMatrixInverse.mul(quadClip);\n const quadView = quadViewHomogeneous.xyz.div(quadViewHomogeneous.w);\n const quadWorld = cameraWorldMatrix.mul(vec4(quadView, 1));\n const quadLocalHomogeneous = modelWorldMatrixInverse.mul(quadWorld);\n const quadLocal = quadLocalHomogeneous.xyz.div(quadLocalHomogeneous.w);\n\n const splatUv = useSurfacePoints\n ? linearTextureUv(attribute('_voxel_record', /** @type {const} */ ('float')), surfaceAtlasSize)\n : uv();\n const splatColor = texture(atlas, splatUv);\n const splatOrm = ormAtlas ? texture(ormAtlas, splatUv) : vec4(1, 1, 0, 1);\n const cameraLocal = modelWorldMatrixInverse.mul(vec4(cameraPosition, 1)).xyz;\n const viewDirection = cameraLocal.sub(voxelCenter).normalize();\n const splatBakedNormal = normalAtlas\n ? texture(normalAtlas, splatUv).xyz.mul(2).sub(1).normalize()\n : viewDirection;\n const splatProjectedNormal = splatBakedNormal.dot(viewDirection).lessThan(0)\n .select(splatBakedNormal.negate(), splatBakedNormal);\n const splatShadingNormal = mix(\n viewDirection,\n splatProjectedNormal,\n projectedNormalMix,\n ).normalize();\n let splatMask;\n if (useSurfacePoints) {\n splatMask = splatColor.a.greaterThan(0.5);\n } else {\n // Legacy v3 files duplicate a voxel once per exposed face. Select exactly\n // one carrier before rotating it into the screen-aligned square.\n const voxelFaceMask = float(attribute('_voxel_face_mask', /** @type {const} */ ('float')));\n const faceScores = [\n viewDirection.x.negate(), viewDirection.x,\n viewDirection.z.negate(), viewDirection.z,\n viewDirection.y.negate(), viewDirection.y,\n ];\n const exposedScore = (/** @type {number} */ face) => {\n const exposed = mod(voxelFaceMask.div(2 ** face).floor(), 2);\n return mix(-2, faceScores[face], exposed);\n };\n const bestFaceScore = max(\n max(max(exposedScore(0), exposedScore(1)), max(exposedScore(2), exposedScore(3))),\n max(exposedScore(4), exposedScore(5)),\n );\n const sourceFaceNormal = attribute('normal', /** @type {const} */ ('vec3'));\n splatMask = sourceFaceNormal.dot(viewDirection)\n .greaterThanEqual(bestFaceScore.sub(1e-5)).and(splatColor.a.greaterThan(0.5));\n }\n const createSnappedMaterial = (/** @type {boolean} */ pbr) => {\n const material = new MeshStandardNodeMaterial({\n name: `Pixel impostor \u00B7 vertex-snapped shell \u00B7 ${pbr ? 'mapped' : 'plain'}`,\n side: THREE.FrontSide,\n depthTest: true,\n depthWrite: true,\n });\n material.positionNode = quadLocal;\n material.colorNode = vec4(splatColor.rgb.mul(float(1).sub(unlitMix)), splatColor.a);\n material.emissiveNode = splatColor.rgb.mul(pbr ? splatOrm.r : 1).mul(unlitMix);\n material.normalNode = transformNormalToView(splatShadingNormal);\n if (pbr) {\n material.aoNode = splatOrm.r;\n material.roughnessNode = splatOrm.g.max(0.04);\n material.metalnessNode = splatOrm.b;\n }\n material.maskNode = splatMask;\n material.toneMapped = true;\n material.userData.pixelImpostorPbr = pbr;\n return material;\n };\n const snappedMaterials = {\n mapped: createSnappedMaterial(true),\n plain: createSnappedMaterial(false),\n };\n const snappedShell = skinnedSplats\n ? new THREE.SkinnedMesh(splatGeometry, snappedMaterials.mapped)\n : new THREE.Mesh(splatGeometry, snappedMaterials.mapped);\n if (snappedShell instanceof THREE.SkinnedMesh && voxelShell instanceof THREE.SkinnedMesh) {\n snappedShell.bindMode = voxelShell.bindMode;\n snappedShell.bind(voxelShell.skeleton, voxelShell.bindMatrix);\n snappedShell.bindMatrixInverse.copy(voxelShell.bindMatrixInverse);\n }\n asset.updateWorldMatrix(true, true);\n voxelShell.updateWorldMatrix(true, false);\n if (!useSurfacePoints) {\n snappedShell.matrix.copy(asset.matrixWorld).invert().multiply(voxelShell.matrixWorld);\n snappedShell.matrixAutoUpdate = false;\n }\n snappedShell.name = 'Pixel impostor \u00B7 vertex-snapped shell';\n snappedShell.castShadow = false;\n snappedShell.receiveShadow = false;\n snappedShell.userData.previewPixelImpostor = true;\n snappedShell.userData.pixelImpostorDisplayMode = 'vertex-snap';\n snappedShell.userData.pixelImpostorAlternateMaterials = Object.values(snappedMaterials);\n\n const preview = new THREE.Group();\n preview.name = 'Pixel impostor shader previews';\n preview.visible = false;\n preview.userData.screenPixelSize = screenPixelSize;\n preview.userData.splatPixelSize = splatPixelSize;\n preview.userData.splatScale = splatScale;\n preview.userData.projectedNormalMix = projectedNormalMix;\n preview.userData.projectedNormalMixValue = 1;\n preview.userData.unlitMix = unlitMix;\n preview.userData.raycastMesh = raycast;\n preview.userData.raycastMaterials = raycastMaterials;\n preview.userData.geometryMesh = voxelShell;\n preview.userData.previousGeometryMaterial = previousGeometryMaterial;\n preview.userData.geometryMaterials = geometryMaterials;\n preview.userData.snappedMesh = snappedShell;\n preview.userData.snappedMaterials = snappedMaterials;\n preview.userData.raycastAntialiasEnabled = true;\n preview.userData.snapMode = snapMode;\n preview.userData.viewportSize = viewportSize;\n preview.userData.dpr = dpr;\n preview.userData.pixelSizeValue = 5;\n preview.add(raycast, snappedShell);\n const textureBytes = textureFootprintBytes(atlas)\n + (normalAtlas ? textureFootprintBytes(normalAtlas) : 0)\n + (ormAtlas ? textureFootprintBytes(ormAtlas) : 0)\n + (indexAtlas ? textureFootprintBytes(indexAtlas) : 0);\n const shellStats = pixelDisplayMeshStats(voxelShell, textureBytes);\n const splatStats = pixelDisplayMeshStats(snappedShell, textureFootprintBytes(atlas));\n const raycastStats = pixelDisplayMeshStats(raycast, textureBytes);\n preview.userData.displayStats = {\n geometry: shellStats,\n 'vertex-snap': splatStats,\n raycast: raycastStats,\n 'screen-pixels': raycastStats,\n };\n return preview;\n}\n\n/** @param {THREE.Mesh} mesh @param {number} textureBytes */\nfunction pixelDisplayMeshStats(mesh, textureBytes) {\n const position = mesh.geometry.getAttribute('position');\n const geometryBytes = bufferGeometryFootprintBytes(mesh.geometry);\n const instances = mesh.geometry instanceof THREE.InstancedBufferGeometry\n ? mesh.geometry.instanceCount : 1;\n return {\n triangles: (mesh.geometry.getIndex()?.count ?? position?.count ?? 0) / 3 * instances,\n vertices: (position?.count ?? 0) * instances,\n drawCalls: 1,\n geometryBytes,\n textureBytes,\n gpuBytes: geometryBytes + textureBytes,\n };\n}\n\n/** @param {THREE.BufferGeometry} geometry */\nfunction bufferGeometryFootprintBytes(geometry) {\n const buffers = new Set();\n let bytes = 0;\n const add = (/** @type {THREE.BufferAttribute | THREE.InterleavedBufferAttribute | null | undefined} */ attribute) => {\n if (!attribute) return;\n const storage = attribute instanceof THREE.InterleavedBufferAttribute ? attribute.data : attribute;\n if (buffers.has(storage)) return;\n buffers.add(storage);\n bytes += storage.array?.byteLength ?? 0;\n };\n add(geometry.getIndex());\n for (const attribute of Object.values(geometry.attributes)) add(attribute);\n return bytes;\n}\n\n/** @param {THREE.Texture} atlas */\nfunction textureFootprintBytes(atlas) {\n const image = /** @type {{width?:number,height?:number,data?:{byteLength?:number}} | null} */ (atlas.image);\n if (image?.data?.byteLength !== undefined) return image.data.byteLength;\n const width = Number(image?.width ?? 0);\n const height = Number(image?.height ?? 0);\n return Number.isFinite(width) && Number.isFinite(height) ? width * height * 4 : 0;\n}\n\n/**\n * Install the same voxel, screen-snap, and raycast TSL display used by the\n * workbench. Register the pixel glTF loader before loading the GLB. Call\n * `updateViewport()` after a resize and `dispose()` before discarding the scene.\n *\n * @param {THREE.Object3D} asset Loaded glTF scene.\n * @param {{mode?: 'geometry'|'vertex-snap'|'raycast'|'screen-pixels',\n * binding?:Record<string,unknown>, attach?:boolean,\n * renderer?: {getPixelRatio?: () => number, domElement?: HTMLCanvasElement},\n * pixelSize?: number, snapMode?: 'nearest-grid'|'single-cell'|'center-only',\n * splatScale?: number, antialias?: boolean, pbr?: boolean,\n * projectedNormalMix?: number}=} options\n */\nexport function createPixelImpostorDisplay(asset, options = {}) {\n /** @type {Record<string, unknown> | null} */\n let binding = options.binding ?? null;\n asset.traverse(object => { if (!binding && object.userData.pixelImpostor) binding = object.userData.pixelImpostor; });\n if (!binding) throw new Error('Load a NEEDLE_pixel_impostor GLB with registerNeedlePixelImpostorLoader first.');\n const preview = createPixelImpostorRaycastPreview(asset, new THREE.Box3().setFromObject(asset), binding);\n if (!preview) throw new Error('The pixel impostor has no supported shader atlas.');\n const originals = new Map();\n asset.traverse(object => {\n if (object instanceof THREE.Mesh) originals.set(object, object.visible);\n });\n if (options.attach !== false) asset.add(preview);\n let mode = options.mode ?? 'geometry';\n let pbr = options.pbr ?? true;\n let antialias = options.antialias ?? true;\n const setMode = (/** @type {typeof mode} */ next) => {\n if (!['geometry', 'vertex-snap', 'raycast', 'screen-pixels'].includes(next)) throw new Error(`Unknown pixel display mode: ${next}`);\n mode = next;\n preview.userData.displayMode = next;\n for (const [mesh, visible] of originals) mesh.visible = next === 'geometry' && visible;\n preview.visible = next !== 'geometry';\n for (const child of preview.children) child.visible = child.userData.pixelImpostorDisplayMode === next\n || (next === 'screen-pixels' && child.userData.pixelImpostorDisplayMode === 'raycast');\n preview.userData.screenPixelSize.value = next === 'screen-pixels' ? (options.pixelSize ?? 5) : 1;\n const raycast = preview.userData.raycastMesh;\n const raycastMaterials = preview.userData.raycastMaterials;\n if (raycast instanceof THREE.Mesh) raycast.material = raycastMaterials[pbr ? 'mapped' : 'plain'][next === 'raycast' && antialias ? 'antialias' : 'fast'];\n const snapped = preview.userData.snappedMesh;\n if (snapped instanceof THREE.Mesh) snapped.material = preview.userData.snappedMaterials[pbr ? 'mapped' : 'plain'];\n const shell = preview.userData.geometryMesh;\n if (shell instanceof THREE.Mesh) shell.material = preview.userData.geometryMaterials[pbr ? 'mapped' : 'plain'];\n return preview.userData.displayStats?.[next] ?? null;\n };\n const updateViewport = () => {\n const canvas = options.renderer?.domElement;\n const viewport = preview.userData.viewportSize.value;\n if (viewport instanceof THREE.Vector2) viewport.set(Math.max(1, canvas?.clientWidth ?? 1), Math.max(1, canvas?.clientHeight ?? 1));\n preview.userData.dpr.value = options.renderer?.getPixelRatio?.() ?? 1;\n };\n preview.userData.splatPixelSize.value = options.pixelSize ?? 5;\n preview.userData.splatScale.value = options.splatScale ?? 1;\n preview.userData.projectedNormalMix.value = options.projectedNormalMix ?? 1;\n preview.userData.snapMode.value = options.snapMode === 'single-cell' ? 1 : options.snapMode === 'center-only' ? 2 : 0;\n setMode(mode);\n updateViewport();\n return {\n preview,\n setMode,\n updateViewport,\n /** @param {boolean} enabled */\n setPbr(enabled) { pbr = Boolean(enabled); setMode(mode); },\n /** @param {boolean} enabled */\n setAntialias(enabled) { antialias = Boolean(enabled); setMode(mode); },\n dispose() {\n preview.removeFromParent();\n for (const [mesh, visible] of originals) mesh.visible = visible;\n const shell = preview.userData.geometryMesh;\n if (shell instanceof THREE.Mesh) shell.material = preview.userData.previousGeometryMaterial;\n for (const child of preview.children) if (child instanceof THREE.Mesh && child.geometry !== preview.userData.geometryMesh?.geometry) child.geometry.dispose();\n for (const materials of [preview.userData.raycastMaterials?.mapped, preview.userData.raycastMaterials?.plain, preview.userData.snappedMaterials, preview.userData.geometryMaterials]) {\n if (materials) for (const material of Object.values(materials)) material.dispose();\n }\n },\n };\n}\n"],
|
|
5
|
+
"mappings": ";;;AACA,SAAS,gCAAgC;AACzC,SAAS,SAAS,iBAAiB,kBAAkB,YAAY;AAK1D,IAAM,0BAAN,cAAsC,yBAAyB;AAAA;AAAA,EAEpE,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,cAAc,SAAS;AACrB,UAAM,WAAW,MAAM,cAAc,OAAO;AAC5C,QAAI,CAAC,KAAK,qBAAsB,QAAO;AACvC,UAAM,QAAQ,iBAAiB,IAAI,KAAK,KAAK,sBAAsB,CAAC,CAAC,EAAE;AACvE,UAAM,OAAO,gBAAgB,IAAI,KAAK,KAAK,sBAAsB,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
+
function classicWebGLSupportsNodeMaterials(revision) {
|
|
5
|
+
const fork = /^186\.2-alpha\.(\d+)$/.exec(revision);
|
|
6
|
+
if (fork) return Number(fork[1]) >= 2;
|
|
7
|
+
return Number.parseInt(revision, 10) >= 187;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
classicWebGLSupportsNodeMaterials
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=classic-webgl-support.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/rendering/classic-webgl-support.js"],
|
|
4
|
+
"sourcesContent": ["// @ts-check\n\n/**\n * Reports whether WebGLRenderer from a three revision can keep many node\n * materials alive. Before r187 every uniform block holds one of a few binding\n * points until its material is disposed, so node materials stop drawing after\n * about a dozen. The Needle fork backports the fix from 0.186.2-alpha.2.\n *\n * @param {string} revision three's `REVISION`, such as `'187'` or `'186.2-alpha.2'`\n */\nexport function classicWebGLSupportsNodeMaterials(revision) {\n\tconst fork = /^186\\.2-alpha\\.(\\d+)$/.exec(revision);\n\tif (fork) return Number(fork[1]) >= 2;\n\treturn Number.parseInt(revision, 10) >= 187;\n}\n"],
|
|
5
|
+
"mappings": ";;;AAUO,SAAS,kCAAkC,UAAU;AAC3D,QAAM,OAAO,wBAAwB,KAAK,QAAQ;AAClD,MAAI,KAAM,QAAO,OAAO,KAAK,CAAC,CAAC,KAAK;AACpC,SAAO,OAAO,SAAS,UAAU,EAAE,KAAK;AACzC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -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;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/rendering/renderer-support.js"],
|
|
4
|
-
"sourcesContent": ["// @ts-check\nimport * as TSL from 'three/tsl';\n\n/**\n * @typedef {object} ImpostorRenderer\n * @property {boolean=} isWebGPURenderer\n * @property {boolean=} isWebGLRenderer\n * @property {(object & {supportsNodeMaterials?: boolean})=} capabilities\n * @property {((handler: import('three/addons/tsl/WebGLNodesHandler.js').WebGLNodesHandler) => void)=} setNodesHandler\n */\n\n/**\n * Reports whether a renderer can compile Baker's TSL impostor material.\n * WebGPURenderer supports node materials directly. Classic WebGLRenderer\n * integrations must advertise that they installed a compatible nodes handler.\n *\n * @param {ImpostorRenderer | undefined} renderer\n */\nexport function rendererSupportsImpostorNodeMaterials(renderer) {\n\tif (typeof Reflect.get(TSL, 'struct') !== 'function') return false;\n\treturn renderer?.isWebGPURenderer === true\n\t\t|| renderer?.capabilities?.supportsNodeMaterials === true;\n}\n\n/** @type {WeakMap<ImpostorRenderer, Promise<void>>} */\nconst pending = new WeakMap();\n\n/** Enable Three's existing TSL handler only when an enabled asset needs it.\n * Hosts with their own compiler advertise supportsNodeMaterials to retain it.\n * @param {ImpostorRenderer | undefined} renderer */\nexport async function enableRendererNodeMaterials(renderer) {\n\tif (rendererSupportsImpostorNodeMaterials(renderer) ||\n\t\t!renderer?.isWebGLRenderer || !renderer.setNodesHandler ||\n\t\ttypeof Reflect.get(TSL, 'struct') !== 'function') return;\n\tlet setup = pending.get(renderer);\n\tif (!setup) {\n\t\tsetup = import('three/addons/tsl/WebGLNodesHandler.js').then(({WebGLNodesHandler}) => {\n\t\t\tif (rendererSupportsImpostorNodeMaterials(renderer)) return;\n\t\t\trenderer.setNodesHandler?.(new WebGLNodesHandler());\n\t\t\trenderer.capabilities ??= {};\n\t\t\trenderer.capabilities.supportsNodeMaterials = true;\n\t\t}).catch(error => {\n\t\t\tpending.delete(renderer);\n\t\t\tthrow error;\n\t\t});\n\t\tpending.set(renderer, setup);\n\t}\n\tawait setup;\n}\n\n"],
|
|
5
|
-
"mappings": ";;;AACA,YAAY,SAAS;
|
|
3
|
+
"sources": ["../../../src/rendering/renderer-support.js", "../../../src/rendering/classic-webgl-support.js"],
|
|
4
|
+
"sourcesContent": ["// @ts-check\nimport {REVISION} from 'three';\nimport * as TSL from 'three/tsl';\nimport {classicWebGLSupportsNodeMaterials} from './classic-webgl-support.js';\n\n/**\n * @typedef {object} ImpostorRenderer\n * @property {boolean=} isWebGPURenderer\n * @property {boolean=} isWebGLRenderer\n * @property {(object & {supportsNodeMaterials?: boolean})=} capabilities\n * @property {((handler: import('three/addons/tsl/WebGLNodesHandler.js').WebGLNodesHandler) => void)=} setNodesHandler\n */\n\n/**\n * Reports whether a renderer can compile Baker's TSL impostor material.\n * WebGPURenderer supports node materials directly. Classic WebGLRenderer\n * integrations must advertise that they installed a compatible nodes handler.\n *\n * @param {ImpostorRenderer | undefined} renderer\n */\nexport function rendererSupportsImpostorNodeMaterials(renderer) {\n\tif (typeof Reflect.get(TSL, 'struct') !== 'function') return false;\n\treturn renderer?.isWebGPURenderer === true\n\t\t|| renderer?.capabilities?.supportsNodeMaterials === true;\n}\n\n/** @type {WeakMap<ImpostorRenderer, Promise<void>>} */\nconst pending = new WeakMap();\n\n/** Enable Three's existing TSL handler only when an enabled asset needs it.\n * Hosts with their own compiler advertise supportsNodeMaterials to retain it.\n * @param {ImpostorRenderer | undefined} renderer */\nexport async function enableRendererNodeMaterials(renderer) {\n\tif (rendererSupportsImpostorNodeMaterials(renderer) ||\n\t\t!renderer?.isWebGLRenderer || !renderer.setNodesHandler ||\n\t\ttypeof Reflect.get(TSL, 'struct') !== 'function') return;\n\tlet setup = pending.get(renderer);\n\tif (!setup) {\n\t\tsetup = import('three/addons/tsl/WebGLNodesHandler.js').then(({WebGLNodesHandler}) => {\n\t\t\tif (rendererSupportsImpostorNodeMaterials(renderer)) return;\n\t\t\tif (!classicWebGLSupportsNodeMaterials(REVISION)) {\n\t\t\t\tconsole.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.`);\n\t\t\t}\n\t\t\trenderer.setNodesHandler?.(new WebGLNodesHandler());\n\t\t\trenderer.capabilities ??= {};\n\t\t\trenderer.capabilities.supportsNodeMaterials = true;\n\t\t}).catch(error => {\n\t\t\tpending.delete(renderer);\n\t\t\tthrow error;\n\t\t});\n\t\tpending.set(renderer, setup);\n\t}\n\tawait setup;\n}\n\n", "// @ts-check\n\n/**\n * Reports whether WebGLRenderer from a three revision can keep many node\n * materials alive. Before r187 every uniform block holds one of a few binding\n * points until its material is disposed, so node materials stop drawing after\n * about a dozen. The Needle fork backports the fix from 0.186.2-alpha.2.\n *\n * @param {string} revision three's `REVISION`, such as `'187'` or `'186.2-alpha.2'`\n */\nexport function classicWebGLSupportsNodeMaterials(revision) {\n\tconst fork = /^186\\.2-alpha\\.(\\d+)$/.exec(revision);\n\tif (fork) return Number(fork[1]) >= 2;\n\treturn Number.parseInt(revision, 10) >= 187;\n}\n"],
|
|
5
|
+
"mappings": ";;;AACA,SAAQ,gBAAe;AACvB,YAAY,SAAS;;;ACQd,SAAS,kCAAkC,UAAU;AAC3D,QAAM,OAAO,wBAAwB,KAAK,QAAQ;AAClD,MAAI,KAAM,QAAO,OAAO,KAAK,CAAC,CAAC,KAAK;AACpC,SAAO,OAAO,SAAS,UAAU,EAAE,KAAK;AACzC;;;ADMO,SAAS,sCAAsC,UAAU;AAC/D,MAAI,OAAO,QAAQ,IAAI,KAAK,QAAQ,MAAM,WAAY,QAAO;AAC7D,SAAO,UAAU,qBAAqB,QAClC,UAAU,cAAc,0BAA0B;AACvD;AAGA,IAAM,UAAU,oBAAI,QAAQ;AAK5B,eAAsB,4BAA4B,UAAU;AAC3D,MAAI,sCAAsC,QAAQ,KACjD,CAAC,UAAU,mBAAmB,CAAC,SAAS,mBACxC,OAAO,QAAQ,IAAI,KAAK,QAAQ,MAAM,WAAY;AACnD,MAAI,QAAQ,QAAQ,IAAI,QAAQ;AAChC,MAAI,CAAC,OAAO;AACX,YAAQ,OAAO,uCAAuC,EAAE,KAAK,CAAC,EAAC,kBAAiB,MAAM;AACrF,UAAI,sCAAsC,QAAQ,EAAG;AACrD,UAAI,CAAC,kCAAkC,QAAQ,GAAG;AACjD,gBAAQ,KAAK,2CAA2C,QAAQ,2GAA2G;AAAA,MAC5K;AACA,eAAS,kBAAkB,IAAI,kBAAkB,CAAC;AAClD,eAAS,iBAAiB,CAAC;AAC3B,eAAS,aAAa,wBAAwB;AAAA,IAC/C,CAAC,EAAE,MAAM,WAAS;AACjB,cAAQ,OAAO,QAAQ;AACvB,YAAM;AAAA,IACP,CAAC;AACD,YAAQ,IAAI,UAAU,KAAK;AAAA,EAC5B;AACA,QAAM;AACP;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -236,6 +236,7 @@ import {
|
|
|
236
236
|
transformNormalToView,
|
|
237
237
|
uint,
|
|
238
238
|
uniform,
|
|
239
|
+
uvec2,
|
|
239
240
|
uvec4,
|
|
240
241
|
uv,
|
|
241
242
|
vec2,
|
|
@@ -327,9 +328,10 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
327
328
|
mod(index, dimensions2[0]).add(0.5).div(dimensions2[0]),
|
|
328
329
|
index.div(dimensions2[0]).floor().add(0.5).div(dimensions2[1])
|
|
329
330
|
);
|
|
331
|
+
const loadTexel = (map, atlasUv) => texture(map).load(uvec2(atlasUv.mul(vec2(Number(map.image.width), Number(map.image.height))).floor()));
|
|
330
332
|
const sparseUint = (texel) => {
|
|
331
333
|
if (!indexAtlas) throw new Error("Sparse pixel impostor requires an index atlas");
|
|
332
|
-
const bytes = uvec4(
|
|
334
|
+
const bytes = uvec4(loadTexel(indexAtlas, linearTextureUv(texel, indexAtlasSize)).mul(255).round());
|
|
333
335
|
return bytes.x.bitOr(bytes.y.shiftLeft(8)).bitOr(bytes.z.shiftLeft(16)).bitOr(bytes.w.shiftLeft(24));
|
|
334
336
|
};
|
|
335
337
|
const traceVolumeNode = Fn2(([sampleOffset]) => {
|
|
@@ -359,13 +361,13 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
359
361
|
const gridVelocity = rayDirection.div(sizeNode).mul(volumeDimensions);
|
|
360
362
|
const gridPoint = entry.add(raycastOffsetNode).div(sizeNode).add(0.5).mul(volumeDimensions).add(gridVelocity.mul(minimumCellSize * 1e-3));
|
|
361
363
|
const cell = exitDistance.greaterThanEqual(nearestDistance).select(gridPoint.floor(), vec3(-1)).toVar();
|
|
362
|
-
const directionStep = step(0, gridVelocity).mul(2).sub(1);
|
|
364
|
+
const directionStep = step(0, gridVelocity).mul(2).sub(1).toVar();
|
|
363
365
|
const absoluteVelocity = abs(gridVelocity).max(1e-6);
|
|
364
366
|
const cellFraction = gridPoint.sub(cell);
|
|
365
367
|
const positiveAxis = step(0, gridVelocity);
|
|
366
368
|
const nextDistance = cellFraction.mul(vec3(1).sub(positiveAxis)).add(vec3(1).sub(cellFraction).mul(positiveAxis));
|
|
367
369
|
const nextCrossing = nextDistance.div(absoluteVelocity).toVar();
|
|
368
|
-
const crossingDelta = vec3(1).div(absoluteVelocity);
|
|
370
|
+
const crossingDelta = vec3(1).div(absoluteVelocity).toVar();
|
|
369
371
|
const result = vec43(0, 0, 0, 0).toVar();
|
|
370
372
|
const travelled = nearestDistance.toVar();
|
|
371
373
|
Loop(maximumSteps, () => {
|
|
@@ -387,7 +389,7 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
387
389
|
atlasColumn.mul(planar).add(cell.x).add(0.5).div(atlasColumns * planar),
|
|
388
390
|
atlasRow.mul(planar).add(cell.z).add(0.5).div(atlasRows * planar)
|
|
389
391
|
);
|
|
390
|
-
cellOccupied =
|
|
392
|
+
cellOccupied = loadTexel(atlas, atlasUv).a.greaterThan(0.5);
|
|
391
393
|
}
|
|
392
394
|
If(cellOccupied, () => {
|
|
393
395
|
result.assign(vec43(
|
|
@@ -458,8 +460,8 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
458
460
|
hitAtlasRow.mul(planar).add(hitCell.z).add(0.5).div(atlasRows * planar)
|
|
459
461
|
);
|
|
460
462
|
}
|
|
461
|
-
const baseSample =
|
|
462
|
-
const ormSample = ormAtlas ?
|
|
463
|
+
const baseSample = loadTexel(atlas, hitAtlasUv);
|
|
464
|
+
const ormSample = ormAtlas ? loadTexel(ormAtlas, hitAtlasUv) : vec43(1, 1, 0, 1);
|
|
463
465
|
const hitPosition = hit.xyz;
|
|
464
466
|
const hitToCamera = modelWorldMatrixInverse.mul(vec43(cameraPosition, 1)).xyz.sub(hitPosition);
|
|
465
467
|
const faceSign = step(0, hitToCamera).mul(2).sub(1);
|
|
@@ -475,7 +477,7 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
475
477
|
const yFaceScore = absoluteCellDelta.y.greaterThanEqual(boundaryDistance.sub(1e-4)).select(faceDirection.y, -1);
|
|
476
478
|
const zFaceScore = absoluteCellDelta.z.greaterThanEqual(boundaryDistance.sub(1e-4)).select(faceDirection.z, -1);
|
|
477
479
|
const geometricNormal = xFaceScore.greaterThanEqual(yFaceScore).and(xFaceScore.greaterThanEqual(zFaceScore)).select(vec3(faceSign.x, 0, 0), yFaceScore.greaterThanEqual(zFaceScore).select(vec3(0, faceSign.y, 0), vec3(0, 0, faceSign.z)));
|
|
478
|
-
const sampledNormal = normalAtlas ?
|
|
480
|
+
const sampledNormal = normalAtlas ? loadTexel(normalAtlas, hitAtlasUv).xyz.mul(2).sub(1) : geometricNormal;
|
|
479
481
|
const bakedNormal = sampledNormal.dot(sampledNormal).greaterThan(1e-8).select(sampledNormal.normalize(), geometricNormal);
|
|
480
482
|
const projectedNormal = bakedNormal.dot(geometricNormal).lessThan(0).select(bakedNormal.negate(), bakedNormal);
|
|
481
483
|
const shadingNormal = mix(geometricNormal, projectedNormal, projectedNormalMix).normalize();
|