@needle-tools/three-mesh-effects 0.3.7 → 0.4.0

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +14 -1
  3. package/build/box-impostor-runtime.js +321 -195
  4. package/build/box-impostor-runtime.js.map +4 -4
  5. package/build/impostor-runtime.js +944 -202
  6. package/build/impostor-runtime.js.map +4 -4
  7. package/build/index.js +7 -7
  8. package/build/index.js.map +2 -2
  9. package/build/internal/box-impostor/box-impostor-display.js +319 -193
  10. package/build/internal/box-impostor/box-impostor-display.js.map +4 -4
  11. package/build/internal/box-impostor/box-impostor-faces.js +8 -6
  12. package/build/internal/box-impostor/box-impostor-faces.js.map +2 -2
  13. package/build/internal/box-impostor/box-impostor-material.js +319 -193
  14. package/build/internal/box-impostor/box-impostor-material.js.map +4 -4
  15. package/build/internal/box-impostor/box-impostor-projection.js +8 -5
  16. package/build/internal/box-impostor/box-impostor-projection.js.map +2 -2
  17. package/build/internal/box-impostor/box-impostor-runtime.js +321 -195
  18. package/build/internal/box-impostor/box-impostor-runtime.js.map +4 -4
  19. package/build/internal/impostor/adaptive-impostor-renderer.js +434 -0
  20. package/build/internal/impostor/adaptive-impostor-renderer.js.map +7 -0
  21. package/build/internal/impostor/impostor-node-material.js +944 -202
  22. package/build/internal/impostor/impostor-node-material.js.map +4 -4
  23. package/build/internal/impostor/impostor-performance.js +136 -0
  24. package/build/internal/impostor/impostor-performance.js.map +7 -0
  25. package/build/internal/pixel-impostor/pixel-impostor-runtime.js +6 -1
  26. package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +2 -2
  27. package/build/internal/rendering/instance-space.js +110 -0
  28. package/build/internal/rendering/instance-space.js.map +7 -0
  29. package/build/internal/rendering/renderer-support.js +6 -1
  30. package/build/internal/rendering/renderer-support.js.map +2 -2
  31. package/build/pixel-impostor-runtime.js +6 -1
  32. package/build/pixel-impostor-runtime.js.map +2 -2
  33. package/build/types/box-impostor/box-impostor-faces.d.ts +3 -1
  34. package/build/types/box-impostor/box-impostor-projection.d.ts +3 -1
  35. package/build/types/impostor/adaptive-impostor-renderer.d.ts +74 -0
  36. package/build/types/impostor/adaptive-impostor-renderer.js +1 -0
  37. package/build/types/impostor/impostor-node-material.d.ts +5 -1
  38. package/build/types/impostor/impostor-performance.d.ts +90 -0
  39. package/build/types/impostor/impostor-performance.js +1 -0
  40. package/build/types/public/impostor-runtime.d.ts +2 -0
  41. package/build/types/public/index.d.ts +3 -0
  42. package/build/types/rendering/instance-space.d.ts +26 -0
  43. package/build/types/rendering/instance-space.js +1 -0
  44. package/build/types/rendering/renderer-support.d.ts +13 -0
  45. package/package.json +2 -2
  46. package/src/box-impostor/box-impostor-faces.js +7 -5
  47. package/src/box-impostor/box-impostor-material.js +34 -19
  48. package/src/box-impostor/box-impostor-projection.js +7 -4
  49. package/src/impostor/adaptive-impostor-renderer.js +423 -0
  50. package/src/impostor/impostor-node-material.js +347 -157
  51. package/src/impostor/impostor-performance.js +152 -0
  52. package/src/public/impostor-runtime.js +2 -0
  53. package/src/public/index.js +12 -9
  54. package/src/rendering/instance-space.js +121 -0
  55. package/src/rendering/renderer-support.js +9 -0
@@ -89,8 +89,8 @@ function parseBoxImpostorDescriptor(raw) {
89
89
  fail();
90
90
  for (let i = 0; i < 3; i++)
91
91
  for (let j = 0; j < 3; j++) {
92
- const dot4 = b.axes[i].reduce((s, v, k) => s + v * b.axes[j][k], 0);
93
- if (Math.abs(dot4 - (i === j ? 1 : 0)) > 1e-4) fail();
92
+ const dot5 = b.axes[i].reduce((s, v, k) => s + v * b.axes[j][k], 0);
93
+ if (Math.abs(dot5 - (i === j ? 1 : 0)) > 1e-4) fail();
94
94
  }
95
95
  const [x, y, z] = b.axes;
96
96
  if ((x[1] * y[2] - x[2] * y[1]) * z[0] + (x[2] * y[0] - x[0] * y[2]) * z[1] + (x[0] * y[1] - x[1] * y[0]) * z[2] < 0.999)
@@ -269,9 +269,9 @@ function capturedSurfaceDepth(position, shadowBias = 0) {
269
269
 
270
270
  // src/box-impostor/box-impostor-material.js
271
271
  import {
272
- DataTexture as DataTexture3,
273
- FloatType as FloatType3,
274
- RGBAFormat as RGBAFormat3,
272
+ DataTexture as DataTexture4,
273
+ FloatType as FloatType4,
274
+ RGBAFormat as RGBAFormat4,
275
275
  RedIntegerFormat,
276
276
  UnsignedIntType,
277
277
  NearestFilter as NearestFilter3,
@@ -286,27 +286,27 @@ import {
286
286
  Loop as Loop2,
287
287
  Break,
288
288
  attribute as attribute3,
289
- varying,
290
- positionLocal as positionLocal2,
289
+ varying as varying2,
290
+ positionGeometry as positionGeometry2,
291
291
  positionViewDirection,
292
292
  modelWorldMatrixInverse,
293
293
  cameraPosition,
294
294
  cameraWorldMatrix,
295
295
  cameraProjectionMatrix as cameraProjectionMatrix2,
296
296
  vec2 as vec24,
297
- vec3 as vec34,
298
- vec4 as vec45,
297
+ vec3 as vec35,
298
+ vec4 as vec46,
299
299
  float as float4,
300
- int as int4,
300
+ int as int5,
301
301
  uint as uint2,
302
- dot as dot3,
302
+ dot as dot4,
303
303
  abs as abs3,
304
304
  max as max4,
305
305
  min as min2,
306
306
  sign as sign3,
307
307
  texture as texture3,
308
- textureLoad as textureLoad4,
309
- ivec2 as ivec24,
308
+ textureLoad as textureLoad5,
309
+ ivec2 as ivec25,
310
310
  normalize as normalize2,
311
311
  floor as floor2,
312
312
  fract,
@@ -317,9 +317,114 @@ import {
317
317
  uniform
318
318
  } from "three/tsl";
319
319
 
320
+ // src/rendering/instance-space.js
321
+ import { DataTexture, DynamicDrawUsage, FloatType, InstancedInterleavedBuffer, InterpolationSamplingType, NodeUpdateType, RGBAFormat } from "three/webgpu";
322
+ import { cross, dot, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, ivec2, textureLoad, varying, vec3, vec4 as vec42 } from "three/tsl";
323
+ var spaces = /* @__PURE__ */ new WeakMap();
324
+ var webglSpaces = /* @__PURE__ */ new WeakMap();
325
+ function instanceColumns(object, matrix, useTexture) {
326
+ const columns = [0, 1, 2, 3];
327
+ if (useTexture) {
328
+ const rowSize = Math.ceil(Math.sqrt(matrix.count) / 2);
329
+ const rows = Math.ceil(matrix.count / rowSize);
330
+ const data = new Float32Array(rowSize * rows * 16);
331
+ const texture4 = new DataTexture(data, rowSize * 4, rows, RGBAFormat, FloatType);
332
+ const upload = () => {
333
+ data.set(matrix.array);
334
+ texture4.needsUpdate = true;
335
+ };
336
+ upload();
337
+ const release = () => {
338
+ object.removeEventListener("dispose", release);
339
+ texture4.dispose();
340
+ webglSpaces.delete(matrix);
341
+ };
342
+ object.addEventListener("dispose", release);
343
+ const x = instanceIndex.mod(rowSize).mul(4);
344
+ const y = instanceIndex.div(rowSize);
345
+ return { nodes: columns.map((column) => textureLoad(texture4, ivec2(int(x.add(column)), int(y)))), upload };
346
+ }
347
+ const interleaved = new InstancedInterleavedBuffer(matrix.array, 16, 1);
348
+ const read = matrix.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
349
+ return {
350
+ nodes: columns.map((column) => read(
351
+ interleaved,
352
+ /** @type {const} */
353
+ "vec4",
354
+ 16,
355
+ column * 4
356
+ )),
357
+ upload: () => {
358
+ interleaved.needsUpdate = true;
359
+ }
360
+ };
361
+ }
362
+ function instanceSpace(builder) {
363
+ const object = (
364
+ /** @type {InstancedMesh} */
365
+ builder.object
366
+ );
367
+ const matrix = object?.isInstancedMesh ? object.instanceMatrix : null;
368
+ if (!matrix) return null;
369
+ const backend = (
370
+ /** @type {{isWebGPUBackend?: boolean} | undefined} */
371
+ builder.renderer.backend
372
+ );
373
+ const useTexture = !backend?.isWebGPUBackend && matrix.count * 64 > (builder.getUniformBufferLimit?.() ?? 16384);
374
+ const cache = useTexture ? webglSpaces : spaces;
375
+ const cached = cache.get(matrix);
376
+ if (cached) return cached;
377
+ const { nodes, upload } = instanceColumns(object, matrix, useTexture);
378
+ let version = matrix.version;
379
+ nodes[0].updateBeforeType = NodeUpdateType.OBJECT;
380
+ nodes[0].updateBefore = () => {
381
+ if (matrix.version !== version) {
382
+ version = matrix.version;
383
+ upload();
384
+ }
385
+ return void 0;
386
+ };
387
+ const [a, b, c, d] = nodes.map((node) => node.xyz);
388
+ const determinant = dot(a, cross(b, c));
389
+ const rows = [cross(b, c), cross(c, a), cross(a, b)].map((row) => row.div(determinant));
390
+ const toLocalDirection = (v) => vec3(dot(rows[0], v), dot(rows[1], v), dot(rows[2], v));
391
+ const toMeshDirection = (v) => a.mul(v.x).add(b.mul(v.y)).add(c.mul(v.z));
392
+ const translation = [d.x, d.y, d.z];
393
+ const packed = [a, b, c].map(
394
+ (column, k) => varying(vec42(column, translation[k]), `instanceSpace${k}`).setInterpolation(InterpolationSamplingType.FLAT)
395
+ );
396
+ const [fa, fb, fc] = packed.map((column) => column.xyz);
397
+ const cofactors = () => [cross(fb, fc), cross(fc, fa), cross(fa, fb)];
398
+ const space = {
399
+ toLocalPoint: (p) => toLocalDirection(p.sub(d)),
400
+ toLocalDirection,
401
+ toMeshPoint: (p) => toMeshDirection(p).add(d),
402
+ toMeshDirection,
403
+ fragment: {
404
+ toMeshPoint: (p) => fa.mul(p.x).add(fb.mul(p.y)).add(fc.mul(p.z)).add(vec3(packed[0].w, packed[1].w, packed[2].w)),
405
+ toMeshDirection: (v) => fa.mul(v.x).add(fb.mul(v.y)).add(fc.mul(v.z)),
406
+ toMeshNormal: (n) => {
407
+ const [x, y, z] = cofactors();
408
+ return x.mul(n.x).add(y.mul(n.y)).add(z.mul(n.z)).mul(dot(fa, x).sign()).normalize();
409
+ },
410
+ toLocalDirection: (v) => {
411
+ const [x, y, z] = cofactors();
412
+ return vec3(dot(x, v), dot(y, v), dot(z, v)).div(dot(fa, x));
413
+ },
414
+ toLocalPoint: (p) => {
415
+ const [x, y, z] = cofactors();
416
+ const v = p.sub(vec3(packed[0].w, packed[1].w, packed[2].w));
417
+ return vec3(dot(x, v), dot(y, v), dot(z, v)).div(dot(fa, x));
418
+ }
419
+ }
420
+ };
421
+ cache.set(matrix, space);
422
+ return space;
423
+ }
424
+
320
425
  // src/rendering/captured-surface-material.js
321
426
  import { MeshStandardNodeMaterial } from "three/webgpu";
322
- import { context, modelViewMatrix as modelViewMatrix2, modelWorldMatrix, vec4 as vec42 } from "three/tsl";
427
+ import { context, modelViewMatrix as modelViewMatrix2, modelWorldMatrix, vec4 as vec43 } from "three/tsl";
323
428
  var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
324
429
  /** @type {import('three/webgpu').Node<'vec3'> | null} */
325
430
  capturedPositionNode = null;
@@ -330,8 +435,8 @@ var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
330
435
  setupLighting(builder) {
331
436
  const lighting = super.setupLighting(builder);
332
437
  if (!this.capturedPositionNode) return lighting;
333
- const world = modelWorldMatrix.mul(vec42(this.capturedPositionNode, 1)).xyz;
334
- const view = modelViewMatrix2.mul(vec42(this.capturedPositionNode, 1)).xyz;
438
+ const world = modelWorldMatrix.mul(vec43(this.capturedPositionNode, 1)).xyz;
439
+ const view = modelViewMatrix2.mul(vec43(this.capturedPositionNode, 1)).xyz;
335
440
  return context(lighting, {
336
441
  positionView: view,
337
442
  positionWorld: world,
@@ -341,7 +446,7 @@ var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
341
446
  };
342
447
 
343
448
  // src/box-impostor/box-impostor-ray-bounds.js
344
- import { Matrix4, NodeUpdateType, StorageBufferAttribute, Vector3 } from "three/webgpu";
449
+ import { Matrix4, NodeUpdateType as NodeUpdateType2, StorageBufferAttribute, Vector3 } from "three/webgpu";
345
450
  import {
346
451
  Fn as Fn2,
347
452
  If,
@@ -351,17 +456,17 @@ import {
351
456
  clamp,
352
457
  float,
353
458
  floor,
354
- instanceIndex,
355
- int,
356
- ivec2,
459
+ instanceIndex as instanceIndex2,
460
+ int as int2,
461
+ ivec2 as ivec22,
357
462
  max,
358
463
  min,
359
464
  storage,
360
- textureLoad,
465
+ textureLoad as textureLoad2,
361
466
  uint,
362
467
  vec2,
363
- vec3,
364
- vec4 as vec43
468
+ vec3 as vec32,
469
+ vec4 as vec44
365
470
  } from "three/tsl";
366
471
  var MIN_TILE_SIZE = 3;
367
472
  var MAX_CAPTURE_TILES = 512 * 1024;
@@ -404,18 +509,18 @@ function buildPatches(descriptor, maps, rects, tiles, size, output) {
404
509
  const descriptions = storage(tiles, "vec4", tiles.count).toReadOnly();
405
510
  const patches = storage(output, "vec4", output.count);
406
511
  return Fn2(() => {
407
- const meta = descriptions.element(instanceIndex).toVar();
408
- const key = int(meta.x), face = key.mod(6), axis = face.div(2);
409
- const rect = textureLoad(rects, ivec2(face, key.div(6))).mul(descriptor.atlasResolution).round().toVar();
410
- const extent = ivec2(rect.zw.add(1).sub(meta.yz)).min(ivec2(size));
411
- const origin = ivec2(rect.xy.add(meta.yz));
512
+ const meta = descriptions.element(instanceIndex2).toVar();
513
+ const key = int2(meta.x), face = key.mod(6), axis = face.div(2);
514
+ const rect = textureLoad2(rects, ivec22(face, key.div(6))).mul(descriptor.atlasResolution).round().toVar();
515
+ const extent = ivec22(rect.zw.add(1).sub(meta.yz)).min(ivec22(size));
516
+ const origin = ivec22(rect.xy.add(meta.yz));
412
517
  const near = float(1).toVar(), far = float(0).toVar();
413
518
  function visit(process) {
414
- Loop({ start: int(0), end: extent.y, type: "int", name: "row" }, ({ row }) => {
415
- Loop({ start: int(0), end: extent.x, type: "int", name: "column" }, ({ column }) => {
416
- const pixel = origin.add(ivec2(column, row));
417
- If(textureLoad(maps.orm, pixel).a.greaterThan(0.5), () => {
418
- const packed = textureLoad(maps.normalDepth, pixel);
519
+ Loop({ start: int2(0), end: extent.y, type: "int", name: "row" }, ({ row }) => {
520
+ Loop({ start: int2(0), end: extent.x, type: "int", name: "column" }, ({ column }) => {
521
+ const pixel = origin.add(ivec22(column, row));
522
+ If(textureLoad2(maps.orm, pixel).a.greaterThan(0.5), () => {
523
+ const packed = textureLoad2(maps.normalDepth, pixel);
419
524
  const depth = packed.b.mul(65280).add(packed.a.mul(255)).div(DEPTH_MAX).toVar();
420
525
  process(column, row, depth);
421
526
  });
@@ -427,11 +532,11 @@ function buildPatches(descriptor, maps, rects, tiles, size, output) {
427
532
  far.assign(max(far, depth));
428
533
  });
429
534
  const middle = near.add(far).mul(0.5).toVar();
430
- const low = [vec3(2).toVar(), vec3(2).toVar()], high = [vec3(-2).toVar(), vec3(-2).toVar()];
535
+ const low = [vec32(2).toVar(), vec32(2).toVar()], high = [vec32(-2).toVar(), vec32(-2).toVar()];
431
536
  visit((x, y, depth) => {
432
537
  const uv2 = meta.yz.add(vec2(x, y)).div(rect.zw).mul(2).sub(1);
433
- const lo = vec3(uv2.clamp(-1, 1), float(1).sub(depth.mul(2)).sub(meta.w).max(-1)).toVar();
434
- const hi = vec3(
538
+ const lo = vec32(uv2.clamp(-1, 1), float(1).sub(depth.mul(2)).sub(meta.w).max(-1)).toVar();
539
+ const hi = vec32(
435
540
  uv2.add(vec2(2).div(rect.zw)).clamp(-1, 1),
436
541
  float(1).sub(depth.mul(2)).add(meta.w).min(1)
437
542
  ).toVar();
@@ -448,38 +553,38 @@ function buildPatches(descriptor, maps, rects, tiles, size, output) {
448
553
  });
449
554
  });
450
555
  const facing = face.mod(2).equal(0).select(1, -1);
451
- const right = axis.equal(0).select(vec3(0, 0, facing.negate()), axis.equal(1).select(vec3(1, 0, 0), vec3(facing, 0, 0)));
452
- const up = axis.equal(1).select(vec3(0, 0, facing.negate()), vec3(0, 1, 0));
556
+ const right = axis.equal(0).select(vec32(0, 0, facing.negate()), axis.equal(1).select(vec32(1, 0, 0), vec32(facing, 0, 0)));
557
+ const up = axis.equal(1).select(vec32(0, 0, facing.negate()), vec32(0, 1, 0));
453
558
  const normal = right.cross(up);
454
559
  const rotate = (p) => right.mul(p.x).add(up.mul(p.y)).add(normal.mul(p.z));
455
560
  for (let group = 0; group < 2; group++) {
456
- const a = rotate(low[group]), b = rotate(high[group]), slot = instanceIndex.mul(4).add(group * 2);
561
+ const a = rotate(low[group]), b = rotate(high[group]), slot = instanceIndex2.mul(4).add(group * 2);
457
562
  const valid = low[group].x.lessThanEqual(high[group].x);
458
- patches.element(slot).assign(vec43(min(a, b), valid.select(meta.x, -1)));
459
- patches.element(slot.add(1)).assign(vec43(max(a, b), 0));
563
+ patches.element(slot).assign(vec44(min(a, b), valid.select(meta.x, -1)));
564
+ patches.element(slot.add(1)).assign(vec44(max(a, b), 0));
460
565
  }
461
566
  })().compute(tiles.count);
462
567
  }
463
568
  function makeViewPasses(patchBuffer, views, ranges, count, resolution) {
464
569
  const table = storage(ranges, "uint", count).toAtomic();
465
570
  const reset = Fn2(() => {
466
- atomicStore(table.element(instanceIndex), uint(DEPTH_MAX));
571
+ atomicStore(table.element(instanceIndex2), uint(DEPTH_MAX));
467
572
  })().compute(count);
468
573
  const patches = storage(patchBuffer, "vec4", patchBuffer.count).toReadOnly();
469
574
  const scatter = Fn2(() => {
470
- const a = patches.element(instanceIndex.mul(2)).toVar(), b = patches.element(instanceIndex.mul(2).add(1)).toVar();
575
+ const a = patches.element(instanceIndex2.mul(2)).toVar(), b = patches.element(instanceIndex2.mul(2).add(1)).toVar();
471
576
  If(a.w.greaterThanEqual(0), () => {
472
- const key = int(a.w), box = key.div(6);
577
+ const key = int2(a.w), box = key.div(6);
473
578
  const mapping = views.element(box.mul(2)), reference = views.element(box.mul(2).add(1));
474
579
  If(reference.w.greaterThanEqual(0), () => {
475
- const axis = int(reference.w).mod(3), x = axis.add(1).mod(3), y = axis.add(2).mod(3);
580
+ const axis = int2(reference.w).mod(3), x = axis.add(1).mod(3), y = axis.add(2).mod(3);
476
581
  const e = vec2(reference.element(x), reference.element(y)), ez = reference.element(axis);
477
582
  const za = a.element(axis), zb = b.element(axis);
478
583
  const weight = reference.w.lessThan(3).select(1, 0).toVar();
479
584
  const eyeSlope = e.div(ez).toVar(), inverseDistance = weight.div(ez).toVar();
480
585
  const project = (v, z) => v.sub(eyeSlope.mul(z)).div(float(1).sub(inverseDistance.mul(z)));
481
586
  const l = vec2(a.element(x), a.element(y)), h = vec2(b.element(x), b.element(y));
482
- const cell = (v, bias) => ivec2(floor(v.sub(mapping.xy).mul(mapping.zw).add(bias)).clamp(0, resolution - 1));
587
+ const cell = (v, bias) => ivec22(floor(v.sub(mapping.xy).mul(mapping.zw).add(bias)).clamp(0, resolution - 1));
483
588
  const lo = cell(min(project(l, za), project(l, zb)), -5e-3);
484
589
  const hi = cell(max(project(h, za), project(h, zb)), 5e-3);
485
590
  const padding = vec2(0.506).div(mapping.zw).mul(inverseDistance.abs().add(1)).add(2e-6);
@@ -631,7 +736,7 @@ function createBoxRayBounds(descriptor, maps, rects, material) {
631
736
  slot.ortho = ortho;
632
737
  slot.ready = true;
633
738
  }
634
- views.updateBeforeType = NodeUpdateType.OBJECT;
739
+ views.updateBeforeType = NodeUpdateType2.OBJECT;
635
740
  views.updateBefore = prepare;
636
741
  material.addEventListener("dispose", () => {
637
742
  for (const state of states.values()) {
@@ -653,7 +758,7 @@ function createBoxRayBounds(descriptor, maps, rects, material) {
653
758
  if (!builder.renderer.backend?.isWebGPUBackend) return null;
654
759
  const mapping = views.element(id.mul(2)).toVar();
655
760
  const ref = views.element(id.mul(2).add(1)).toVar();
656
- const axis = int(max(ref.w, 0)).mod(3), x = axis.add(1).mod(3), y = axis.add(2).mod(3);
761
+ const axis = int2(max(ref.w, 0)).mod(3), x = axis.add(1).mod(3), y = axis.add(2).mod(3);
657
762
  const rz = r.element(axis).toVar(), oz = o.element(axis).toVar();
658
763
  const ez = ref.element(axis), e = vec2(ref.element(x), ref.element(y));
659
764
  const eyeSlope = e.div(ez), inverseDistance = ref.w.lessThan(3).select(1, 0).div(ez);
@@ -663,9 +768,9 @@ function createBoxRayBounds(descriptor, maps, rects, material) {
663
768
  return p.sub(mapping.xy).mul(mapping.zw);
664
769
  };
665
770
  const a = project(enter).toVar(), b = project(exit).toVar();
666
- const cellLo = ivec2(floor(min(a, b).sub(1e-3)).clamp(0, resolution - 1)).toVar();
667
- const cellHi = ivec2(floor(max(a, b).add(1e-3)).clamp(0, resolution - 1)).toVar();
668
- const valid = ref.w.greaterThanEqual(0).and(rz.abs().greaterThan(1e-12)).and(cellHi.sub(cellLo).lessThanEqual(ivec2(2)).all()).toVar();
771
+ const cellLo = ivec22(floor(min(a, b).sub(1e-3)).clamp(0, resolution - 1)).toVar();
772
+ const cellHi = ivec22(floor(max(a, b).add(1e-3)).clamp(0, resolution - 1)).toVar();
773
+ const valid = ref.w.greaterThanEqual(0).and(rz.abs().greaterThan(1e-12)).and(cellHi.sub(cellLo).lessThanEqual(ivec22(2)).all()).toVar();
669
774
  return (face, enter2, exit2) => {
670
775
  const start = enter2.toVar(), end = exit2.toVar();
671
776
  If(valid, () => {
@@ -709,21 +814,21 @@ function refineSurfaceCrossing({ float: float5, If: If5, Loop: Loop3 }, { lo, hi
709
814
  }
710
815
 
711
816
  // src/box-impostor/box-impostor-faces.js
712
- import { DataTexture, FloatType, RGBAFormat, NearestFilter } from "three";
817
+ import { DataTexture as DataTexture2, FloatType as FloatType2, RGBAFormat as RGBAFormat2, NearestFilter } from "three";
713
818
  import {
714
819
  Fn as Fn3,
715
820
  If as If2,
716
821
  attribute,
717
- positionLocal,
822
+ positionGeometry,
718
823
  uv,
719
824
  texture,
720
- textureLoad as textureLoad2,
721
- ivec2 as ivec22,
825
+ textureLoad as textureLoad3,
826
+ ivec2 as ivec23,
722
827
  vec2 as vec22,
723
- vec3 as vec32,
828
+ vec3 as vec33,
724
829
  float as float2,
725
- int as int2,
726
- dot,
830
+ int as int3,
831
+ dot as dot2,
727
832
  abs,
728
833
  max as max2,
729
834
  sign,
@@ -737,45 +842,47 @@ function applyBoxFaces({
737
842
  transparency,
738
843
  half,
739
844
  toBox,
740
- fromBox
845
+ fromBox,
846
+ meshVertex,
847
+ meshNormal
741
848
  }) {
742
849
  const values = new Float32Array(descriptor.boxes.length * 6 * 4);
743
850
  descriptor.boxes.forEach((box, i) => {
744
851
  for (let face2 = 0; face2 < 6; face2++)
745
852
  values[(i * 6 + face2) * 4] = box.planes?.[face2] ?? 0.5;
746
853
  });
747
- const planes = new DataTexture(
854
+ const planes = new DataTexture2(
748
855
  values,
749
856
  6,
750
857
  descriptor.boxes.length,
751
- RGBAFormat,
752
- FloatType
858
+ RGBAFormat2,
859
+ FloatType2
753
860
  );
754
861
  planes.minFilter = planes.magFilter = NearestFilter;
755
862
  planes.needsUpdate = true;
756
863
  material.addEventListener("dispose", () => planes.dispose());
757
- const face = int2(attribute("boxFace", "float"));
864
+ const face = int3(attribute("boxFace", "float"));
758
865
  const n = attribute("normal", "vec3");
759
- const depth = textureLoad2(
866
+ const depth = textureLoad3(
760
867
  planes,
761
- ivec22(face, int2(attribute("boxId", "float")))
868
+ ivec23(face, int3(attribute("boxId", "float")))
762
869
  ).r;
763
- const proxy = positionLocal.sub(
870
+ const proxy = positionGeometry.sub(
764
871
  n.mul(
765
- dot(abs(toBox(n)), half).mul(depth).mul(2)
872
+ dot2(abs(toBox(n)), half).mul(depth).mul(2)
766
873
  )
767
874
  );
768
- material.positionNode = proxy;
769
- material.castShadowPositionNode = proxy;
875
+ material.positionNode = meshVertex(proxy);
876
+ material.castShadowPositionNode = material.positionNode;
770
877
  const base = texture(maps.baseColor, uv()).level(0).toVar("boxFaceColor");
771
878
  const orm = texture(maps.orm, uv()).level(0);
772
879
  const coverage = max2(orm.a, 1e-10);
773
880
  const normal = Fn3(() => {
774
- const packed = textureLoad2(
881
+ const packed = textureLoad3(
775
882
  maps.normalDepth,
776
- ivec22(uv().mul(descriptor.atlasResolution))
883
+ ivec23(uv().mul(descriptor.atlasResolution))
777
884
  ).rg.mul(2).sub(1);
778
- const decoded = vec32(
885
+ const decoded = vec33(
779
886
  packed,
780
887
  float2(1).sub(abs(packed.x)).sub(abs(packed.y))
781
888
  ).toVar();
@@ -784,13 +891,13 @@ function applyBoxFaces({
784
891
  vec22(1).sub(abs(decoded.yx)).mul(sign(decoded.xy.add(1e-20)))
785
892
  );
786
893
  });
787
- const result = vec32(0).toVar();
894
+ const result = vec33(0).toVar();
788
895
  for (let f = 0; f < 6; f++) {
789
896
  const a = BOX_FACE_AXES[f];
790
897
  If2(face.equal(f), () => {
791
898
  result.assign(
792
899
  fromBox(
793
- vec32(...a.right).mul(decoded.x).add(vec32(...a.up).mul(decoded.y)).add(vec32(...a.normal).mul(decoded.z))
900
+ vec33(...a.right).mul(decoded.x).add(vec33(...a.up).mul(decoded.y)).add(vec33(...a.normal).mul(decoded.z))
794
901
  ).normalize()
795
902
  );
796
903
  });
@@ -798,7 +905,7 @@ function applyBoxFaces({
798
905
  return result;
799
906
  })();
800
907
  material.colorNode = base.rgb.div(coverage);
801
- material.normalNode = transformNormalToView(normal);
908
+ material.normalNode = transformNormalToView(meshNormal(normal));
802
909
  material.roughnessNode = orm.g.div(coverage);
803
910
  material.metalnessNode = orm.b.div(coverage);
804
911
  material.aoNode = orm.r.div(coverage);
@@ -813,23 +920,23 @@ function applyBoxFaces({
813
920
  }
814
921
 
815
922
  // src/box-impostor/box-impostor-projection.js
816
- import { DataTexture as DataTexture2, FloatType as FloatType2, RGBAFormat as RGBAFormat2, NearestFilter as NearestFilter2 } from "three";
923
+ import { DataTexture as DataTexture3, FloatType as FloatType3, RGBAFormat as RGBAFormat3, NearestFilter as NearestFilter2 } from "three";
817
924
  import {
818
925
  Fn as Fn4,
819
926
  If as If3,
820
927
  vec2 as vec23,
821
- vec3 as vec33,
822
- vec4 as vec44,
928
+ vec3 as vec34,
929
+ vec4 as vec45,
823
930
  float as float3,
824
- int as int3,
825
- ivec2 as ivec23,
826
- dot as dot2,
931
+ int as int4,
932
+ ivec2 as ivec24,
933
+ dot as dot3,
827
934
  abs as abs2,
828
935
  max as max3,
829
936
  sign as sign2,
830
937
  normalize,
831
938
  texture as texture2,
832
- textureLoad as textureLoad3,
939
+ textureLoad as textureLoad4,
833
940
  attribute as attribute2,
834
941
  struct,
835
942
  modelWorldMatrix as modelWorldMatrix2,
@@ -850,19 +957,21 @@ function applyBoxProjection({
850
957
  eye,
851
958
  viewAxis,
852
959
  perspective,
853
- raster
960
+ raster,
961
+ meshPoint,
962
+ meshNormal
854
963
  }) {
855
964
  const data = new Float32Array(descriptor.boxes.length * 24);
856
965
  descriptor.boxes.forEach((box, i) => {
857
966
  for (let face = 0; face < 6; face++)
858
967
  data[(i * 6 + face) * 4] = box.planes?.[face] ?? 0.5;
859
968
  });
860
- const planes = new DataTexture2(
969
+ const planes = new DataTexture3(
861
970
  data,
862
971
  6,
863
972
  descriptor.boxes.length,
864
- RGBAFormat2,
865
- FloatType2
973
+ RGBAFormat3,
974
+ FloatType3
866
975
  );
867
976
  planes.minFilter = planes.magFilter = NearestFilter2;
868
977
  planes.needsUpdate = true;
@@ -879,11 +988,11 @@ function applyBoxProjection({
879
988
  "BoxProjectedSurface"
880
989
  );
881
990
  const readNormal = (uv2, right, up, n) => {
882
- const packed = textureLoad3(
991
+ const packed = textureLoad4(
883
992
  maps.normalDepth,
884
- ivec23(uv2.mul(descriptor.atlasResolution))
993
+ ivec24(uv2.mul(descriptor.atlasResolution))
885
994
  ).rg.mul(2).sub(1);
886
- const decoded = vec33(
995
+ const decoded = vec34(
887
996
  packed,
888
997
  float3(1).sub(abs2(packed.x)).sub(abs2(packed.y))
889
998
  ).toVar();
@@ -907,20 +1016,20 @@ function applyBoxProjection({
907
1016
  );
908
1017
  const o = toBox(origin.sub(center)).div(half), r = toBox(ray).div(half);
909
1018
  const look = normalize(toBox(ray).negate()), angles = abs2(look);
910
- const positions = vec33(0).toVar();
911
- const selectedUv = vec23(0).toVar(), selectedRight = vec33(1, 0, 0).toVar(), selectedUp = vec33(0, 1, 0).toVar(), selectedNormal = vec33(0, 0, 1).toVar();
1019
+ const positions = vec34(0).toVar();
1020
+ const selectedUv = vec23(0).toVar(), selectedRight = vec34(1, 0, 0).toVar(), selectedUp = vec34(0, 1, 0).toVar(), selectedNormal = vec34(0, 0, 1).toVar();
912
1021
  const nearest = float3(1e20).toVar("boxPlaneDistance");
913
1022
  const opacity = float3(0).toVar();
914
1023
  const candidates = [];
915
1024
  for (let axis = 0; axis < 3; axis++) {
916
1025
  const angle = angles.element(axis);
917
1026
  const positive = look.element(axis).greaterThanEqual(0), a = BOX_FACE_AXES[axis * 2], b = BOX_FACE_AXES[axis * 2 + 1];
918
- const n = positive.select(vec33(...a.normal), vec33(...b.normal)), right = positive.select(vec33(...a.right), vec33(...b.right)), up = positive.select(vec33(...a.up), vec33(...b.up));
1027
+ const n = positive.select(vec34(...a.normal), vec34(...b.normal)), right = positive.select(vec34(...a.right), vec34(...b.right)), up = positive.select(vec34(...a.up), vec34(...b.up));
919
1028
  const weight = settings.interpolation === "smooth" ? angle.mul(angle) : angle;
920
1029
  const candidate = settings.interpolation === "none" ? null : {
921
1030
  uv: vec23(0).toVar(),
922
- base: vec44(0).toVar(),
923
- orm: vec44(0).toVar(),
1031
+ base: vec45(0).toVar(),
1032
+ orm: vec45(0).toVar(),
924
1033
  t: float3(1e20).toVar(),
925
1034
  tolerance: float3(0).toVar(),
926
1035
  right,
@@ -930,17 +1039,17 @@ function applyBoxProjection({
930
1039
  };
931
1040
  if (candidate) candidates.push(candidate);
932
1041
  If3(angle.greaterThan(1e-4), () => {
933
- const face = positive.select(int3(axis * 2), int3(axis * 2 + 1)), id = int3(attribute2("boxId", "float"));
1042
+ const face = positive.select(int4(axis * 2), int4(axis * 2 + 1)), id = int4(attribute2("boxId", "float"));
934
1043
  const plane = float3(1).sub(
935
- textureLoad3(planes, ivec23(face, id)).r.mul(2)
1044
+ textureLoad4(planes, ivec24(face, id)).r.mul(2)
936
1045
  );
937
- const divisor2 = dot2(r, n), safe = sign2(divisor2.add(1e-20)).mul(max3(abs2(divisor2), 1e-10));
938
- const t = plane.sub(dot2(o, n)).div(safe), point = o.add(r.mul(t));
939
- const xy = vec23(dot2(point, right), dot2(point, up)).mul(0.5).add(0.5);
1046
+ const divisor2 = dot3(r, n), safe = sign2(divisor2.add(1e-20)).mul(max3(abs2(divisor2), 1e-10));
1047
+ const t = plane.sub(dot3(o, n)).div(safe), point = o.add(r.mul(t));
1048
+ const xy = vec23(dot3(point, right), dot3(point, up)).mul(0.5).add(0.5);
940
1049
  let supported = t.greaterThanEqual(0).and(xy.x.greaterThanEqual(0)).and(xy.y.greaterThanEqual(0)).and(xy.x.lessThanEqual(1)).and(xy.y.lessThanEqual(1));
941
1050
  if (!candidate) supported = supported.and(t.lessThan(nearest));
942
1051
  If3(supported, () => {
943
- const rect = textureLoad3(rects, ivec23(face, id)), uv2 = rect.xy.add(xy.mul(rect.zw));
1052
+ const rect = textureLoad4(rects, ivec24(face, id)), uv2 = rect.xy.add(xy.mul(rect.zw));
944
1053
  const base = texture2(maps.baseColor, uv2).level(0), orm = texture2(maps.orm, uv2).level(0);
945
1054
  const alpha2 = base.a.clamp(0, 1);
946
1055
  If3(
@@ -964,10 +1073,10 @@ function applyBoxProjection({
964
1073
  candidate.t.assign(t);
965
1074
  candidate.tolerance.assign(
966
1075
  max3(
967
- dot2(abs2(right), half).div(
1076
+ dot3(abs2(right), half).div(
968
1077
  rect.z.mul(descriptor.atlasResolution)
969
1078
  ),
970
- dot2(abs2(up), half).div(
1079
+ dot3(abs2(up), half).div(
971
1080
  rect.w.mul(descriptor.atlasResolution)
972
1081
  )
973
1082
  ).mul(4).div(max3(angle, 0.1))
@@ -990,7 +1099,7 @@ function applyBoxProjection({
990
1099
  positions
991
1100
  );
992
1101
  }
993
- const colors = vec33(0).toVar(), orms = vec33(0).toVar(), emissions = vec33(0).toVar(), normals = vec33(0).toVar();
1102
+ const colors = vec34(0).toVar(), orms = vec34(0).toVar(), emissions = vec34(0).toVar(), normals = vec34(0).toVar();
994
1103
  const weights = float3(0).toVar(), support = float3(0).toVar(), alpha = float3(0).toVar();
995
1104
  for (const c of candidates) {
996
1105
  If3(
@@ -1019,9 +1128,10 @@ function applyBoxProjection({
1019
1128
  positions
1020
1129
  );
1021
1130
  })().toVar("boxProjectedSurface");
1022
- material.capturedPositionNode = surface.get("position");
1131
+ const position = meshPoint(surface.get("position")).toVar("boxProjectedMeshPosition");
1132
+ material.capturedPositionNode = position;
1023
1133
  material.colorNode = surface.get("color");
1024
- material.normalNode = transformNormalToView2(surface.get("normal"));
1134
+ material.normalNode = transformNormalToView2(meshNormal(surface.get("normal")));
1025
1135
  material.roughnessNode = surface.get("orm").g;
1026
1136
  material.metalnessNode = surface.get("orm").b;
1027
1137
  material.aoNode = surface.get("orm").r;
@@ -1029,9 +1139,9 @@ function applyBoxProjection({
1029
1139
  material.maskNode = surface.get("alpha").greaterThanEqual(transparency === "cutout" ? alphaCutoff : float3(1 / 255));
1030
1140
  material.maskShadowNode = material.maskNode;
1031
1141
  if (transparency !== "cutout") material.opacityNode = surface.get("alpha");
1032
- material.depthNode = capturedSurfaceDepth(surface.get("position"));
1142
+ material.depthNode = capturedSurfaceDepth(position);
1033
1143
  material.receivedShadowPositionNode = modelWorldMatrix2.mul(
1034
- vec44(surface.get("position"), 1)
1144
+ vec45(position, 1)
1035
1145
  ).xyz;
1036
1146
  material.userData.boxImpostor = { descriptor, maps, alphaCutoff };
1037
1147
  return material;
@@ -1049,7 +1159,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1049
1159
  const surfaceCoverage = (ormAlpha, baseAlpha) => filtering && descriptor.alphaMode !== "blend" ? min2(ormAlpha, baseAlpha) : ormAlpha;
1050
1160
  const unpackNormal = (encoded) => {
1051
1161
  const packed = encoded.mul(2).sub(1);
1052
- const normal2 = vec34(packed, float4(1).sub(abs3(packed.x)).sub(abs3(packed.y))).toVar();
1162
+ const normal2 = vec35(packed, float4(1).sub(abs3(packed.x)).sub(abs3(packed.y))).toVar();
1053
1163
  If4(normal2.z.lessThan(0), () => {
1054
1164
  normal2.xy.assign(vec24(1).sub(abs3(normal2.yx)).mul(sign3(normal2.xy.add(1e-20))));
1055
1165
  });
@@ -1062,14 +1172,14 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1062
1172
  const nearestNormal = decodeNormal(nearest.rg), result = decodeNormal(sampled.rg.div(coverage2)).toVar();
1063
1173
  const sampledDepth = sampled.b.mul(65280).add(sampled.a.mul(255)).div(65535);
1064
1174
  const nearestDepth = nearest.b.mul(65280).add(nearest.a.mul(255)).div(65535);
1065
- If4(nearestNormal.z.lessThan(0).or(dot3(result, nearestNormal).lessThan(0.75)).or(coverage2.lessThan(0.9999)).or(abs3(sampledDepth.sub(nearestDepth)).greaterThan(tolerance)), () => {
1175
+ If4(nearestNormal.z.lessThan(0).or(dot4(result, nearestNormal).lessThan(0.75)).or(coverage2.lessThan(0.9999)).or(abs3(sampledDepth.sub(nearestDepth)).greaterThan(tolerance)), () => {
1066
1176
  const p = uv2.mul(descriptor.atlasResolution).sub(0.5), lo = floor2(p), f = fract(p);
1067
- const normal2 = vec34(0).toVar(), weights = float4(0).toVar();
1177
+ const normal2 = vec35(0).toVar(), weights = float4(0).toVar();
1068
1178
  for (const [x, y] of [[0, 0], [1, 0], [0, 1], [1, 1]]) {
1069
- const texel = ivec24(lo.add(vec24(x, y)).clamp(0, descriptor.atlasResolution - 1));
1070
- const packed = textureLoad4(maps.normalDepth, texel).toVar();
1071
- const alpha2 = textureLoad4(maps.baseColor, texel).a;
1072
- const coverage3 = descriptor.alphaMode === "blend" ? textureLoad4(maps.orm, texel).a : alpha2;
1179
+ const texel = ivec25(lo.add(vec24(x, y)).clamp(0, descriptor.atlasResolution - 1));
1180
+ const packed = textureLoad5(maps.normalDepth, texel).toVar();
1181
+ const alpha2 = textureLoad5(maps.baseColor, texel).a;
1182
+ const coverage3 = descriptor.alphaMode === "blend" ? textureLoad5(maps.orm, texel).a : alpha2;
1073
1183
  const capturedDepth = packed.b.mul(65280).add(packed.a.mul(255)).div(65535);
1074
1184
  const supported = coverage3.greaterThan(1e-4).and(alpha2.greaterThanEqual(minimumAlpha.mul(coverage3))).and(abs3(capturedDepth.sub(depth)).lessThanEqual(tolerance));
1075
1185
  If4(supported, () => {
@@ -1111,46 +1221,57 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1111
1221
  )
1112
1222
  )
1113
1223
  );
1114
- const rects = new DataTexture3(
1224
+ const rects = new DataTexture4(
1115
1225
  rectData,
1116
1226
  6,
1117
1227
  descriptor.boxes.length,
1118
- RGBAFormat3,
1119
- FloatType3
1228
+ RGBAFormat4,
1229
+ FloatType4
1120
1230
  );
1121
1231
  rects.needsUpdate = true;
1122
1232
  rects.magFilter = rects.minFilter = NearestFilter3;
1123
1233
  material.addEventListener("dispose", () => rects.dispose());
1124
1234
  const center = attribute3("boxCenter", "vec3"), half = attribute3("boxHalfSize", "vec3");
1125
1235
  const ax = attribute3("boxAxisX", "vec3"), ay = attribute3("boxAxisY", "vec3"), az = attribute3("boxAxisZ", "vec3");
1126
- const toBox = (p) => vec34(dot3(p, ax), dot3(p, ay), dot3(p, az));
1236
+ const toBox = (p) => vec35(dot4(p, ax), dot4(p, ay), dot4(p, az));
1127
1237
  const fromBox = (p) => ax.mul(p.x).add(ay.mul(p.y)).add(az.mul(p.z));
1128
- const eye = modelWorldMatrixInverse.mul(vec45(cameraPosition, 1)).xyz;
1129
- const viewAxis = modelWorldMatrixInverse.mul(cameraWorldMatrix.mul(vec45(0, 0, 1, 0))).xyz.normalize();
1238
+ const meshVertex = (p) => Fn5((_, builder) => instanceSpace(builder)?.toMeshPoint(p) ?? p)();
1239
+ const meshPoint = (p) => Fn5((_, builder) => instanceSpace(builder)?.fragment.toMeshPoint(p) ?? p)();
1240
+ const meshNormal = (n) => Fn5((_, builder) => instanceSpace(builder)?.fragment.toMeshNormal(n) ?? n)();
1241
+ const meshEye = modelWorldMatrixInverse.mul(vec46(cameraPosition, 1)).xyz;
1242
+ const meshViewAxis = modelWorldMatrixInverse.mul(cameraWorldMatrix.mul(vec46(0, 0, 1, 0))).xyz;
1243
+ const eye = Fn5((_, builder) => instanceSpace(builder)?.fragment.toLocalPoint(meshEye) ?? meshEye)();
1244
+ const viewAxis = Fn5((_, builder) => instanceSpace(builder)?.fragment.toLocalDirection(meshViewAxis) ?? meshViewAxis)().normalize();
1245
+ const vertexEye = Fn5((_, builder) => instanceSpace(builder)?.toLocalPoint(meshEye) ?? meshEye)();
1246
+ const vertexViewAxis = Fn5((_, builder) => instanceSpace(builder)?.toLocalDirection(meshViewAxis) ?? meshViewAxis)().normalize();
1247
+ const cameraUp = Fn5((_, builder) => {
1248
+ const up = modelWorldMatrixInverse.mul(cameraWorldMatrix.mul(vec46(0, 1, 0, 0))).xyz;
1249
+ return instanceSpace(builder)?.toLocalDirection(up) ?? up;
1250
+ })();
1130
1251
  const perspective = cameraProjectionMatrix2.element(3).w.equal(0);
1131
- let proxy = positionLocal2;
1252
+ let proxy = positionGeometry2;
1132
1253
  if (descriptor.mode !== "fitted") {
1133
1254
  proxy = Fn5((_, builder) => {
1134
- const delta = eye.sub(center);
1135
- const forward = perspective.and(delta.length().greaterThan(1e-6)).select(normalize2(delta), viewAxis);
1136
- const right = modelWorldMatrixInverse.mul(cameraWorldMatrix.mul(vec45(0, 1, 0, 0))).xyz.cross(forward).normalize();
1255
+ const delta = vertexEye.sub(center);
1256
+ const forward = perspective.and(delta.length().greaterThan(1e-6)).select(normalize2(delta), vertexViewAxis);
1257
+ const right = cameraUp.cross(forward).normalize();
1137
1258
  const up = forward.cross(right).normalize();
1138
1259
  const radius = half.length();
1139
- const distance = dot3(eye.sub(center), forward);
1260
+ const distance = dot4(vertexEye.sub(center), forward);
1140
1261
  const planeOffset = perspective.select(min2(radius, distance.sub(cameraNear2.mul(2))), radius);
1141
1262
  const plane = center.add(forward.mul(planeOffset));
1142
1263
  const lo = vec24(1e20).toVar(), hi = vec24(-1e20).toVar();
1143
1264
  for (const x of [-1, 1])
1144
1265
  for (const y of [-1, 1])
1145
1266
  for (const z of [-1, 1]) {
1146
- const corner2 = fromBox(half.mul(vec34(x, y, z)));
1267
+ const corner2 = fromBox(half.mul(vec35(x, y, z)));
1147
1268
  const scale = perspective.select(
1148
1269
  max4(distance.sub(planeOffset), 1e-5).div(
1149
- max4(distance.sub(dot3(corner2, forward)), 1e-5)
1270
+ max4(distance.sub(dot4(corner2, forward)), 1e-5)
1150
1271
  ),
1151
1272
  float4(1)
1152
1273
  );
1153
- const p = vec24(dot3(corner2, right), dot3(corner2, up)).mul(scale);
1274
+ const p = vec24(dot4(corner2, right), dot4(corner2, up)).mul(scale);
1154
1275
  lo.assign(min2(lo, p));
1155
1276
  hi.assign(max4(hi, p));
1156
1277
  }
@@ -1158,10 +1279,10 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1158
1279
  const xy = lo.add(hi.sub(lo).mul(corner));
1159
1280
  return plane.add(right.mul(xy.x)).add(up.mul(xy.y));
1160
1281
  })();
1161
- material.positionNode = proxy;
1162
- material.castShadowPositionNode = proxy;
1282
+ material.positionNode = meshVertex(proxy);
1283
+ material.castShadowPositionNode = material.positionNode;
1163
1284
  }
1164
- const raster = varying(proxy, "boxRasterPosition");
1285
+ const raster = varying2(proxy, "boxRasterPosition");
1165
1286
  if (boxDepthMode(descriptor, settings) === "projection" && descriptor.mode === "fitted" && settings.interpolation === "none") {
1166
1287
  material.side = FrontSide;
1167
1288
  return applyBoxFaces({
@@ -1172,7 +1293,9 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1172
1293
  transparency,
1173
1294
  half,
1174
1295
  toBox,
1175
- fromBox
1296
+ fromBox,
1297
+ meshVertex,
1298
+ meshNormal
1176
1299
  });
1177
1300
  }
1178
1301
  if (boxDepthMode(descriptor, settings) === "projection")
@@ -1191,7 +1314,9 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1191
1314
  eye,
1192
1315
  viewAxis,
1193
1316
  perspective,
1194
- raster
1317
+ raster,
1318
+ meshPoint,
1319
+ meshNormal
1195
1320
  });
1196
1321
  const accelerated = descriptor.boxes.every((b) => b.depthBounds);
1197
1322
  const gridSize = BOX_OCCUPANCY_RESOLUTION;
@@ -1204,7 +1329,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1204
1329
  descriptor.boxes.forEach(
1205
1330
  (box, index) => words.set(box.occupancy, index * wordsPerBox)
1206
1331
  );
1207
- occupancy = new DataTexture3(
1332
+ occupancy = new DataTexture4(
1208
1333
  words,
1209
1334
  wordsPerBox,
1210
1335
  descriptor.boxes.length,
@@ -1221,16 +1346,16 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1221
1346
  "BoxImpostorHit"
1222
1347
  );
1223
1348
  const faceBasis = (axis, facing) => {
1224
- const n = vec34(
1349
+ const n = vec35(
1225
1350
  axis.equal(0).select(facing, 0),
1226
1351
  axis.equal(1).select(facing, 0),
1227
1352
  axis.equal(2).select(facing, 0)
1228
1353
  ).toVar();
1229
1354
  const right = axis.equal(0).select(
1230
- vec34(0, 0, facing.negate()),
1231
- axis.equal(1).select(vec34(1, 0, 0), vec34(facing, 0, 0))
1355
+ vec35(0, 0, facing.negate()),
1356
+ axis.equal(1).select(vec35(1, 0, 0), vec35(facing, 0, 0))
1232
1357
  ).toVar();
1233
- const up = axis.equal(1).select(vec34(0, 0, facing.negate()), vec34(0, 1, 0)).toVar();
1358
+ const up = axis.equal(1).select(vec35(0, 0, facing.negate()), vec35(0, 1, 0)).toVar();
1234
1359
  return { n, right, up };
1235
1360
  };
1236
1361
  const ray = perspective.select(normalize2(raster.sub(eye)), viewAxis.negate());
@@ -1241,17 +1366,17 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1241
1366
  );
1242
1367
  const o = toBox(origin.sub(center)).div(half), r = toBox(ray).div(half);
1243
1368
  const safe = sign3(r.add(1e-20)).mul(max4(abs3(r), 1e-10));
1244
- const a = vec34(-1).sub(o).div(safe), b = vec34(1).sub(o).div(safe);
1369
+ const a = vec35(-1).sub(o).div(safe), b = vec35(1).sub(o).div(safe);
1245
1370
  const enter = max4(max4(min2(a, b).x, min2(a, b).y), min2(a, b).z).max(0);
1246
1371
  const exit = min2(min2(max4(a, b).x, max4(a, b).y), max4(a, b).z);
1247
- const rayBounds = viewBounds?.(builder, int4(attribute3("boxId", "float")), o, r, enter, exit);
1372
+ const rayBounds = viewBounds?.(builder, int5(attribute3("boxId", "float")), o, r, enter, exit);
1248
1373
  const occupiedStart = enter.toVar();
1249
1374
  if (occupancy) {
1250
1375
  const gridOrigin = o.add(1).mul(gridSize / 2);
1251
1376
  const gridRay = r.mul(gridSize / 2);
1252
1377
  const step = sign3(gridRay.add(1e-20));
1253
1378
  const cell = floor2(gridOrigin.add(gridRay.mul(enter))).clamp(0, gridSize - 1).toVar();
1254
- const inverse = vec34(1).div(safe.mul(gridSize / 2));
1379
+ const inverse = vec35(1).div(safe.mul(gridSize / 2));
1255
1380
  const delta = abs3(inverse);
1256
1381
  const next = cell.add(step.add(1).mul(0.5)).sub(gridOrigin).mul(inverse).toVar();
1257
1382
  const t = enter.toVar();
@@ -1263,9 +1388,9 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1263
1388
  const cellIndex = uint2(
1264
1389
  cell.x.add(cell.y.mul(gridSize)).add(cell.z.mul(gridSize ** 2))
1265
1390
  ).toVar();
1266
- const word = textureLoad4(
1391
+ const word = textureLoad5(
1267
1392
  occupancy,
1268
- ivec24(int4(cellIndex.shiftRight(5)), int4(attribute3("boxId", "float")))
1393
+ ivec25(int5(cellIndex.shiftRight(5)), int5(attribute3("boxId", "float")))
1269
1394
  ).r;
1270
1395
  const support = word.shiftRight(cellIndex.bitAnd(31)).bitAnd(1);
1271
1396
  If4(support.notEqual(uint2(0)), () => {
@@ -1273,7 +1398,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1273
1398
  Break();
1274
1399
  });
1275
1400
  const edge = min2(min2(next.x, next.y), next.z).toVar();
1276
- const advance = vec34(
1401
+ const advance = vec35(
1277
1402
  next.x.lessThanEqual(edge).select(1, 0),
1278
1403
  next.y.lessThanEqual(edge).select(1, 0),
1279
1404
  next.z.lessThanEqual(edge).select(1, 0)
@@ -1290,15 +1415,15 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1290
1415
  });
1291
1416
  }
1292
1417
  const look = toBox(ray).negate();
1293
- const bestT = exit.add(1).toVar(), bestUv = vec24(0).toVar(), bestFace = int4(0).toVar(), appearanceNear = preferFacingCapture ? float4(0).toVar() : null, valid = float4(0).toVar(), found = float4(0).toVar();
1418
+ const bestT = exit.add(1).toVar(), bestUv = vec24(0).toVar(), bestFace = int5(0).toVar(), appearanceNear = preferFacingCapture ? float4(0).toVar() : null, valid = float4(0).toVar(), found = float4(0).toVar();
1294
1419
  const angles = abs3(look).toVar();
1295
1420
  const major = angles.x.greaterThanEqual(angles.y).and(angles.x.greaterThanEqual(angles.z)).select(
1296
- int4(0),
1297
- angles.y.greaterThanEqual(angles.z).select(int4(1), int4(2))
1421
+ int5(0),
1422
+ angles.y.greaterThanEqual(angles.z).select(int5(1), int5(2))
1298
1423
  ).toVar();
1299
1424
  const nextAxis = major.add(1).mod(3), lastAxis = major.add(2).mod(3);
1300
1425
  const second = angles.element(nextAxis).greaterThanEqual(angles.element(lastAxis)).select(nextAxis, lastAxis).toVar();
1301
- const third = int4(3).sub(major).sub(second).toVar();
1426
+ const third = int5(3).sub(major).sub(second).toVar();
1302
1427
  Loop2(
1303
1428
  { start: 0, end: 6, type: "int", name: "viewIndex" },
1304
1429
  ({ viewIndex: i }) => {
@@ -1312,24 +1437,24 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1312
1437
  look.element(axis).greaterThanEqual(0),
1313
1438
  look.element(axis).lessThan(0)
1314
1439
  );
1315
- const face = axis.mul(2).add(positive.select(int4(0), int4(1)));
1440
+ const face = axis.mul(2).add(positive.select(int5(0), int5(1)));
1316
1441
  const bounds = rayBounds?.(face, enter, exit);
1317
1442
  const facing = positive.select(1, -1);
1318
1443
  const { n, right, up } = faceBasis(axis, facing);
1319
1444
  const direction = i.lessThan(3).select(1, -1);
1320
- const rect = textureLoad4(
1445
+ const rect = textureLoad5(
1321
1446
  rects,
1322
- ivec24(face, int4(attribute3("boxId", "float")))
1447
+ ivec25(face, int5(attribute3("boxId", "float")))
1323
1448
  ).toVar();
1324
1449
  const sampleUv = (p) => rect.xy.add(
1325
- vec24(dot3(p, right), dot3(p, up)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
1450
+ vec24(dot4(p, right), dot4(p, up)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
1326
1451
  );
1327
1452
  const decode = (d) => d.b.mul(65280).add(d.a.mul(255)).div(65535);
1328
1453
  const depthAt = (uv2) => decode(texture3(maps.normalDepth, uv2).level(0));
1329
- const projectedOrigin = vec24(dot3(o, right), dot3(o, up)).toVar();
1330
- const projectedRay = vec24(dot3(r, right), dot3(r, up)).toVar();
1331
- const axialOrigin = dot3(o, n).toVar();
1332
- const axialRay = dot3(r, n).toVar();
1454
+ const projectedOrigin = vec24(dot4(o, right), dot4(o, up)).toVar();
1455
+ const projectedRay = vec24(dot4(r, right), dot4(r, up)).toVar();
1456
+ const axialOrigin = dot4(o, n).toVar();
1457
+ const axialRay = dot4(r, n).toVar();
1333
1458
  const distance = (t) => {
1334
1459
  const uv2 = rect.xy.add(
1335
1460
  projectedOrigin.add(projectedRay.mul(t)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
@@ -1338,17 +1463,17 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1338
1463
  };
1339
1464
  const acceptHit = (hitT) => {
1340
1465
  const point2 = o.add(r.mul(hitT)), uv2 = sampleUv(point2);
1341
- const texel = ivec24(uv2.mul(descriptor.atlasResolution));
1342
- const nearest = textureLoad4(maps.normalDepth, texel);
1466
+ const texel = ivec25(uv2.mul(descriptor.atlasResolution));
1467
+ const nearest = textureLoad5(maps.normalDepth, texel);
1343
1468
  const capturedBase = texture3(maps.baseColor, uv2).level(0);
1344
- const occupied = textureLoad4(maps.orm, texel).a.greaterThan(0.5);
1469
+ const occupied = textureLoad5(maps.orm, texel).a.greaterThan(0.5);
1345
1470
  const residual = abs3(
1346
- dot3(point2, n).sub(float4(1).sub(decode(nearest).mul(2)))
1471
+ dot4(point2, n).sub(float4(1).sub(decode(nearest).mul(2)))
1347
1472
  );
1348
1473
  const tolerance = max4(
1349
- dot3(abs3(right), half).div(rect.z.mul(descriptor.atlasResolution)),
1350
- dot3(abs3(up), half).div(rect.w.mul(descriptor.atlasResolution))
1351
- ).div(dot3(abs3(n), half)).mul(4).add(4 / 65535);
1474
+ dot4(abs3(right), half).div(rect.z.mul(descriptor.atlasResolution)),
1475
+ dot4(abs3(up), half).div(rect.w.mul(descriptor.atlasResolution))
1476
+ ).div(dot4(abs3(n), half)).mul(4).add(4 / 65535);
1352
1477
  If4(
1353
1478
  residual.lessThanEqual(tolerance).and(occupied).and(
1354
1479
  capturedBase.a.greaterThanEqual(minimumAlpha)
@@ -1363,8 +1488,8 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1363
1488
  };
1364
1489
  if (preferFacingCapture) {
1365
1490
  const texel2 = max4(
1366
- dot3(abs3(right), half).div(rect.z),
1367
- dot3(abs3(up), half).div(rect.w)
1491
+ dot4(abs3(right), half).div(rect.z),
1492
+ dot4(abs3(up), half).div(rect.w)
1368
1493
  ).div(descriptor.atlasResolution);
1369
1494
  const uncertainty = min2(
1370
1495
  texel2,
@@ -1381,7 +1506,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1381
1506
  );
1382
1507
  };
1383
1508
  const traceInterval = (start, end, steps) => {
1384
- const footprint = vec24(dot3(r, right), dot3(r, up)).abs().mul(rect.zw).mul(descriptor.atlasResolution / 2).mul(end.sub(start));
1509
+ const footprint = vec24(dot4(r, right), dot4(r, up)).abs().mul(rect.zw).mul(descriptor.atlasResolution / 2).mul(end.sub(start));
1385
1510
  let density = steps / 8;
1386
1511
  if (descriptor.alphaMode === "blend" && transparency === "blended" && steps < 32) {
1387
1512
  density = i.equal(0).select(steps / 16, steps / 32);
@@ -1390,10 +1515,10 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1390
1515
  }
1391
1516
  const samples = max4(float4(steps), max4(footprint.x, footprint.y).mul(density)).div(2).ceil().mul(2).toVar();
1392
1517
  const step = end.sub(start).div(samples).toVar();
1393
- const pairs = int4(samples.div(2));
1518
+ const pairs = int5(samples.div(2));
1394
1519
  const pairAt = (t) => t.sub(start).div(max4(step.mul(2), 1e-15));
1395
- const firstPair = bounds ? int4(floor2(pairAt(bounds.start))).clamp(0, pairs).toVar() : int4(0);
1396
- const lastPair = bounds ? int4(pairAt(bounds.end).ceil()).clamp(0, pairs).toVar() : pairs;
1520
+ const firstPair = bounds ? int5(floor2(pairAt(bounds.start))).clamp(0, pairs).toVar() : int5(0);
1521
+ const lastPair = bounds ? int5(pairAt(bounds.end).ceil()).clamp(0, pairs).toVar() : pairs;
1397
1522
  const previous = start.toVar();
1398
1523
  if (bounds) If4(firstPair.greaterThan(0), () => {
1399
1524
  previous.assign(start.add(step.mul(float4(firstPair.mul(2)))));
@@ -1451,8 +1576,8 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1451
1576
  )
1452
1577
  );
1453
1578
  const interval = positive.select(depths.xy, depths.zw);
1454
- const initialDepth = float4(1).sub(dot3(o, n)).mul(0.5);
1455
- const depthSlope = dot3(r, n).negate().mul(0.5);
1579
+ const initialDepth = float4(1).sub(dot4(o, n)).mul(0.5);
1580
+ const depthSlope = dot4(r, n).negate().mul(0.5);
1456
1581
  const da = interval.x.sub(2 / 65535).sub(initialDepth).div(depthSlope);
1457
1582
  const db = interval.y.add(2 / 65535).sub(initialDepth).div(depthSlope);
1458
1583
  const start = max4(occupiedStart, min2(da, db));
@@ -1506,7 +1631,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1506
1631
  const sampled = texture3(maps.normalDepth, hit.get("uv")).level(0);
1507
1632
  const local = unpackNormal(sampled.rg.div(coverage));
1508
1633
  const direction = fromBox(right.mul(local.x).add(up.mul(local.y)).add(n.mul(local.z))).normalize().toVar();
1509
- return direction.mul(dot3(direction, ray).greaterThan(0).select(-1, 1));
1634
+ return direction.mul(dot4(direction, ray).greaterThan(0).select(-1, 1));
1510
1635
  })();
1511
1636
  let color = base.div(coverage), surfaceOrm = orm.rgb.div(coverage), emission = texture3(maps.emissive, hit.get("uv")).level(0).rgb.div(coverage), normal = hitNormal;
1512
1637
  if (settings.interpolation !== "none") {
@@ -1520,37 +1645,37 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1520
1645
  const look = toBox(
1521
1646
  perspective.select(normalize2(eye.sub(hit.get("position"))), viewAxis)
1522
1647
  );
1523
- const colors = vec45(0).toVar(), materials = vec34(0).toVar(), emissions = vec34(0).toVar(), normals = vec34(0).toVar(), weights = float4(0).toVar();
1648
+ const colors = vec46(0).toVar(), materials = vec35(0).toVar(), emissions = vec35(0).toVar(), normals = vec35(0).toVar(), weights = float4(0).toVar();
1524
1649
  for (let axis = 0; axis < 3; axis++) {
1525
1650
  const positive = look.element(axis).greaterThanEqual(0);
1526
1651
  const front = BOX_FACE_AXES[axis * 2], back = BOX_FACE_AXES[axis * 2 + 1];
1527
- const n = positive.select(vec34(...front.normal), vec34(...back.normal));
1652
+ const n = positive.select(vec35(...front.normal), vec35(...back.normal));
1528
1653
  const right = positive.select(
1529
- vec34(...front.right),
1530
- vec34(...back.right)
1654
+ vec35(...front.right),
1655
+ vec35(...back.right)
1531
1656
  );
1532
- const up = positive.select(vec34(...front.up), vec34(...back.up));
1533
- const face = positive.select(int4(axis * 2), int4(axis * 2 + 1));
1534
- const rect = textureLoad4(
1657
+ const up = positive.select(vec35(...front.up), vec35(...back.up));
1658
+ const face = positive.select(int5(axis * 2), int5(axis * 2 + 1));
1659
+ const rect = textureLoad5(
1535
1660
  rects,
1536
- ivec24(face, int4(attribute3("boxId", "float")))
1661
+ ivec25(face, int5(attribute3("boxId", "float")))
1537
1662
  );
1538
1663
  const uv2 = rect.xy.add(
1539
- vec24(dot3(point, right), dot3(point, up)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
1664
+ vec24(dot4(point, right), dot4(point, up)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
1540
1665
  );
1541
- const texel = ivec24(uv2.mul(descriptor.atlasResolution));
1542
- const captured = textureLoad4(maps.normalDepth, texel);
1666
+ const texel = ivec25(uv2.mul(descriptor.atlasResolution));
1667
+ const captured = textureLoad5(maps.normalDepth, texel);
1543
1668
  const sampled = texture3(maps.baseColor, uv2).level(0);
1544
1669
  const sampledOrm = texture3(maps.orm, uv2).level(0);
1545
- const occupied = textureLoad4(maps.orm, texel).a.greaterThan(0.5);
1670
+ const occupied = textureLoad5(maps.orm, texel).a.greaterThan(0.5);
1546
1671
  const depth = captured.b.mul(65280).add(captured.a.mul(255)).div(65535);
1547
1672
  const tolerance = max4(
1548
- dot3(abs3(right), half).div(rect.z.mul(descriptor.atlasResolution)),
1549
- dot3(abs3(up), half).div(rect.w.mul(descriptor.atlasResolution))
1550
- ).div(dot3(abs3(n), half)).mul(4).add(4 / 65535);
1673
+ dot4(abs3(right), half).div(rect.z.mul(descriptor.atlasResolution)),
1674
+ dot4(abs3(up), half).div(rect.w.mul(descriptor.atlasResolution))
1675
+ ).div(dot4(abs3(n), half)).mul(4).add(4 / 65535);
1551
1676
  If4(
1552
1677
  occupied.and(sampled.a.greaterThanEqual(minimumAlpha)).and(
1553
- abs3(dot3(point, n).sub(float4(1).sub(depth.mul(2)))).lessThanEqual(
1678
+ abs3(dot4(point, n).sub(float4(1).sub(depth.mul(2)))).lessThanEqual(
1554
1679
  tolerance
1555
1680
  )
1556
1681
  ),
@@ -1559,7 +1684,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1559
1684
  const filtered = filtering ? texture3(maps.normalDepth, uv2).level(0).toVar() : captured;
1560
1685
  let weight = settings.interpolation === "smooth" ? angle.mul(angle) : angle;
1561
1686
  if (filtering) {
1562
- const error = abs3(dot3(point, n).sub(float4(1).sub(
1687
+ const error = abs3(dot4(point, n).sub(float4(1).sub(
1563
1688
  filtered.b.mul(65280).add(filtered.a.mul(255)).div(65535).mul(2)
1564
1689
  )));
1565
1690
  weight = weight.mul(float4(1).sub(error.div(tolerance)).clamp(0, 1));
@@ -1571,10 +1696,10 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1571
1696
  texture3(maps.emissive, uv2).level(0).rgb.div(coverage2).mul(weight)
1572
1697
  );
1573
1698
  let shadingNormal;
1574
- if (filtering) shadingNormal = filteredNormal(uv2, float4(1).sub(dot3(point, n)).mul(0.5), tolerance.mul(0.5), captured, sampled.a, filtered, sampledOrm.a);
1699
+ if (filtering) shadingNormal = filteredNormal(uv2, float4(1).sub(dot4(point, n)).mul(0.5), tolerance.mul(0.5), captured, sampled.a, filtered, sampledOrm.a);
1575
1700
  else {
1576
1701
  const packed = captured.rg.mul(2).sub(1);
1577
- const decoded = vec34(
1702
+ const decoded = vec35(
1578
1703
  packed,
1579
1704
  float4(1).sub(abs3(packed.x)).sub(abs3(packed.y))
1580
1705
  ).toVar();
@@ -1607,9 +1732,10 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1607
1732
  emission = blended.get("emission");
1608
1733
  normal = blended.get("normal");
1609
1734
  }
1610
- material.capturedPositionNode = hit.get("position");
1735
+ const position = meshPoint(hit.get("position")).toVar("boxHitMeshPosition");
1736
+ material.capturedPositionNode = position;
1611
1737
  material.colorNode = color.rgb;
1612
- material.normalNode = transformNormalToView3(normal);
1738
+ material.normalNode = transformNormalToView3(meshNormal(normal));
1613
1739
  material.roughnessNode = surfaceOrm.g;
1614
1740
  material.metalnessNode = surfaceOrm.b;
1615
1741
  material.aoNode = surfaceOrm.r;
@@ -1624,9 +1750,9 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1624
1750
  }
1625
1751
  material.maskNode = hit.get("valid").greaterThan(0.5);
1626
1752
  material.maskShadowNode = material.maskNode;
1627
- material.depthNode = capturedSurfaceDepth(hit.get("position"));
1753
+ material.depthNode = capturedSurfaceDepth(position);
1628
1754
  material.receivedShadowPositionNode = modelWorldMatrix3.mul(
1629
- vec45(hit.get("position"), 1)
1755
+ vec46(position, 1)
1630
1756
  ).xyz;
1631
1757
  material.userData.boxImpostor = { descriptor, maps, alphaCutoff };
1632
1758
  return material;