@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
@@ -98,8 +98,8 @@ function parseBoxImpostorDescriptor(raw) {
98
98
  fail();
99
99
  for (let i = 0; i < 3; i++)
100
100
  for (let j = 0; j < 3; j++) {
101
- const dot4 = b.axes[i].reduce((s, v, k) => s + v * b.axes[j][k], 0);
102
- if (Math.abs(dot4 - (i === j ? 1 : 0)) > 1e-4) fail();
101
+ const dot5 = b.axes[i].reduce((s, v, k) => s + v * b.axes[j][k], 0);
102
+ if (Math.abs(dot5 - (i === j ? 1 : 0)) > 1e-4) fail();
103
103
  }
104
104
  const [x, y, z] = b.axes;
105
105
  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)
@@ -316,9 +316,9 @@ function capturedSurfaceDepth(position, shadowBias = 0) {
316
316
 
317
317
  // src/box-impostor/box-impostor-material.js
318
318
  import {
319
- DataTexture as DataTexture3,
320
- FloatType as FloatType3,
321
- RGBAFormat as RGBAFormat3,
319
+ DataTexture as DataTexture4,
320
+ FloatType as FloatType4,
321
+ RGBAFormat as RGBAFormat4,
322
322
  RedIntegerFormat,
323
323
  UnsignedIntType,
324
324
  NearestFilter as NearestFilter3,
@@ -333,27 +333,27 @@ import {
333
333
  Loop as Loop2,
334
334
  Break,
335
335
  attribute as attribute3,
336
- varying,
337
- positionLocal as positionLocal2,
336
+ varying as varying2,
337
+ positionGeometry as positionGeometry2,
338
338
  positionViewDirection,
339
339
  modelWorldMatrixInverse,
340
340
  cameraPosition,
341
341
  cameraWorldMatrix,
342
342
  cameraProjectionMatrix as cameraProjectionMatrix2,
343
343
  vec2 as vec24,
344
- vec3 as vec34,
345
- vec4 as vec45,
344
+ vec3 as vec35,
345
+ vec4 as vec46,
346
346
  float as float4,
347
- int as int4,
347
+ int as int5,
348
348
  uint as uint2,
349
- dot as dot3,
349
+ dot as dot4,
350
350
  abs as abs3,
351
351
  max as max4,
352
352
  min as min2,
353
353
  sign as sign3,
354
354
  texture as texture3,
355
- textureLoad as textureLoad4,
356
- ivec2 as ivec24,
355
+ textureLoad as textureLoad5,
356
+ ivec2 as ivec25,
357
357
  normalize as normalize2,
358
358
  floor as floor2,
359
359
  fract,
@@ -364,9 +364,114 @@ import {
364
364
  uniform
365
365
  } from "three/tsl";
366
366
 
367
+ // src/rendering/instance-space.js
368
+ import { DataTexture, DynamicDrawUsage, FloatType, InstancedInterleavedBuffer, InterpolationSamplingType, NodeUpdateType, RGBAFormat } from "three/webgpu";
369
+ import { cross, dot, instanceIndex, instancedBufferAttribute, instancedDynamicBufferAttribute, int, ivec2, textureLoad, varying, vec3, vec4 as vec42 } from "three/tsl";
370
+ var spaces = /* @__PURE__ */ new WeakMap();
371
+ var webglSpaces = /* @__PURE__ */ new WeakMap();
372
+ function instanceColumns(object, matrix, useTexture) {
373
+ const columns = [0, 1, 2, 3];
374
+ if (useTexture) {
375
+ const rowSize = Math.ceil(Math.sqrt(matrix.count) / 2);
376
+ const rows = Math.ceil(matrix.count / rowSize);
377
+ const data = new Float32Array(rowSize * rows * 16);
378
+ const texture4 = new DataTexture(data, rowSize * 4, rows, RGBAFormat, FloatType);
379
+ const upload = () => {
380
+ data.set(matrix.array);
381
+ texture4.needsUpdate = true;
382
+ };
383
+ upload();
384
+ const release = () => {
385
+ object.removeEventListener("dispose", release);
386
+ texture4.dispose();
387
+ webglSpaces.delete(matrix);
388
+ };
389
+ object.addEventListener("dispose", release);
390
+ const x = instanceIndex.mod(rowSize).mul(4);
391
+ const y = instanceIndex.div(rowSize);
392
+ return { nodes: columns.map((column) => textureLoad(texture4, ivec2(int(x.add(column)), int(y)))), upload };
393
+ }
394
+ const interleaved = new InstancedInterleavedBuffer(matrix.array, 16, 1);
395
+ const read = matrix.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
396
+ return {
397
+ nodes: columns.map((column) => read(
398
+ interleaved,
399
+ /** @type {const} */
400
+ "vec4",
401
+ 16,
402
+ column * 4
403
+ )),
404
+ upload: () => {
405
+ interleaved.needsUpdate = true;
406
+ }
407
+ };
408
+ }
409
+ function instanceSpace(builder) {
410
+ const object = (
411
+ /** @type {InstancedMesh} */
412
+ builder.object
413
+ );
414
+ const matrix = object?.isInstancedMesh ? object.instanceMatrix : null;
415
+ if (!matrix) return null;
416
+ const backend = (
417
+ /** @type {{isWebGPUBackend?: boolean} | undefined} */
418
+ builder.renderer.backend
419
+ );
420
+ const useTexture = !backend?.isWebGPUBackend && matrix.count * 64 > (builder.getUniformBufferLimit?.() ?? 16384);
421
+ const cache = useTexture ? webglSpaces : spaces;
422
+ const cached = cache.get(matrix);
423
+ if (cached) return cached;
424
+ const { nodes, upload } = instanceColumns(object, matrix, useTexture);
425
+ let version = matrix.version;
426
+ nodes[0].updateBeforeType = NodeUpdateType.OBJECT;
427
+ nodes[0].updateBefore = () => {
428
+ if (matrix.version !== version) {
429
+ version = matrix.version;
430
+ upload();
431
+ }
432
+ return void 0;
433
+ };
434
+ const [a, b, c, d] = nodes.map((node) => node.xyz);
435
+ const determinant = dot(a, cross(b, c));
436
+ const rows = [cross(b, c), cross(c, a), cross(a, b)].map((row) => row.div(determinant));
437
+ const toLocalDirection = (v) => vec3(dot(rows[0], v), dot(rows[1], v), dot(rows[2], v));
438
+ const toMeshDirection = (v) => a.mul(v.x).add(b.mul(v.y)).add(c.mul(v.z));
439
+ const translation = [d.x, d.y, d.z];
440
+ const packed = [a, b, c].map(
441
+ (column, k) => varying(vec42(column, translation[k]), `instanceSpace${k}`).setInterpolation(InterpolationSamplingType.FLAT)
442
+ );
443
+ const [fa, fb, fc] = packed.map((column) => column.xyz);
444
+ const cofactors = () => [cross(fb, fc), cross(fc, fa), cross(fa, fb)];
445
+ const space = {
446
+ toLocalPoint: (p) => toLocalDirection(p.sub(d)),
447
+ toLocalDirection,
448
+ toMeshPoint: (p) => toMeshDirection(p).add(d),
449
+ toMeshDirection,
450
+ fragment: {
451
+ 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)),
452
+ toMeshDirection: (v) => fa.mul(v.x).add(fb.mul(v.y)).add(fc.mul(v.z)),
453
+ toMeshNormal: (n) => {
454
+ const [x, y, z] = cofactors();
455
+ return x.mul(n.x).add(y.mul(n.y)).add(z.mul(n.z)).mul(dot(fa, x).sign()).normalize();
456
+ },
457
+ toLocalDirection: (v) => {
458
+ const [x, y, z] = cofactors();
459
+ return vec3(dot(x, v), dot(y, v), dot(z, v)).div(dot(fa, x));
460
+ },
461
+ toLocalPoint: (p) => {
462
+ const [x, y, z] = cofactors();
463
+ const v = p.sub(vec3(packed[0].w, packed[1].w, packed[2].w));
464
+ return vec3(dot(x, v), dot(y, v), dot(z, v)).div(dot(fa, x));
465
+ }
466
+ }
467
+ };
468
+ cache.set(matrix, space);
469
+ return space;
470
+ }
471
+
367
472
  // src/rendering/captured-surface-material.js
368
473
  import { MeshStandardNodeMaterial } from "three/webgpu";
369
- import { context, modelViewMatrix as modelViewMatrix2, modelWorldMatrix, vec4 as vec42 } from "three/tsl";
474
+ import { context, modelViewMatrix as modelViewMatrix2, modelWorldMatrix, vec4 as vec43 } from "three/tsl";
370
475
  var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
371
476
  /** @type {import('three/webgpu').Node<'vec3'> | null} */
372
477
  capturedPositionNode = null;
@@ -377,8 +482,8 @@ var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
377
482
  setupLighting(builder) {
378
483
  const lighting = super.setupLighting(builder);
379
484
  if (!this.capturedPositionNode) return lighting;
380
- const world = modelWorldMatrix.mul(vec42(this.capturedPositionNode, 1)).xyz;
381
- const view = modelViewMatrix2.mul(vec42(this.capturedPositionNode, 1)).xyz;
485
+ const world = modelWorldMatrix.mul(vec43(this.capturedPositionNode, 1)).xyz;
486
+ const view = modelViewMatrix2.mul(vec43(this.capturedPositionNode, 1)).xyz;
382
487
  return context(lighting, {
383
488
  positionView: view,
384
489
  positionWorld: world,
@@ -388,7 +493,7 @@ var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
388
493
  };
389
494
 
390
495
  // src/box-impostor/box-impostor-ray-bounds.js
391
- import { Matrix4, NodeUpdateType, StorageBufferAttribute, Vector3 } from "three/webgpu";
496
+ import { Matrix4, NodeUpdateType as NodeUpdateType2, StorageBufferAttribute, Vector3 } from "three/webgpu";
392
497
  import {
393
498
  Fn as Fn2,
394
499
  If,
@@ -398,17 +503,17 @@ import {
398
503
  clamp,
399
504
  float,
400
505
  floor,
401
- instanceIndex,
402
- int,
403
- ivec2,
506
+ instanceIndex as instanceIndex2,
507
+ int as int2,
508
+ ivec2 as ivec22,
404
509
  max,
405
510
  min,
406
511
  storage,
407
- textureLoad,
512
+ textureLoad as textureLoad2,
408
513
  uint,
409
514
  vec2,
410
- vec3,
411
- vec4 as vec43
515
+ vec3 as vec32,
516
+ vec4 as vec44
412
517
  } from "three/tsl";
413
518
  var MIN_TILE_SIZE = 3;
414
519
  var MAX_CAPTURE_TILES = 512 * 1024;
@@ -451,18 +556,18 @@ function buildPatches(descriptor, maps, rects, tiles, size, output) {
451
556
  const descriptions = storage(tiles, "vec4", tiles.count).toReadOnly();
452
557
  const patches = storage(output, "vec4", output.count);
453
558
  return Fn2(() => {
454
- const meta = descriptions.element(instanceIndex).toVar();
455
- const key = int(meta.x), face = key.mod(6), axis = face.div(2);
456
- const rect = textureLoad(rects, ivec2(face, key.div(6))).mul(descriptor.atlasResolution).round().toVar();
457
- const extent = ivec2(rect.zw.add(1).sub(meta.yz)).min(ivec2(size));
458
- const origin = ivec2(rect.xy.add(meta.yz));
559
+ const meta = descriptions.element(instanceIndex2).toVar();
560
+ const key = int2(meta.x), face = key.mod(6), axis = face.div(2);
561
+ const rect = textureLoad2(rects, ivec22(face, key.div(6))).mul(descriptor.atlasResolution).round().toVar();
562
+ const extent = ivec22(rect.zw.add(1).sub(meta.yz)).min(ivec22(size));
563
+ const origin = ivec22(rect.xy.add(meta.yz));
459
564
  const near = float(1).toVar(), far = float(0).toVar();
460
565
  function visit(process) {
461
- Loop({ start: int(0), end: extent.y, type: "int", name: "row" }, ({ row }) => {
462
- Loop({ start: int(0), end: extent.x, type: "int", name: "column" }, ({ column }) => {
463
- const pixel = origin.add(ivec2(column, row));
464
- If(textureLoad(maps.orm, pixel).a.greaterThan(0.5), () => {
465
- const packed = textureLoad(maps.normalDepth, pixel);
566
+ Loop({ start: int2(0), end: extent.y, type: "int", name: "row" }, ({ row }) => {
567
+ Loop({ start: int2(0), end: extent.x, type: "int", name: "column" }, ({ column }) => {
568
+ const pixel = origin.add(ivec22(column, row));
569
+ If(textureLoad2(maps.orm, pixel).a.greaterThan(0.5), () => {
570
+ const packed = textureLoad2(maps.normalDepth, pixel);
466
571
  const depth = packed.b.mul(65280).add(packed.a.mul(255)).div(DEPTH_MAX).toVar();
467
572
  process(column, row, depth);
468
573
  });
@@ -474,11 +579,11 @@ function buildPatches(descriptor, maps, rects, tiles, size, output) {
474
579
  far.assign(max(far, depth));
475
580
  });
476
581
  const middle = near.add(far).mul(0.5).toVar();
477
- const low = [vec3(2).toVar(), vec3(2).toVar()], high = [vec3(-2).toVar(), vec3(-2).toVar()];
582
+ const low = [vec32(2).toVar(), vec32(2).toVar()], high = [vec32(-2).toVar(), vec32(-2).toVar()];
478
583
  visit((x, y, depth) => {
479
584
  const uv2 = meta.yz.add(vec2(x, y)).div(rect.zw).mul(2).sub(1);
480
- const lo = vec3(uv2.clamp(-1, 1), float(1).sub(depth.mul(2)).sub(meta.w).max(-1)).toVar();
481
- const hi = vec3(
585
+ const lo = vec32(uv2.clamp(-1, 1), float(1).sub(depth.mul(2)).sub(meta.w).max(-1)).toVar();
586
+ const hi = vec32(
482
587
  uv2.add(vec2(2).div(rect.zw)).clamp(-1, 1),
483
588
  float(1).sub(depth.mul(2)).add(meta.w).min(1)
484
589
  ).toVar();
@@ -495,38 +600,38 @@ function buildPatches(descriptor, maps, rects, tiles, size, output) {
495
600
  });
496
601
  });
497
602
  const facing = face.mod(2).equal(0).select(1, -1);
498
- const right = axis.equal(0).select(vec3(0, 0, facing.negate()), axis.equal(1).select(vec3(1, 0, 0), vec3(facing, 0, 0)));
499
- const up = axis.equal(1).select(vec3(0, 0, facing.negate()), vec3(0, 1, 0));
603
+ const right = axis.equal(0).select(vec32(0, 0, facing.negate()), axis.equal(1).select(vec32(1, 0, 0), vec32(facing, 0, 0)));
604
+ const up = axis.equal(1).select(vec32(0, 0, facing.negate()), vec32(0, 1, 0));
500
605
  const normal = right.cross(up);
501
606
  const rotate = (p) => right.mul(p.x).add(up.mul(p.y)).add(normal.mul(p.z));
502
607
  for (let group = 0; group < 2; group++) {
503
- const a = rotate(low[group]), b = rotate(high[group]), slot = instanceIndex.mul(4).add(group * 2);
608
+ const a = rotate(low[group]), b = rotate(high[group]), slot = instanceIndex2.mul(4).add(group * 2);
504
609
  const valid = low[group].x.lessThanEqual(high[group].x);
505
- patches.element(slot).assign(vec43(min(a, b), valid.select(meta.x, -1)));
506
- patches.element(slot.add(1)).assign(vec43(max(a, b), 0));
610
+ patches.element(slot).assign(vec44(min(a, b), valid.select(meta.x, -1)));
611
+ patches.element(slot.add(1)).assign(vec44(max(a, b), 0));
507
612
  }
508
613
  })().compute(tiles.count);
509
614
  }
510
615
  function makeViewPasses(patchBuffer, views, ranges, count, resolution) {
511
616
  const table = storage(ranges, "uint", count).toAtomic();
512
617
  const reset = Fn2(() => {
513
- atomicStore(table.element(instanceIndex), uint(DEPTH_MAX));
618
+ atomicStore(table.element(instanceIndex2), uint(DEPTH_MAX));
514
619
  })().compute(count);
515
620
  const patches = storage(patchBuffer, "vec4", patchBuffer.count).toReadOnly();
516
621
  const scatter = Fn2(() => {
517
- const a = patches.element(instanceIndex.mul(2)).toVar(), b = patches.element(instanceIndex.mul(2).add(1)).toVar();
622
+ const a = patches.element(instanceIndex2.mul(2)).toVar(), b = patches.element(instanceIndex2.mul(2).add(1)).toVar();
518
623
  If(a.w.greaterThanEqual(0), () => {
519
- const key = int(a.w), box = key.div(6);
624
+ const key = int2(a.w), box = key.div(6);
520
625
  const mapping = views.element(box.mul(2)), reference = views.element(box.mul(2).add(1));
521
626
  If(reference.w.greaterThanEqual(0), () => {
522
- const axis = int(reference.w).mod(3), x = axis.add(1).mod(3), y = axis.add(2).mod(3);
627
+ const axis = int2(reference.w).mod(3), x = axis.add(1).mod(3), y = axis.add(2).mod(3);
523
628
  const e = vec2(reference.element(x), reference.element(y)), ez = reference.element(axis);
524
629
  const za = a.element(axis), zb = b.element(axis);
525
630
  const weight = reference.w.lessThan(3).select(1, 0).toVar();
526
631
  const eyeSlope = e.div(ez).toVar(), inverseDistance = weight.div(ez).toVar();
527
632
  const project = (v, z) => v.sub(eyeSlope.mul(z)).div(float(1).sub(inverseDistance.mul(z)));
528
633
  const l = vec2(a.element(x), a.element(y)), h = vec2(b.element(x), b.element(y));
529
- const cell = (v, bias) => ivec2(floor(v.sub(mapping.xy).mul(mapping.zw).add(bias)).clamp(0, resolution - 1));
634
+ const cell = (v, bias) => ivec22(floor(v.sub(mapping.xy).mul(mapping.zw).add(bias)).clamp(0, resolution - 1));
530
635
  const lo = cell(min(project(l, za), project(l, zb)), -5e-3);
531
636
  const hi = cell(max(project(h, za), project(h, zb)), 5e-3);
532
637
  const padding = vec2(0.506).div(mapping.zw).mul(inverseDistance.abs().add(1)).add(2e-6);
@@ -678,7 +783,7 @@ function createBoxRayBounds(descriptor, maps, rects, material) {
678
783
  slot.ortho = ortho;
679
784
  slot.ready = true;
680
785
  }
681
- views.updateBeforeType = NodeUpdateType.OBJECT;
786
+ views.updateBeforeType = NodeUpdateType2.OBJECT;
682
787
  views.updateBefore = prepare;
683
788
  material.addEventListener("dispose", () => {
684
789
  for (const state of states.values()) {
@@ -700,7 +805,7 @@ function createBoxRayBounds(descriptor, maps, rects, material) {
700
805
  if (!builder.renderer.backend?.isWebGPUBackend) return null;
701
806
  const mapping = views.element(id.mul(2)).toVar();
702
807
  const ref = views.element(id.mul(2).add(1)).toVar();
703
- const axis = int(max(ref.w, 0)).mod(3), x = axis.add(1).mod(3), y = axis.add(2).mod(3);
808
+ const axis = int2(max(ref.w, 0)).mod(3), x = axis.add(1).mod(3), y = axis.add(2).mod(3);
704
809
  const rz = r.element(axis).toVar(), oz = o.element(axis).toVar();
705
810
  const ez = ref.element(axis), e = vec2(ref.element(x), ref.element(y));
706
811
  const eyeSlope = e.div(ez), inverseDistance = ref.w.lessThan(3).select(1, 0).div(ez);
@@ -710,9 +815,9 @@ function createBoxRayBounds(descriptor, maps, rects, material) {
710
815
  return p.sub(mapping.xy).mul(mapping.zw);
711
816
  };
712
817
  const a = project(enter).toVar(), b = project(exit).toVar();
713
- const cellLo = ivec2(floor(min(a, b).sub(1e-3)).clamp(0, resolution - 1)).toVar();
714
- const cellHi = ivec2(floor(max(a, b).add(1e-3)).clamp(0, resolution - 1)).toVar();
715
- const valid = ref.w.greaterThanEqual(0).and(rz.abs().greaterThan(1e-12)).and(cellHi.sub(cellLo).lessThanEqual(ivec2(2)).all()).toVar();
818
+ const cellLo = ivec22(floor(min(a, b).sub(1e-3)).clamp(0, resolution - 1)).toVar();
819
+ const cellHi = ivec22(floor(max(a, b).add(1e-3)).clamp(0, resolution - 1)).toVar();
820
+ const valid = ref.w.greaterThanEqual(0).and(rz.abs().greaterThan(1e-12)).and(cellHi.sub(cellLo).lessThanEqual(ivec22(2)).all()).toVar();
716
821
  return (face, enter2, exit2) => {
717
822
  const start = enter2.toVar(), end = exit2.toVar();
718
823
  If(valid, () => {
@@ -756,21 +861,21 @@ function refineSurfaceCrossing({ float: float5, If: If5, Loop: Loop3 }, { lo, hi
756
861
  }
757
862
 
758
863
  // src/box-impostor/box-impostor-faces.js
759
- import { DataTexture, FloatType, RGBAFormat, NearestFilter } from "three";
864
+ import { DataTexture as DataTexture2, FloatType as FloatType2, RGBAFormat as RGBAFormat2, NearestFilter } from "three";
760
865
  import {
761
866
  Fn as Fn3,
762
867
  If as If2,
763
868
  attribute,
764
- positionLocal,
869
+ positionGeometry,
765
870
  uv,
766
871
  texture,
767
- textureLoad as textureLoad2,
768
- ivec2 as ivec22,
872
+ textureLoad as textureLoad3,
873
+ ivec2 as ivec23,
769
874
  vec2 as vec22,
770
- vec3 as vec32,
875
+ vec3 as vec33,
771
876
  float as float2,
772
- int as int2,
773
- dot,
877
+ int as int3,
878
+ dot as dot2,
774
879
  abs,
775
880
  max as max2,
776
881
  sign,
@@ -784,45 +889,47 @@ function applyBoxFaces({
784
889
  transparency,
785
890
  half,
786
891
  toBox,
787
- fromBox
892
+ fromBox,
893
+ meshVertex,
894
+ meshNormal
788
895
  }) {
789
896
  const values = new Float32Array(descriptor.boxes.length * 6 * 4);
790
897
  descriptor.boxes.forEach((box, i) => {
791
898
  for (let face2 = 0; face2 < 6; face2++)
792
899
  values[(i * 6 + face2) * 4] = box.planes?.[face2] ?? 0.5;
793
900
  });
794
- const planes = new DataTexture(
901
+ const planes = new DataTexture2(
795
902
  values,
796
903
  6,
797
904
  descriptor.boxes.length,
798
- RGBAFormat,
799
- FloatType
905
+ RGBAFormat2,
906
+ FloatType2
800
907
  );
801
908
  planes.minFilter = planes.magFilter = NearestFilter;
802
909
  planes.needsUpdate = true;
803
910
  material.addEventListener("dispose", () => planes.dispose());
804
- const face = int2(attribute("boxFace", "float"));
911
+ const face = int3(attribute("boxFace", "float"));
805
912
  const n = attribute("normal", "vec3");
806
- const depth = textureLoad2(
913
+ const depth = textureLoad3(
807
914
  planes,
808
- ivec22(face, int2(attribute("boxId", "float")))
915
+ ivec23(face, int3(attribute("boxId", "float")))
809
916
  ).r;
810
- const proxy = positionLocal.sub(
917
+ const proxy = positionGeometry.sub(
811
918
  n.mul(
812
- dot(abs(toBox(n)), half).mul(depth).mul(2)
919
+ dot2(abs(toBox(n)), half).mul(depth).mul(2)
813
920
  )
814
921
  );
815
- material.positionNode = proxy;
816
- material.castShadowPositionNode = proxy;
922
+ material.positionNode = meshVertex(proxy);
923
+ material.castShadowPositionNode = material.positionNode;
817
924
  const base = texture(maps.baseColor, uv()).level(0).toVar("boxFaceColor");
818
925
  const orm = texture(maps.orm, uv()).level(0);
819
926
  const coverage = max2(orm.a, 1e-10);
820
927
  const normal = Fn3(() => {
821
- const packed = textureLoad2(
928
+ const packed = textureLoad3(
822
929
  maps.normalDepth,
823
- ivec22(uv().mul(descriptor.atlasResolution))
930
+ ivec23(uv().mul(descriptor.atlasResolution))
824
931
  ).rg.mul(2).sub(1);
825
- const decoded = vec32(
932
+ const decoded = vec33(
826
933
  packed,
827
934
  float2(1).sub(abs(packed.x)).sub(abs(packed.y))
828
935
  ).toVar();
@@ -831,13 +938,13 @@ function applyBoxFaces({
831
938
  vec22(1).sub(abs(decoded.yx)).mul(sign(decoded.xy.add(1e-20)))
832
939
  );
833
940
  });
834
- const result = vec32(0).toVar();
941
+ const result = vec33(0).toVar();
835
942
  for (let f = 0; f < 6; f++) {
836
943
  const a = BOX_FACE_AXES[f];
837
944
  If2(face.equal(f), () => {
838
945
  result.assign(
839
946
  fromBox(
840
- vec32(...a.right).mul(decoded.x).add(vec32(...a.up).mul(decoded.y)).add(vec32(...a.normal).mul(decoded.z))
947
+ vec33(...a.right).mul(decoded.x).add(vec33(...a.up).mul(decoded.y)).add(vec33(...a.normal).mul(decoded.z))
841
948
  ).normalize()
842
949
  );
843
950
  });
@@ -845,7 +952,7 @@ function applyBoxFaces({
845
952
  return result;
846
953
  })();
847
954
  material.colorNode = base.rgb.div(coverage);
848
- material.normalNode = transformNormalToView(normal);
955
+ material.normalNode = transformNormalToView(meshNormal(normal));
849
956
  material.roughnessNode = orm.g.div(coverage);
850
957
  material.metalnessNode = orm.b.div(coverage);
851
958
  material.aoNode = orm.r.div(coverage);
@@ -860,23 +967,23 @@ function applyBoxFaces({
860
967
  }
861
968
 
862
969
  // src/box-impostor/box-impostor-projection.js
863
- import { DataTexture as DataTexture2, FloatType as FloatType2, RGBAFormat as RGBAFormat2, NearestFilter as NearestFilter2 } from "three";
970
+ import { DataTexture as DataTexture3, FloatType as FloatType3, RGBAFormat as RGBAFormat3, NearestFilter as NearestFilter2 } from "three";
864
971
  import {
865
972
  Fn as Fn4,
866
973
  If as If3,
867
974
  vec2 as vec23,
868
- vec3 as vec33,
869
- vec4 as vec44,
975
+ vec3 as vec34,
976
+ vec4 as vec45,
870
977
  float as float3,
871
- int as int3,
872
- ivec2 as ivec23,
873
- dot as dot2,
978
+ int as int4,
979
+ ivec2 as ivec24,
980
+ dot as dot3,
874
981
  abs as abs2,
875
982
  max as max3,
876
983
  sign as sign2,
877
984
  normalize,
878
985
  texture as texture2,
879
- textureLoad as textureLoad3,
986
+ textureLoad as textureLoad4,
880
987
  attribute as attribute2,
881
988
  struct,
882
989
  modelWorldMatrix as modelWorldMatrix2,
@@ -897,19 +1004,21 @@ function applyBoxProjection({
897
1004
  eye,
898
1005
  viewAxis,
899
1006
  perspective,
900
- raster
1007
+ raster,
1008
+ meshPoint,
1009
+ meshNormal
901
1010
  }) {
902
1011
  const data = new Float32Array(descriptor.boxes.length * 24);
903
1012
  descriptor.boxes.forEach((box, i) => {
904
1013
  for (let face = 0; face < 6; face++)
905
1014
  data[(i * 6 + face) * 4] = box.planes?.[face] ?? 0.5;
906
1015
  });
907
- const planes = new DataTexture2(
1016
+ const planes = new DataTexture3(
908
1017
  data,
909
1018
  6,
910
1019
  descriptor.boxes.length,
911
- RGBAFormat2,
912
- FloatType2
1020
+ RGBAFormat3,
1021
+ FloatType3
913
1022
  );
914
1023
  planes.minFilter = planes.magFilter = NearestFilter2;
915
1024
  planes.needsUpdate = true;
@@ -926,11 +1035,11 @@ function applyBoxProjection({
926
1035
  "BoxProjectedSurface"
927
1036
  );
928
1037
  const readNormal = (uv2, right, up, n) => {
929
- const packed = textureLoad3(
1038
+ const packed = textureLoad4(
930
1039
  maps.normalDepth,
931
- ivec23(uv2.mul(descriptor.atlasResolution))
1040
+ ivec24(uv2.mul(descriptor.atlasResolution))
932
1041
  ).rg.mul(2).sub(1);
933
- const decoded = vec33(
1042
+ const decoded = vec34(
934
1043
  packed,
935
1044
  float3(1).sub(abs2(packed.x)).sub(abs2(packed.y))
936
1045
  ).toVar();
@@ -954,20 +1063,20 @@ function applyBoxProjection({
954
1063
  );
955
1064
  const o = toBox(origin.sub(center)).div(half), r = toBox(ray).div(half);
956
1065
  const look = normalize(toBox(ray).negate()), angles = abs2(look);
957
- const positions = vec33(0).toVar();
958
- const selectedUv = vec23(0).toVar(), selectedRight = vec33(1, 0, 0).toVar(), selectedUp = vec33(0, 1, 0).toVar(), selectedNormal = vec33(0, 0, 1).toVar();
1066
+ const positions = vec34(0).toVar();
1067
+ const selectedUv = vec23(0).toVar(), selectedRight = vec34(1, 0, 0).toVar(), selectedUp = vec34(0, 1, 0).toVar(), selectedNormal = vec34(0, 0, 1).toVar();
959
1068
  const nearest = float3(1e20).toVar("boxPlaneDistance");
960
1069
  const opacity = float3(0).toVar();
961
1070
  const candidates = [];
962
1071
  for (let axis = 0; axis < 3; axis++) {
963
1072
  const angle = angles.element(axis);
964
1073
  const positive = look.element(axis).greaterThanEqual(0), a = BOX_FACE_AXES[axis * 2], b = BOX_FACE_AXES[axis * 2 + 1];
965
- 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));
1074
+ 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));
966
1075
  const weight = settings.interpolation === "smooth" ? angle.mul(angle) : angle;
967
1076
  const candidate = settings.interpolation === "none" ? null : {
968
1077
  uv: vec23(0).toVar(),
969
- base: vec44(0).toVar(),
970
- orm: vec44(0).toVar(),
1078
+ base: vec45(0).toVar(),
1079
+ orm: vec45(0).toVar(),
971
1080
  t: float3(1e20).toVar(),
972
1081
  tolerance: float3(0).toVar(),
973
1082
  right,
@@ -977,17 +1086,17 @@ function applyBoxProjection({
977
1086
  };
978
1087
  if (candidate) candidates.push(candidate);
979
1088
  If3(angle.greaterThan(1e-4), () => {
980
- const face = positive.select(int3(axis * 2), int3(axis * 2 + 1)), id = int3(attribute2("boxId", "float"));
1089
+ const face = positive.select(int4(axis * 2), int4(axis * 2 + 1)), id = int4(attribute2("boxId", "float"));
981
1090
  const plane = float3(1).sub(
982
- textureLoad3(planes, ivec23(face, id)).r.mul(2)
1091
+ textureLoad4(planes, ivec24(face, id)).r.mul(2)
983
1092
  );
984
- const divisor2 = dot2(r, n), safe = sign2(divisor2.add(1e-20)).mul(max3(abs2(divisor2), 1e-10));
985
- const t = plane.sub(dot2(o, n)).div(safe), point = o.add(r.mul(t));
986
- const xy = vec23(dot2(point, right), dot2(point, up)).mul(0.5).add(0.5);
1093
+ const divisor2 = dot3(r, n), safe = sign2(divisor2.add(1e-20)).mul(max3(abs2(divisor2), 1e-10));
1094
+ const t = plane.sub(dot3(o, n)).div(safe), point = o.add(r.mul(t));
1095
+ const xy = vec23(dot3(point, right), dot3(point, up)).mul(0.5).add(0.5);
987
1096
  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));
988
1097
  if (!candidate) supported = supported.and(t.lessThan(nearest));
989
1098
  If3(supported, () => {
990
- const rect = textureLoad3(rects, ivec23(face, id)), uv2 = rect.xy.add(xy.mul(rect.zw));
1099
+ const rect = textureLoad4(rects, ivec24(face, id)), uv2 = rect.xy.add(xy.mul(rect.zw));
991
1100
  const base = texture2(maps.baseColor, uv2).level(0), orm = texture2(maps.orm, uv2).level(0);
992
1101
  const alpha2 = base.a.clamp(0, 1);
993
1102
  If3(
@@ -1011,10 +1120,10 @@ function applyBoxProjection({
1011
1120
  candidate.t.assign(t);
1012
1121
  candidate.tolerance.assign(
1013
1122
  max3(
1014
- dot2(abs2(right), half).div(
1123
+ dot3(abs2(right), half).div(
1015
1124
  rect.z.mul(descriptor.atlasResolution)
1016
1125
  ),
1017
- dot2(abs2(up), half).div(
1126
+ dot3(abs2(up), half).div(
1018
1127
  rect.w.mul(descriptor.atlasResolution)
1019
1128
  )
1020
1129
  ).mul(4).div(max3(angle, 0.1))
@@ -1037,7 +1146,7 @@ function applyBoxProjection({
1037
1146
  positions
1038
1147
  );
1039
1148
  }
1040
- const colors = vec33(0).toVar(), orms = vec33(0).toVar(), emissions = vec33(0).toVar(), normals = vec33(0).toVar();
1149
+ const colors = vec34(0).toVar(), orms = vec34(0).toVar(), emissions = vec34(0).toVar(), normals = vec34(0).toVar();
1041
1150
  const weights = float3(0).toVar(), support = float3(0).toVar(), alpha = float3(0).toVar();
1042
1151
  for (const c of candidates) {
1043
1152
  If3(
@@ -1066,9 +1175,10 @@ function applyBoxProjection({
1066
1175
  positions
1067
1176
  );
1068
1177
  })().toVar("boxProjectedSurface");
1069
- material.capturedPositionNode = surface.get("position");
1178
+ const position = meshPoint(surface.get("position")).toVar("boxProjectedMeshPosition");
1179
+ material.capturedPositionNode = position;
1070
1180
  material.colorNode = surface.get("color");
1071
- material.normalNode = transformNormalToView2(surface.get("normal"));
1181
+ material.normalNode = transformNormalToView2(meshNormal(surface.get("normal")));
1072
1182
  material.roughnessNode = surface.get("orm").g;
1073
1183
  material.metalnessNode = surface.get("orm").b;
1074
1184
  material.aoNode = surface.get("orm").r;
@@ -1076,9 +1186,9 @@ function applyBoxProjection({
1076
1186
  material.maskNode = surface.get("alpha").greaterThanEqual(transparency === "cutout" ? alphaCutoff : float3(1 / 255));
1077
1187
  material.maskShadowNode = material.maskNode;
1078
1188
  if (transparency !== "cutout") material.opacityNode = surface.get("alpha");
1079
- material.depthNode = capturedSurfaceDepth(surface.get("position"));
1189
+ material.depthNode = capturedSurfaceDepth(position);
1080
1190
  material.receivedShadowPositionNode = modelWorldMatrix2.mul(
1081
- vec44(surface.get("position"), 1)
1191
+ vec45(position, 1)
1082
1192
  ).xyz;
1083
1193
  material.userData.boxImpostor = { descriptor, maps, alphaCutoff };
1084
1194
  return material;
@@ -1096,7 +1206,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1096
1206
  const surfaceCoverage = (ormAlpha, baseAlpha) => filtering && descriptor.alphaMode !== "blend" ? min2(ormAlpha, baseAlpha) : ormAlpha;
1097
1207
  const unpackNormal = (encoded) => {
1098
1208
  const packed = encoded.mul(2).sub(1);
1099
- const normal2 = vec34(packed, float4(1).sub(abs3(packed.x)).sub(abs3(packed.y))).toVar();
1209
+ const normal2 = vec35(packed, float4(1).sub(abs3(packed.x)).sub(abs3(packed.y))).toVar();
1100
1210
  If4(normal2.z.lessThan(0), () => {
1101
1211
  normal2.xy.assign(vec24(1).sub(abs3(normal2.yx)).mul(sign3(normal2.xy.add(1e-20))));
1102
1212
  });
@@ -1109,14 +1219,14 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1109
1219
  const nearestNormal = decodeNormal(nearest.rg), result = decodeNormal(sampled.rg.div(coverage2)).toVar();
1110
1220
  const sampledDepth = sampled.b.mul(65280).add(sampled.a.mul(255)).div(65535);
1111
1221
  const nearestDepth = nearest.b.mul(65280).add(nearest.a.mul(255)).div(65535);
1112
- If4(nearestNormal.z.lessThan(0).or(dot3(result, nearestNormal).lessThan(0.75)).or(coverage2.lessThan(0.9999)).or(abs3(sampledDepth.sub(nearestDepth)).greaterThan(tolerance)), () => {
1222
+ If4(nearestNormal.z.lessThan(0).or(dot4(result, nearestNormal).lessThan(0.75)).or(coverage2.lessThan(0.9999)).or(abs3(sampledDepth.sub(nearestDepth)).greaterThan(tolerance)), () => {
1113
1223
  const p = uv2.mul(descriptor.atlasResolution).sub(0.5), lo = floor2(p), f = fract(p);
1114
- const normal2 = vec34(0).toVar(), weights = float4(0).toVar();
1224
+ const normal2 = vec35(0).toVar(), weights = float4(0).toVar();
1115
1225
  for (const [x, y] of [[0, 0], [1, 0], [0, 1], [1, 1]]) {
1116
- const texel = ivec24(lo.add(vec24(x, y)).clamp(0, descriptor.atlasResolution - 1));
1117
- const packed = textureLoad4(maps.normalDepth, texel).toVar();
1118
- const alpha2 = textureLoad4(maps.baseColor, texel).a;
1119
- const coverage3 = descriptor.alphaMode === "blend" ? textureLoad4(maps.orm, texel).a : alpha2;
1226
+ const texel = ivec25(lo.add(vec24(x, y)).clamp(0, descriptor.atlasResolution - 1));
1227
+ const packed = textureLoad5(maps.normalDepth, texel).toVar();
1228
+ const alpha2 = textureLoad5(maps.baseColor, texel).a;
1229
+ const coverage3 = descriptor.alphaMode === "blend" ? textureLoad5(maps.orm, texel).a : alpha2;
1120
1230
  const capturedDepth = packed.b.mul(65280).add(packed.a.mul(255)).div(65535);
1121
1231
  const supported = coverage3.greaterThan(1e-4).and(alpha2.greaterThanEqual(minimumAlpha.mul(coverage3))).and(abs3(capturedDepth.sub(depth)).lessThanEqual(tolerance));
1122
1232
  If4(supported, () => {
@@ -1158,46 +1268,57 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1158
1268
  )
1159
1269
  )
1160
1270
  );
1161
- const rects = new DataTexture3(
1271
+ const rects = new DataTexture4(
1162
1272
  rectData,
1163
1273
  6,
1164
1274
  descriptor.boxes.length,
1165
- RGBAFormat3,
1166
- FloatType3
1275
+ RGBAFormat4,
1276
+ FloatType4
1167
1277
  );
1168
1278
  rects.needsUpdate = true;
1169
1279
  rects.magFilter = rects.minFilter = NearestFilter3;
1170
1280
  material.addEventListener("dispose", () => rects.dispose());
1171
1281
  const center = attribute3("boxCenter", "vec3"), half = attribute3("boxHalfSize", "vec3");
1172
1282
  const ax = attribute3("boxAxisX", "vec3"), ay = attribute3("boxAxisY", "vec3"), az = attribute3("boxAxisZ", "vec3");
1173
- const toBox = (p) => vec34(dot3(p, ax), dot3(p, ay), dot3(p, az));
1283
+ const toBox = (p) => vec35(dot4(p, ax), dot4(p, ay), dot4(p, az));
1174
1284
  const fromBox = (p) => ax.mul(p.x).add(ay.mul(p.y)).add(az.mul(p.z));
1175
- const eye = modelWorldMatrixInverse.mul(vec45(cameraPosition, 1)).xyz;
1176
- const viewAxis = modelWorldMatrixInverse.mul(cameraWorldMatrix.mul(vec45(0, 0, 1, 0))).xyz.normalize();
1285
+ const meshVertex = (p) => Fn5((_, builder) => instanceSpace(builder)?.toMeshPoint(p) ?? p)();
1286
+ const meshPoint = (p) => Fn5((_, builder) => instanceSpace(builder)?.fragment.toMeshPoint(p) ?? p)();
1287
+ const meshNormal = (n) => Fn5((_, builder) => instanceSpace(builder)?.fragment.toMeshNormal(n) ?? n)();
1288
+ const meshEye = modelWorldMatrixInverse.mul(vec46(cameraPosition, 1)).xyz;
1289
+ const meshViewAxis = modelWorldMatrixInverse.mul(cameraWorldMatrix.mul(vec46(0, 0, 1, 0))).xyz;
1290
+ const eye = Fn5((_, builder) => instanceSpace(builder)?.fragment.toLocalPoint(meshEye) ?? meshEye)();
1291
+ const viewAxis = Fn5((_, builder) => instanceSpace(builder)?.fragment.toLocalDirection(meshViewAxis) ?? meshViewAxis)().normalize();
1292
+ const vertexEye = Fn5((_, builder) => instanceSpace(builder)?.toLocalPoint(meshEye) ?? meshEye)();
1293
+ const vertexViewAxis = Fn5((_, builder) => instanceSpace(builder)?.toLocalDirection(meshViewAxis) ?? meshViewAxis)().normalize();
1294
+ const cameraUp = Fn5((_, builder) => {
1295
+ const up = modelWorldMatrixInverse.mul(cameraWorldMatrix.mul(vec46(0, 1, 0, 0))).xyz;
1296
+ return instanceSpace(builder)?.toLocalDirection(up) ?? up;
1297
+ })();
1177
1298
  const perspective = cameraProjectionMatrix2.element(3).w.equal(0);
1178
- let proxy = positionLocal2;
1299
+ let proxy = positionGeometry2;
1179
1300
  if (descriptor.mode !== "fitted") {
1180
1301
  proxy = Fn5((_, builder) => {
1181
- const delta = eye.sub(center);
1182
- const forward = perspective.and(delta.length().greaterThan(1e-6)).select(normalize2(delta), viewAxis);
1183
- const right = modelWorldMatrixInverse.mul(cameraWorldMatrix.mul(vec45(0, 1, 0, 0))).xyz.cross(forward).normalize();
1302
+ const delta = vertexEye.sub(center);
1303
+ const forward = perspective.and(delta.length().greaterThan(1e-6)).select(normalize2(delta), vertexViewAxis);
1304
+ const right = cameraUp.cross(forward).normalize();
1184
1305
  const up = forward.cross(right).normalize();
1185
1306
  const radius = half.length();
1186
- const distance = dot3(eye.sub(center), forward);
1307
+ const distance = dot4(vertexEye.sub(center), forward);
1187
1308
  const planeOffset = perspective.select(min2(radius, distance.sub(cameraNear2.mul(2))), radius);
1188
1309
  const plane = center.add(forward.mul(planeOffset));
1189
1310
  const lo = vec24(1e20).toVar(), hi = vec24(-1e20).toVar();
1190
1311
  for (const x of [-1, 1])
1191
1312
  for (const y of [-1, 1])
1192
1313
  for (const z of [-1, 1]) {
1193
- const corner2 = fromBox(half.mul(vec34(x, y, z)));
1314
+ const corner2 = fromBox(half.mul(vec35(x, y, z)));
1194
1315
  const scale = perspective.select(
1195
1316
  max4(distance.sub(planeOffset), 1e-5).div(
1196
- max4(distance.sub(dot3(corner2, forward)), 1e-5)
1317
+ max4(distance.sub(dot4(corner2, forward)), 1e-5)
1197
1318
  ),
1198
1319
  float4(1)
1199
1320
  );
1200
- const p = vec24(dot3(corner2, right), dot3(corner2, up)).mul(scale);
1321
+ const p = vec24(dot4(corner2, right), dot4(corner2, up)).mul(scale);
1201
1322
  lo.assign(min2(lo, p));
1202
1323
  hi.assign(max4(hi, p));
1203
1324
  }
@@ -1205,10 +1326,10 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1205
1326
  const xy = lo.add(hi.sub(lo).mul(corner));
1206
1327
  return plane.add(right.mul(xy.x)).add(up.mul(xy.y));
1207
1328
  })();
1208
- material.positionNode = proxy;
1209
- material.castShadowPositionNode = proxy;
1329
+ material.positionNode = meshVertex(proxy);
1330
+ material.castShadowPositionNode = material.positionNode;
1210
1331
  }
1211
- const raster = varying(proxy, "boxRasterPosition");
1332
+ const raster = varying2(proxy, "boxRasterPosition");
1212
1333
  if (boxDepthMode(descriptor, settings) === "projection" && descriptor.mode === "fitted" && settings.interpolation === "none") {
1213
1334
  material.side = FrontSide;
1214
1335
  return applyBoxFaces({
@@ -1219,7 +1340,9 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1219
1340
  transparency,
1220
1341
  half,
1221
1342
  toBox,
1222
- fromBox
1343
+ fromBox,
1344
+ meshVertex,
1345
+ meshNormal
1223
1346
  });
1224
1347
  }
1225
1348
  if (boxDepthMode(descriptor, settings) === "projection")
@@ -1238,7 +1361,9 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1238
1361
  eye,
1239
1362
  viewAxis,
1240
1363
  perspective,
1241
- raster
1364
+ raster,
1365
+ meshPoint,
1366
+ meshNormal
1242
1367
  });
1243
1368
  const accelerated = descriptor.boxes.every((b) => b.depthBounds);
1244
1369
  const gridSize = BOX_OCCUPANCY_RESOLUTION;
@@ -1251,7 +1376,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1251
1376
  descriptor.boxes.forEach(
1252
1377
  (box, index) => words.set(box.occupancy, index * wordsPerBox)
1253
1378
  );
1254
- occupancy = new DataTexture3(
1379
+ occupancy = new DataTexture4(
1255
1380
  words,
1256
1381
  wordsPerBox,
1257
1382
  descriptor.boxes.length,
@@ -1268,16 +1393,16 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1268
1393
  "BoxImpostorHit"
1269
1394
  );
1270
1395
  const faceBasis = (axis, facing) => {
1271
- const n = vec34(
1396
+ const n = vec35(
1272
1397
  axis.equal(0).select(facing, 0),
1273
1398
  axis.equal(1).select(facing, 0),
1274
1399
  axis.equal(2).select(facing, 0)
1275
1400
  ).toVar();
1276
1401
  const right = axis.equal(0).select(
1277
- vec34(0, 0, facing.negate()),
1278
- axis.equal(1).select(vec34(1, 0, 0), vec34(facing, 0, 0))
1402
+ vec35(0, 0, facing.negate()),
1403
+ axis.equal(1).select(vec35(1, 0, 0), vec35(facing, 0, 0))
1279
1404
  ).toVar();
1280
- const up = axis.equal(1).select(vec34(0, 0, facing.negate()), vec34(0, 1, 0)).toVar();
1405
+ const up = axis.equal(1).select(vec35(0, 0, facing.negate()), vec35(0, 1, 0)).toVar();
1281
1406
  return { n, right, up };
1282
1407
  };
1283
1408
  const ray = perspective.select(normalize2(raster.sub(eye)), viewAxis.negate());
@@ -1288,17 +1413,17 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1288
1413
  );
1289
1414
  const o = toBox(origin.sub(center)).div(half), r = toBox(ray).div(half);
1290
1415
  const safe = sign3(r.add(1e-20)).mul(max4(abs3(r), 1e-10));
1291
- const a = vec34(-1).sub(o).div(safe), b = vec34(1).sub(o).div(safe);
1416
+ const a = vec35(-1).sub(o).div(safe), b = vec35(1).sub(o).div(safe);
1292
1417
  const enter = max4(max4(min2(a, b).x, min2(a, b).y), min2(a, b).z).max(0);
1293
1418
  const exit = min2(min2(max4(a, b).x, max4(a, b).y), max4(a, b).z);
1294
- const rayBounds = viewBounds?.(builder, int4(attribute3("boxId", "float")), o, r, enter, exit);
1419
+ const rayBounds = viewBounds?.(builder, int5(attribute3("boxId", "float")), o, r, enter, exit);
1295
1420
  const occupiedStart = enter.toVar();
1296
1421
  if (occupancy) {
1297
1422
  const gridOrigin = o.add(1).mul(gridSize / 2);
1298
1423
  const gridRay = r.mul(gridSize / 2);
1299
1424
  const step = sign3(gridRay.add(1e-20));
1300
1425
  const cell = floor2(gridOrigin.add(gridRay.mul(enter))).clamp(0, gridSize - 1).toVar();
1301
- const inverse = vec34(1).div(safe.mul(gridSize / 2));
1426
+ const inverse = vec35(1).div(safe.mul(gridSize / 2));
1302
1427
  const delta = abs3(inverse);
1303
1428
  const next = cell.add(step.add(1).mul(0.5)).sub(gridOrigin).mul(inverse).toVar();
1304
1429
  const t = enter.toVar();
@@ -1310,9 +1435,9 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1310
1435
  const cellIndex = uint2(
1311
1436
  cell.x.add(cell.y.mul(gridSize)).add(cell.z.mul(gridSize ** 2))
1312
1437
  ).toVar();
1313
- const word = textureLoad4(
1438
+ const word = textureLoad5(
1314
1439
  occupancy,
1315
- ivec24(int4(cellIndex.shiftRight(5)), int4(attribute3("boxId", "float")))
1440
+ ivec25(int5(cellIndex.shiftRight(5)), int5(attribute3("boxId", "float")))
1316
1441
  ).r;
1317
1442
  const support = word.shiftRight(cellIndex.bitAnd(31)).bitAnd(1);
1318
1443
  If4(support.notEqual(uint2(0)), () => {
@@ -1320,7 +1445,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1320
1445
  Break();
1321
1446
  });
1322
1447
  const edge = min2(min2(next.x, next.y), next.z).toVar();
1323
- const advance = vec34(
1448
+ const advance = vec35(
1324
1449
  next.x.lessThanEqual(edge).select(1, 0),
1325
1450
  next.y.lessThanEqual(edge).select(1, 0),
1326
1451
  next.z.lessThanEqual(edge).select(1, 0)
@@ -1337,15 +1462,15 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1337
1462
  });
1338
1463
  }
1339
1464
  const look = toBox(ray).negate();
1340
- 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();
1465
+ 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();
1341
1466
  const angles = abs3(look).toVar();
1342
1467
  const major = angles.x.greaterThanEqual(angles.y).and(angles.x.greaterThanEqual(angles.z)).select(
1343
- int4(0),
1344
- angles.y.greaterThanEqual(angles.z).select(int4(1), int4(2))
1468
+ int5(0),
1469
+ angles.y.greaterThanEqual(angles.z).select(int5(1), int5(2))
1345
1470
  ).toVar();
1346
1471
  const nextAxis = major.add(1).mod(3), lastAxis = major.add(2).mod(3);
1347
1472
  const second = angles.element(nextAxis).greaterThanEqual(angles.element(lastAxis)).select(nextAxis, lastAxis).toVar();
1348
- const third = int4(3).sub(major).sub(second).toVar();
1473
+ const third = int5(3).sub(major).sub(second).toVar();
1349
1474
  Loop2(
1350
1475
  { start: 0, end: 6, type: "int", name: "viewIndex" },
1351
1476
  ({ viewIndex: i }) => {
@@ -1359,24 +1484,24 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1359
1484
  look.element(axis).greaterThanEqual(0),
1360
1485
  look.element(axis).lessThan(0)
1361
1486
  );
1362
- const face = axis.mul(2).add(positive.select(int4(0), int4(1)));
1487
+ const face = axis.mul(2).add(positive.select(int5(0), int5(1)));
1363
1488
  const bounds = rayBounds?.(face, enter, exit);
1364
1489
  const facing = positive.select(1, -1);
1365
1490
  const { n, right, up } = faceBasis(axis, facing);
1366
1491
  const direction = i.lessThan(3).select(1, -1);
1367
- const rect = textureLoad4(
1492
+ const rect = textureLoad5(
1368
1493
  rects,
1369
- ivec24(face, int4(attribute3("boxId", "float")))
1494
+ ivec25(face, int5(attribute3("boxId", "float")))
1370
1495
  ).toVar();
1371
1496
  const sampleUv = (p) => rect.xy.add(
1372
- vec24(dot3(p, right), dot3(p, up)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
1497
+ vec24(dot4(p, right), dot4(p, up)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
1373
1498
  );
1374
1499
  const decode = (d) => d.b.mul(65280).add(d.a.mul(255)).div(65535);
1375
1500
  const depthAt = (uv2) => decode(texture3(maps.normalDepth, uv2).level(0));
1376
- const projectedOrigin = vec24(dot3(o, right), dot3(o, up)).toVar();
1377
- const projectedRay = vec24(dot3(r, right), dot3(r, up)).toVar();
1378
- const axialOrigin = dot3(o, n).toVar();
1379
- const axialRay = dot3(r, n).toVar();
1501
+ const projectedOrigin = vec24(dot4(o, right), dot4(o, up)).toVar();
1502
+ const projectedRay = vec24(dot4(r, right), dot4(r, up)).toVar();
1503
+ const axialOrigin = dot4(o, n).toVar();
1504
+ const axialRay = dot4(r, n).toVar();
1380
1505
  const distance = (t) => {
1381
1506
  const uv2 = rect.xy.add(
1382
1507
  projectedOrigin.add(projectedRay.mul(t)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
@@ -1385,17 +1510,17 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1385
1510
  };
1386
1511
  const acceptHit = (hitT) => {
1387
1512
  const point2 = o.add(r.mul(hitT)), uv2 = sampleUv(point2);
1388
- const texel = ivec24(uv2.mul(descriptor.atlasResolution));
1389
- const nearest = textureLoad4(maps.normalDepth, texel);
1513
+ const texel = ivec25(uv2.mul(descriptor.atlasResolution));
1514
+ const nearest = textureLoad5(maps.normalDepth, texel);
1390
1515
  const capturedBase = texture3(maps.baseColor, uv2).level(0);
1391
- const occupied = textureLoad4(maps.orm, texel).a.greaterThan(0.5);
1516
+ const occupied = textureLoad5(maps.orm, texel).a.greaterThan(0.5);
1392
1517
  const residual = abs3(
1393
- dot3(point2, n).sub(float4(1).sub(decode(nearest).mul(2)))
1518
+ dot4(point2, n).sub(float4(1).sub(decode(nearest).mul(2)))
1394
1519
  );
1395
1520
  const tolerance = max4(
1396
- dot3(abs3(right), half).div(rect.z.mul(descriptor.atlasResolution)),
1397
- dot3(abs3(up), half).div(rect.w.mul(descriptor.atlasResolution))
1398
- ).div(dot3(abs3(n), half)).mul(4).add(4 / 65535);
1521
+ dot4(abs3(right), half).div(rect.z.mul(descriptor.atlasResolution)),
1522
+ dot4(abs3(up), half).div(rect.w.mul(descriptor.atlasResolution))
1523
+ ).div(dot4(abs3(n), half)).mul(4).add(4 / 65535);
1399
1524
  If4(
1400
1525
  residual.lessThanEqual(tolerance).and(occupied).and(
1401
1526
  capturedBase.a.greaterThanEqual(minimumAlpha)
@@ -1410,8 +1535,8 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1410
1535
  };
1411
1536
  if (preferFacingCapture) {
1412
1537
  const texel2 = max4(
1413
- dot3(abs3(right), half).div(rect.z),
1414
- dot3(abs3(up), half).div(rect.w)
1538
+ dot4(abs3(right), half).div(rect.z),
1539
+ dot4(abs3(up), half).div(rect.w)
1415
1540
  ).div(descriptor.atlasResolution);
1416
1541
  const uncertainty = min2(
1417
1542
  texel2,
@@ -1428,7 +1553,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1428
1553
  );
1429
1554
  };
1430
1555
  const traceInterval = (start, end, steps) => {
1431
- const footprint = vec24(dot3(r, right), dot3(r, up)).abs().mul(rect.zw).mul(descriptor.atlasResolution / 2).mul(end.sub(start));
1556
+ const footprint = vec24(dot4(r, right), dot4(r, up)).abs().mul(rect.zw).mul(descriptor.atlasResolution / 2).mul(end.sub(start));
1432
1557
  let density = steps / 8;
1433
1558
  if (descriptor.alphaMode === "blend" && transparency === "blended" && steps < 32) {
1434
1559
  density = i.equal(0).select(steps / 16, steps / 32);
@@ -1437,10 +1562,10 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1437
1562
  }
1438
1563
  const samples = max4(float4(steps), max4(footprint.x, footprint.y).mul(density)).div(2).ceil().mul(2).toVar();
1439
1564
  const step = end.sub(start).div(samples).toVar();
1440
- const pairs = int4(samples.div(2));
1565
+ const pairs = int5(samples.div(2));
1441
1566
  const pairAt = (t) => t.sub(start).div(max4(step.mul(2), 1e-15));
1442
- const firstPair = bounds ? int4(floor2(pairAt(bounds.start))).clamp(0, pairs).toVar() : int4(0);
1443
- const lastPair = bounds ? int4(pairAt(bounds.end).ceil()).clamp(0, pairs).toVar() : pairs;
1567
+ const firstPair = bounds ? int5(floor2(pairAt(bounds.start))).clamp(0, pairs).toVar() : int5(0);
1568
+ const lastPair = bounds ? int5(pairAt(bounds.end).ceil()).clamp(0, pairs).toVar() : pairs;
1444
1569
  const previous = start.toVar();
1445
1570
  if (bounds) If4(firstPair.greaterThan(0), () => {
1446
1571
  previous.assign(start.add(step.mul(float4(firstPair.mul(2)))));
@@ -1498,8 +1623,8 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1498
1623
  )
1499
1624
  );
1500
1625
  const interval = positive.select(depths.xy, depths.zw);
1501
- const initialDepth = float4(1).sub(dot3(o, n)).mul(0.5);
1502
- const depthSlope = dot3(r, n).negate().mul(0.5);
1626
+ const initialDepth = float4(1).sub(dot4(o, n)).mul(0.5);
1627
+ const depthSlope = dot4(r, n).negate().mul(0.5);
1503
1628
  const da = interval.x.sub(2 / 65535).sub(initialDepth).div(depthSlope);
1504
1629
  const db = interval.y.add(2 / 65535).sub(initialDepth).div(depthSlope);
1505
1630
  const start = max4(occupiedStart, min2(da, db));
@@ -1553,7 +1678,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1553
1678
  const sampled = texture3(maps.normalDepth, hit.get("uv")).level(0);
1554
1679
  const local = unpackNormal(sampled.rg.div(coverage));
1555
1680
  const direction = fromBox(right.mul(local.x).add(up.mul(local.y)).add(n.mul(local.z))).normalize().toVar();
1556
- return direction.mul(dot3(direction, ray).greaterThan(0).select(-1, 1));
1681
+ return direction.mul(dot4(direction, ray).greaterThan(0).select(-1, 1));
1557
1682
  })();
1558
1683
  let color = base.div(coverage), surfaceOrm = orm.rgb.div(coverage), emission = texture3(maps.emissive, hit.get("uv")).level(0).rgb.div(coverage), normal = hitNormal;
1559
1684
  if (settings.interpolation !== "none") {
@@ -1567,37 +1692,37 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1567
1692
  const look = toBox(
1568
1693
  perspective.select(normalize2(eye.sub(hit.get("position"))), viewAxis)
1569
1694
  );
1570
- const colors = vec45(0).toVar(), materials = vec34(0).toVar(), emissions = vec34(0).toVar(), normals = vec34(0).toVar(), weights = float4(0).toVar();
1695
+ const colors = vec46(0).toVar(), materials = vec35(0).toVar(), emissions = vec35(0).toVar(), normals = vec35(0).toVar(), weights = float4(0).toVar();
1571
1696
  for (let axis = 0; axis < 3; axis++) {
1572
1697
  const positive = look.element(axis).greaterThanEqual(0);
1573
1698
  const front = BOX_FACE_AXES[axis * 2], back = BOX_FACE_AXES[axis * 2 + 1];
1574
- const n = positive.select(vec34(...front.normal), vec34(...back.normal));
1699
+ const n = positive.select(vec35(...front.normal), vec35(...back.normal));
1575
1700
  const right = positive.select(
1576
- vec34(...front.right),
1577
- vec34(...back.right)
1701
+ vec35(...front.right),
1702
+ vec35(...back.right)
1578
1703
  );
1579
- const up = positive.select(vec34(...front.up), vec34(...back.up));
1580
- const face = positive.select(int4(axis * 2), int4(axis * 2 + 1));
1581
- const rect = textureLoad4(
1704
+ const up = positive.select(vec35(...front.up), vec35(...back.up));
1705
+ const face = positive.select(int5(axis * 2), int5(axis * 2 + 1));
1706
+ const rect = textureLoad5(
1582
1707
  rects,
1583
- ivec24(face, int4(attribute3("boxId", "float")))
1708
+ ivec25(face, int5(attribute3("boxId", "float")))
1584
1709
  );
1585
1710
  const uv2 = rect.xy.add(
1586
- vec24(dot3(point, right), dot3(point, up)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
1711
+ vec24(dot4(point, right), dot4(point, up)).mul(0.5).add(0.5).clamp(0, 1).mul(rect.zw)
1587
1712
  );
1588
- const texel = ivec24(uv2.mul(descriptor.atlasResolution));
1589
- const captured = textureLoad4(maps.normalDepth, texel);
1713
+ const texel = ivec25(uv2.mul(descriptor.atlasResolution));
1714
+ const captured = textureLoad5(maps.normalDepth, texel);
1590
1715
  const sampled = texture3(maps.baseColor, uv2).level(0);
1591
1716
  const sampledOrm = texture3(maps.orm, uv2).level(0);
1592
- const occupied = textureLoad4(maps.orm, texel).a.greaterThan(0.5);
1717
+ const occupied = textureLoad5(maps.orm, texel).a.greaterThan(0.5);
1593
1718
  const depth = captured.b.mul(65280).add(captured.a.mul(255)).div(65535);
1594
1719
  const tolerance = max4(
1595
- dot3(abs3(right), half).div(rect.z.mul(descriptor.atlasResolution)),
1596
- dot3(abs3(up), half).div(rect.w.mul(descriptor.atlasResolution))
1597
- ).div(dot3(abs3(n), half)).mul(4).add(4 / 65535);
1720
+ dot4(abs3(right), half).div(rect.z.mul(descriptor.atlasResolution)),
1721
+ dot4(abs3(up), half).div(rect.w.mul(descriptor.atlasResolution))
1722
+ ).div(dot4(abs3(n), half)).mul(4).add(4 / 65535);
1598
1723
  If4(
1599
1724
  occupied.and(sampled.a.greaterThanEqual(minimumAlpha)).and(
1600
- abs3(dot3(point, n).sub(float4(1).sub(depth.mul(2)))).lessThanEqual(
1725
+ abs3(dot4(point, n).sub(float4(1).sub(depth.mul(2)))).lessThanEqual(
1601
1726
  tolerance
1602
1727
  )
1603
1728
  ),
@@ -1606,7 +1731,7 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1606
1731
  const filtered = filtering ? texture3(maps.normalDepth, uv2).level(0).toVar() : captured;
1607
1732
  let weight = settings.interpolation === "smooth" ? angle.mul(angle) : angle;
1608
1733
  if (filtering) {
1609
- const error = abs3(dot3(point, n).sub(float4(1).sub(
1734
+ const error = abs3(dot4(point, n).sub(float4(1).sub(
1610
1735
  filtered.b.mul(65280).add(filtered.a.mul(255)).div(65535).mul(2)
1611
1736
  )));
1612
1737
  weight = weight.mul(float4(1).sub(error.div(tolerance)).clamp(0, 1));
@@ -1618,10 +1743,10 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1618
1743
  texture3(maps.emissive, uv2).level(0).rgb.div(coverage2).mul(weight)
1619
1744
  );
1620
1745
  let shadingNormal;
1621
- if (filtering) shadingNormal = filteredNormal(uv2, float4(1).sub(dot3(point, n)).mul(0.5), tolerance.mul(0.5), captured, sampled.a, filtered, sampledOrm.a);
1746
+ if (filtering) shadingNormal = filteredNormal(uv2, float4(1).sub(dot4(point, n)).mul(0.5), tolerance.mul(0.5), captured, sampled.a, filtered, sampledOrm.a);
1622
1747
  else {
1623
1748
  const packed = captured.rg.mul(2).sub(1);
1624
- const decoded = vec34(
1749
+ const decoded = vec35(
1625
1750
  packed,
1626
1751
  float4(1).sub(abs3(packed.x)).sub(abs3(packed.y))
1627
1752
  ).toVar();
@@ -1654,9 +1779,10 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1654
1779
  emission = blended.get("emission");
1655
1780
  normal = blended.get("normal");
1656
1781
  }
1657
- material.capturedPositionNode = hit.get("position");
1782
+ const position = meshPoint(hit.get("position")).toVar("boxHitMeshPosition");
1783
+ material.capturedPositionNode = position;
1658
1784
  material.colorNode = color.rgb;
1659
- material.normalNode = transformNormalToView3(normal);
1785
+ material.normalNode = transformNormalToView3(meshNormal(normal));
1660
1786
  material.roughnessNode = surfaceOrm.g;
1661
1787
  material.metalnessNode = surfaceOrm.b;
1662
1788
  material.aoNode = surfaceOrm.r;
@@ -1671,9 +1797,9 @@ function createBoxImpostorMaterialVariant(descriptor, maps, { filtering = false,
1671
1797
  }
1672
1798
  material.maskNode = hit.get("valid").greaterThan(0.5);
1673
1799
  material.maskShadowNode = material.maskNode;
1674
- material.depthNode = capturedSurfaceDepth(hit.get("position"));
1800
+ material.depthNode = capturedSurfaceDepth(position);
1675
1801
  material.receivedShadowPositionNode = modelWorldMatrix3.mul(
1676
- vec45(hit.get("position"), 1)
1802
+ vec46(position, 1)
1677
1803
  ).xyz;
1678
1804
  material.userData.boxImpostor = { descriptor, maps, alphaCutoff };
1679
1805
  return material;