@needle-tools/three-mesh-effects 0.3.5 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -28
- package/README.md +63 -231
- package/SKILL.md +11 -68
- package/build/box-impostor-runtime.js +652 -257
- package/build/box-impostor-runtime.js.map +4 -4
- package/build/deformation-runtime.js +1 -1
- package/build/deformation-runtime.js.map +1 -1
- package/build/hull-effects.js.map +1 -1
- package/build/impostor-runtime.js +2 -2
- package/build/impostor-runtime.js.map +2 -2
- package/build/index.js +2 -2
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display.js +662 -265
- package/build/internal/box-impostor/box-impostor-display.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-material.js +662 -265
- package/build/internal/box-impostor/box-impostor-material.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-ray-bounds.js +369 -0
- package/build/internal/box-impostor/box-impostor-ray-bounds.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-runtime.js +652 -257
- package/build/internal/box-impostor/box-impostor-runtime.js.map +4 -4
- package/build/internal/deformation/rig-runtime.js +1 -1
- package/build/internal/deformation/rig-runtime.js.map +1 -1
- package/build/internal/impostor/impostor-node-material.js +2 -2
- package/build/internal/impostor/impostor-node-material.js.map +2 -2
- package/build/internal/impostor/octahedral.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-display.js +39 -16
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +2 -2
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js +61 -6
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +2 -2
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js +980 -26
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +4 -4
- package/build/internal/rendering/hull-effect-runtime.js.map +1 -1
- package/build/internal/rendering/renderer-support.js.map +1 -1
- package/build/internal/rendering/skin-projection.js.map +1 -1
- package/build/internal/rendering/surface-query.js.map +1 -1
- package/build/internal/rendering/wrap-preview.js.map +1 -1
- package/build/internal/rendering/wrap-skin.js.map +1 -1
- package/build/pixel-impostor-runtime.js +362 -172
- package/build/pixel-impostor-runtime.js.map +4 -4
- package/build/types/box-impostor/box-impostor-material.d.ts +2 -1
- package/build/types/box-impostor/box-impostor-ray-bounds.d.ts +6 -0
- package/build/types/box-impostor/box-impostor-ray-bounds.js +1 -0
- package/build/types/deformation/rig-runtime.d.ts +1 -1
- package/build/types/impostor/octahedral.d.ts +1 -1
- package/build/types/pixel-impostor/pixel-impostor-display.d.ts +3 -3
- package/build/types/pixel-impostor/pixel-impostor-metadata.d.ts +76 -5
- package/build/types/pixel-impostor/pixel-impostor-runtime.d.ts +19 -7
- package/build/types/public/pixel-impostor-runtime.d.ts +1 -1
- package/build/types/rendering/renderer-support.d.ts +1 -1
- package/build/types/rendering/surface-query.d.ts +2 -2
- package/package.json +2 -2
- package/src/box-impostor/box-impostor-material.js +128 -90
- package/src/box-impostor/box-impostor-ray-bounds.js +452 -0
- package/src/deformation/rig-runtime.ts +1 -1
- package/src/impostor/impostor-node-material.js +2 -2
- package/src/impostor/octahedral.js +1 -1
- package/src/pixel-impostor/pixel-impostor-display.js +32 -18
- package/src/pixel-impostor/pixel-impostor-metadata.js +69 -9
- package/src/pixel-impostor/pixel-impostor-runtime.js +32 -9
- package/src/public/index.js +2 -2
- package/src/public/pixel-impostor-runtime.js +1 -1
- package/src/rendering/renderer-support.js +1 -1
- package/src/rendering/surface-query.js +2 -2
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
/** Register pixel atlas loading before calling `loadAsync`; returns the same loader.
|
|
1
|
+
/** Register pixel atlas loading before calling `loadAsync`; returns the same loader. With a
|
|
2
|
+
* renderer, files show their stored display.
|
|
2
3
|
* @template {import('three/addons/loaders/GLTFLoader.js').GLTFLoader} T
|
|
3
|
-
* @param {T} loader @returns {T}
|
|
4
|
+
* @param {T} loader @param {{renderer?: import('../rendering/renderer-support.js').ImpostorRenderer}} [options] @returns {T}
|
|
4
5
|
*/
|
|
5
|
-
export function registerNeedlePixelImpostorLoader<T extends import("three/addons/loaders/GLTFLoader.js").GLTFLoader>(loader: T
|
|
6
|
+
export function registerNeedlePixelImpostorLoader<T extends import("three/addons/loaders/GLTFLoader.js").GLTFLoader>(loader: T, options?: {
|
|
7
|
+
renderer?: import("../rendering/renderer-support.js").ImpostorRenderer;
|
|
8
|
+
}): T;
|
|
6
9
|
/**
|
|
7
10
|
* Three.js GLTFLoader plugin for versioned pixel impostor atlas bindings.
|
|
8
|
-
*
|
|
9
|
-
*
|
|
11
|
+
* Given a renderer, it shows a file's stored display (`display` in the extension) with
|
|
12
|
+
* `createPixelImpostorDisplay`, and keeps the display's handle in the scene's
|
|
13
|
+
* `userData.pixelImpostorDisplay`. Without a renderer, or for files without a stored
|
|
14
|
+
* display, it leaves the file's mesh as it is; call `createPixelImpostorDisplay` to choose a mode.
|
|
10
15
|
*/
|
|
11
16
|
export class NeedlePixelImpostorLoaderPlugin {
|
|
12
|
-
/** @param {unknown} parser */
|
|
13
|
-
constructor(parser: unknown
|
|
17
|
+
/** @param {unknown} parser @param {{renderer?: import('../rendering/renderer-support.js').ImpostorRenderer}} [options] */
|
|
18
|
+
constructor(parser: unknown, options?: {
|
|
19
|
+
renderer?: import("../rendering/renderer-support.js").ImpostorRenderer;
|
|
20
|
+
});
|
|
14
21
|
name: string;
|
|
15
22
|
parser: unknown;
|
|
23
|
+
options: {
|
|
24
|
+
renderer?: import("../rendering/renderer-support.js").ImpostorRenderer;
|
|
25
|
+
};
|
|
16
26
|
/** @param {import('three/addons/loaders/GLTFLoader.js').GLTF} result */
|
|
17
27
|
afterRoot(result: import("three/addons/loaders/GLTFLoader.js").GLTF): Promise<void>;
|
|
28
|
+
/** @param {import('three/addons/loaders/GLTFLoader.js').GLTF} result */
|
|
29
|
+
applyStoredDisplay(result: import("three/addons/loaders/GLTFLoader.js").GLTF): Promise<void>;
|
|
18
30
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { NeedlePixelImpostorLoaderPlugin, registerNeedlePixelImpostorLoader } from "../pixel-impostor/pixel-impostor-runtime.js";
|
|
2
|
-
export { NEEDLE_PIXEL_IMPOSTOR, parsePixelImpostorDescriptor } from "../pixel-impostor/pixel-impostor-metadata.js";
|
|
2
|
+
export { NEEDLE_PIXEL_IMPOSTOR, parsePixelImpostorDescriptor, normalizePixelImpostorDisplay, DEFAULT_PIXEL_IMPOSTOR_DISPLAY, PIXEL_IMPOSTOR_VOLUME_MODES } from "../pixel-impostor/pixel-impostor-metadata.js";
|
|
3
3
|
export { createPixelImpostorDisplay, createPixelImpostorRaycastPreview } from "../pixel-impostor/pixel-impostor-display.js";
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @property {((handler: import('three/addons/tsl/WebGLNodesHandler.js').WebGLNodesHandler) => void)=} setNodesHandler
|
|
7
7
|
*/
|
|
8
8
|
/**
|
|
9
|
-
* Reports whether a renderer can compile
|
|
9
|
+
* Reports whether a renderer can compile TSL impostor materials.
|
|
10
10
|
* WebGPURenderer supports node materials directly. Classic WebGLRenderer
|
|
11
11
|
* integrations must advertise that they installed a compatible nodes handler.
|
|
12
12
|
*
|
|
@@ -28,8 +28,8 @@ export function createSurfaceQuery(mesh: QueryMesh, options?: {
|
|
|
28
28
|
dispose(): void;
|
|
29
29
|
};
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
32
|
-
* aligned with the source triangle arrays.
|
|
31
|
+
* Reuse allocations when querying a prebuilt BVH. Indirect indexing keeps BVH
|
|
32
|
+
* face IDs aligned with the source triangle arrays.
|
|
33
33
|
*
|
|
34
34
|
* @param {BufferGeometry} geometry
|
|
35
35
|
* @param {MeshBVH} bvh
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/three-mesh-effects",
|
|
3
|
-
"version": "0.3.
|
|
4
|
-
"description": "Three.js loaders and TSL
|
|
3
|
+
"version": "0.3.7",
|
|
4
|
+
"description": "Three.js loaders and TSL materials for glTF impostors, hull effects, and deformation rigs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"three.js",
|
|
7
7
|
"gltf",
|
|
@@ -50,6 +50,7 @@ import {
|
|
|
50
50
|
uniform,
|
|
51
51
|
} from "three/tsl";
|
|
52
52
|
import {CapturedSurfaceMaterial} from '../rendering/captured-surface-material.js';
|
|
53
|
+
import {createBoxRayBounds} from './box-impostor-ray-bounds.js';
|
|
53
54
|
import {refineSurfaceCrossing} from './box-impostor-surface-search.js';
|
|
54
55
|
import { applyBoxFaces } from "./box-impostor-faces.js";
|
|
55
56
|
import { applyBoxProjection } from "./box-impostor-projection.js";
|
|
@@ -72,7 +73,7 @@ export function createBoxImpostorMaterial(descriptor, maps) {
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
/** Internal compile-time variants for matched quality and cost measurements. */
|
|
75
|
-
export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering = false} = {}) {
|
|
76
|
+
export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering = false, boundSearch = true} = {}) {
|
|
76
77
|
const settings = normalizeBoxImpostorDisplay(descriptor);
|
|
77
78
|
const alphaCutoff = uniform(settings.alphaCutoff);
|
|
78
79
|
const transparency = boxTransparency(descriptor, settings);
|
|
@@ -80,12 +81,13 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
80
81
|
// Opaque/masked captures store geometric coverage in base alpha as well.
|
|
81
82
|
// This also supports older MRT captures whose unused ORM alpha was opaque.
|
|
82
83
|
const surfaceCoverage = (ormAlpha,baseAlpha) => filtering && descriptor.alphaMode !== 'blend' ? min(ormAlpha,baseAlpha) : ormAlpha;
|
|
83
|
-
const
|
|
84
|
+
const unpackNormal = encoded => {
|
|
84
85
|
const packed=encoded.mul(2).sub(1);
|
|
85
86
|
const normal=vec3(packed,float(1).sub(abs(packed.x)).sub(abs(packed.y))).toVar();
|
|
86
87
|
If(normal.z.lessThan(0),()=>{normal.xy.assign(vec2(1).sub(abs(normal.yx)).mul(sign(normal.xy.add(1e-20))));});
|
|
87
|
-
return normal
|
|
88
|
+
return normal;
|
|
88
89
|
};
|
|
90
|
+
const decodeNormal = encoded => unpackNormal(encoded).normalize();
|
|
89
91
|
const filteredNormal = (uv,depth,tolerance,nearest,alpha,sampled=texture(maps.normalDepth,uv).level(0),ormAlpha=texture(maps.orm,uv).level(0).a) => {
|
|
90
92
|
sampled=sampled.toVar();
|
|
91
93
|
const coverage=max(descriptor.alphaMode==='blend'?ormAlpha:alpha,1e-10);
|
|
@@ -264,15 +266,33 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
264
266
|
occupancy.needsUpdate = true;
|
|
265
267
|
material.addEventListener("dispose", () => occupancy.dispose());
|
|
266
268
|
}
|
|
269
|
+
const preferFacingCapture = filtering && descriptor.alphaMode === "opaque" && settings.interpolation === "none";
|
|
270
|
+
const viewBounds = boundSearch ? createBoxRayBounds(descriptor, maps, rects, material) : null;
|
|
267
271
|
const Result = struct(
|
|
268
|
-
{ uv: "vec2", position: "vec3",
|
|
272
|
+
{ uv: "vec2", position: "vec3", face: "int", valid: "float" },
|
|
269
273
|
"BoxImpostorHit",
|
|
270
274
|
);
|
|
275
|
+
const faceBasis = (axis, facing) => {
|
|
276
|
+
const n = vec3(
|
|
277
|
+
axis.equal(0).select(facing, 0),
|
|
278
|
+
axis.equal(1).select(facing, 0),
|
|
279
|
+
axis.equal(2).select(facing, 0),
|
|
280
|
+
).toVar();
|
|
281
|
+
const right = axis
|
|
282
|
+
.equal(0)
|
|
283
|
+
.select(
|
|
284
|
+
vec3(0, 0, facing.negate()),
|
|
285
|
+
axis.equal(1).select(vec3(1, 0, 0), vec3(facing, 0, 0)),
|
|
286
|
+
)
|
|
287
|
+
.toVar();
|
|
288
|
+
const up = axis
|
|
289
|
+
.equal(1)
|
|
290
|
+
.select(vec3(0, 0, facing.negate()), vec3(0, 1, 0))
|
|
291
|
+
.toVar();
|
|
292
|
+
return { n, right, up };
|
|
293
|
+
};
|
|
294
|
+
const ray = perspective.select(normalize(raster.sub(eye)), viewAxis.negate());
|
|
271
295
|
const raycast = Fn((_, builder) => {
|
|
272
|
-
const ray = perspective.select(
|
|
273
|
-
normalize(raster.sub(eye)),
|
|
274
|
-
viewAxis.negate(),
|
|
275
|
-
);
|
|
276
296
|
const origin = perspective.select(
|
|
277
297
|
eye,
|
|
278
298
|
raster.sub(ray.mul(half.length().mul(4))),
|
|
@@ -284,6 +304,7 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
284
304
|
b = vec3(1).sub(o).div(safe);
|
|
285
305
|
const enter = max(max(min(a, b).x, min(a, b).y), min(a, b).z).max(0);
|
|
286
306
|
const exit = min(min(max(a, b).x, max(a, b).y), max(a, b).z);
|
|
307
|
+
const rayBounds = viewBounds?.(builder, int(attribute("boxId", "float")), o, r, enter, exit);
|
|
287
308
|
const occupiedStart = enter.toVar();
|
|
288
309
|
// This cover contains whole source voxel cubes. Only the empty space is
|
|
289
310
|
// skipped; the depth fields still determine the full-resolution surface.
|
|
@@ -345,7 +366,8 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
345
366
|
const look = toBox(ray).negate();
|
|
346
367
|
const bestT = exit.add(1).toVar(),
|
|
347
368
|
bestUv = vec2(0).toVar(),
|
|
348
|
-
|
|
369
|
+
bestFace = int(0).toVar(),
|
|
370
|
+
appearanceNear = preferFacingCapture ? float(0).toVar() : null,
|
|
349
371
|
valid = float(0).toVar(),
|
|
350
372
|
found = float(0).toVar();
|
|
351
373
|
// A face-on capture can miss a nearer surface visible from another axis.
|
|
@@ -386,23 +408,9 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
386
408
|
look.element(axis).lessThan(0),
|
|
387
409
|
);
|
|
388
410
|
const face = axis.mul(2).add(positive.select(int(0), int(1)));
|
|
411
|
+
const bounds = rayBounds?.(face, enter, exit);
|
|
389
412
|
const facing = positive.select(1, -1);
|
|
390
|
-
const n =
|
|
391
|
-
axis.equal(0).select(facing, 0),
|
|
392
|
-
axis.equal(1).select(facing, 0),
|
|
393
|
-
axis.equal(2).select(facing, 0),
|
|
394
|
-
).toVar();
|
|
395
|
-
const right = axis
|
|
396
|
-
.equal(0)
|
|
397
|
-
.select(
|
|
398
|
-
vec3(0, 0, facing.negate()),
|
|
399
|
-
axis.equal(1).select(vec3(1, 0, 0), vec3(facing, 0, 0)),
|
|
400
|
-
)
|
|
401
|
-
.toVar();
|
|
402
|
-
const up = axis
|
|
403
|
-
.equal(1)
|
|
404
|
-
.select(vec3(0, 0, facing.negate()), vec3(0, 1, 0))
|
|
405
|
-
.toVar();
|
|
413
|
+
const { n, right, up } = faceBasis(axis, facing);
|
|
406
414
|
const direction = i.lessThan(3).select(1, -1);
|
|
407
415
|
const rect = textureLoad(
|
|
408
416
|
rects,
|
|
@@ -418,10 +426,19 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
418
426
|
);
|
|
419
427
|
const decode = (d) => d.b.mul(65280).add(d.a.mul(255)).div(65535);
|
|
420
428
|
const depthAt = (uv) => decode(texture(maps.normalDepth, uv).level(0));
|
|
429
|
+
// A capture sees an affine ray. Project it once per face so stepping
|
|
430
|
+
// and refinement only need its position along that ray.
|
|
431
|
+
const projectedOrigin = vec2(dot(o, right), dot(o, up)).toVar();
|
|
432
|
+
const projectedRay = vec2(dot(r, right), dot(r, up)).toVar();
|
|
433
|
+
const axialOrigin = dot(o, n).toVar();
|
|
434
|
+
const axialRay = dot(r, n).toVar();
|
|
421
435
|
const distance = (t) => {
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
436
|
+
const uv = rect.xy.add(
|
|
437
|
+
projectedOrigin.add(projectedRay.mul(t)).mul(0.5).add(0.5)
|
|
438
|
+
.clamp(0, 1).mul(rect.zw),
|
|
439
|
+
);
|
|
440
|
+
return axialOrigin.add(axialRay.mul(t))
|
|
441
|
+
.sub(float(1).sub(depthAt(uv).mul(2)))
|
|
425
442
|
.mul(direction);
|
|
426
443
|
};
|
|
427
444
|
const acceptHit = (hitT) => {
|
|
@@ -456,36 +473,27 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
456
473
|
valid.assign(1);
|
|
457
474
|
If(hitT.lessThan(bestT), () => {
|
|
458
475
|
bestT.assign(hitT);
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
.
|
|
465
|
-
.
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
vec2(1)
|
|
474
|
-
.sub(abs(normal.yx))
|
|
475
|
-
.mul(sign(normal.xy.add(1e-20))),
|
|
476
|
+
const useAppearance = () => {
|
|
477
|
+
bestUv.assign(uv);
|
|
478
|
+
bestFace.assign(face);
|
|
479
|
+
};
|
|
480
|
+
if (preferFacingCapture) {
|
|
481
|
+
// The more face-on capture was visited first. Keep it only
|
|
482
|
+
// while the two depth estimates overlap within one texel.
|
|
483
|
+
const texel = max(
|
|
484
|
+
dot(abs(right), half).div(rect.z),
|
|
485
|
+
dot(abs(up), half).div(rect.w),
|
|
486
|
+
).div(descriptor.atlasResolution);
|
|
487
|
+
const uncertainty = min(
|
|
488
|
+
texel,
|
|
489
|
+
residual.add(2 / 65535).div(abs(axialRay).max(1e-10)),
|
|
476
490
|
);
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
.add(n.mul(normal.z)),
|
|
484
|
-
).normalize(),
|
|
485
|
-
);
|
|
486
|
-
bestNormal.mulAssign(
|
|
487
|
-
dot(bestNormal, ray).greaterThan(0).select(-1, 1),
|
|
488
|
-
);
|
|
491
|
+
If(found.lessThan(0.5).or(hitT.add(uncertainty).lessThan(appearanceNear)), () => {
|
|
492
|
+
appearanceNear.assign(hitT.sub(uncertainty));
|
|
493
|
+
useAppearance();
|
|
494
|
+
});
|
|
495
|
+
} else useAppearance();
|
|
496
|
+
found.assign(1);
|
|
489
497
|
});
|
|
490
498
|
},
|
|
491
499
|
);
|
|
@@ -495,48 +503,68 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
495
503
|
end,
|
|
496
504
|
steps,
|
|
497
505
|
) => {
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
506
|
+
const footprint = vec2(dot(r, right), dot(r, up)).abs()
|
|
507
|
+
.mul(rect.zw).mul(descriptor.atlasResolution / 2).mul(end.sub(start));
|
|
508
|
+
let density = steps / 8;
|
|
509
|
+
if (descriptor.alphaMode === "blend" && transparency === "blended" && steps < 32) {
|
|
510
|
+
// Overlapping blended carriers each trace their dominant capture more densely.
|
|
511
|
+
density = i.equal(0).select(steps / 16, steps / 32);
|
|
512
|
+
} else if (descriptor.alphaMode === "opaque" && steps === 16) {
|
|
513
|
+
// Use the full density until the silhouette is established. Later
|
|
514
|
+
// captures look for closer occluders at one sample per crossed texel.
|
|
515
|
+
density = found.greaterThan(0.5).select(1, 2);
|
|
516
|
+
}
|
|
517
|
+
const samples = max(float(steps), max(footprint.x, footprint.y).mul(density))
|
|
518
|
+
.div(2).ceil().mul(2).toVar();
|
|
519
|
+
const step = end.sub(start).div(samples).toVar();
|
|
520
|
+
const pairs = int(samples.div(2));
|
|
521
|
+
// Keep the original bracket indices. Restarting at a clipped bound
|
|
522
|
+
// moves the samples and can lose thin surfaces between them.
|
|
523
|
+
const pairAt = t => t.sub(start).div(max(step.mul(2), 1e-15));
|
|
524
|
+
const firstPair = bounds ? int(floor(pairAt(bounds.start))).clamp(0, pairs).toVar() : int(0);
|
|
525
|
+
const lastPair = bounds ? int(pairAt(bounds.end).ceil()).clamp(0, pairs).toVar() : pairs;
|
|
526
|
+
const previous = start.toVar();
|
|
527
|
+
if (bounds) If(firstPair.greaterThan(0), () => {
|
|
528
|
+
previous.assign(start.add(step.mul(float(firstPair.mul(2)))));
|
|
529
|
+
});
|
|
530
|
+
const previousD = distance(previous).toVar();
|
|
531
|
+
const atEntry = bounds ? firstPair.equal(0).and(start.greaterThanEqual(bounds.start)).and(start.lessThanEqual(bounds.end)) : null;
|
|
532
|
+
If(atEntry ? atEntry.and(previousD.lessThanEqual(0)) : previousD.lessThanEqual(0), () => {
|
|
508
533
|
acceptHit(start);
|
|
509
534
|
});
|
|
510
|
-
Loop({ start:
|
|
511
|
-
If(valid.greaterThan(0.5), () => {
|
|
535
|
+
Loop({ start: firstPair, end: lastPair, type: "int" }, ({ i }) => {
|
|
536
|
+
If(valid.greaterThan(0.5).or(previous.greaterThan(bestT)), () => {
|
|
512
537
|
Break();
|
|
513
538
|
});
|
|
514
|
-
|
|
515
|
-
// their original order before refining either crossing direction.
|
|
516
|
-
const samples = [1, 2].map((offset) => {
|
|
539
|
+
const [first, second] = [1, 2].map((offset) => {
|
|
517
540
|
const t = start.add(step.mul(float(i.mul(2).add(offset)))).toVar();
|
|
518
541
|
return { t, d: distance(t).toVar() };
|
|
519
542
|
});
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
543
|
+
const crossesFirst = first.d.mul(previousD).lessThanEqual(0);
|
|
544
|
+
const crossesSecond = second.d.mul(first.d).lessThanEqual(0);
|
|
545
|
+
// Most pairs have no crossing. Skip the per-bracket work together,
|
|
546
|
+
// while retaining both brackets for thin surfaces and reversals.
|
|
547
|
+
If(crossesFirst.or(crossesSecond), () => {
|
|
548
|
+
for (const [{ t, d }, crosses] of [[first, crossesFirst], [second, crossesSecond]]) {
|
|
549
|
+
If(crosses.and(valid.lessThan(0.5)).and(previous.lessThanEqual(bestT)), () => {
|
|
550
|
+
const crossing = refineSurfaceCrossing({ float, If, Loop }, {
|
|
551
|
+
lo: previous, hi: t, loValue: previousD, hiValue: d,
|
|
552
|
+
height: distance, steps: 3, secant: true,
|
|
553
|
+
});
|
|
554
|
+
acceptHit(crossing);
|
|
529
555
|
});
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
}
|
|
556
|
+
previous.assign(t);
|
|
557
|
+
previousD.assign(d);
|
|
558
|
+
}
|
|
559
|
+
}).Else(() => {
|
|
560
|
+
previous.assign(second.t);
|
|
561
|
+
previousD.assign(second.d);
|
|
562
|
+
});
|
|
534
563
|
});
|
|
535
564
|
};
|
|
565
|
+
const supported = exit.greaterThanEqual(enter).and(abs(look.element(axis)).greaterThan(0.001));
|
|
536
566
|
If(
|
|
537
|
-
|
|
538
|
-
.greaterThanEqual(enter)
|
|
539
|
-
.and(abs(look.element(axis)).greaterThan(0.001)),
|
|
567
|
+
bounds ? supported.and(bounds.start.lessThanEqual(bestT)).and(bounds.end.greaterThanEqual(occupiedStart)) : supported,
|
|
540
568
|
() => {
|
|
541
569
|
if (!accelerated) {
|
|
542
570
|
traceInterval(enter, exit, descriptor.raySteps);
|
|
@@ -611,7 +639,7 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
611
639
|
return Result(
|
|
612
640
|
bestUv,
|
|
613
641
|
center.add(fromBox(point.mul(half))),
|
|
614
|
-
|
|
642
|
+
bestFace,
|
|
615
643
|
valid,
|
|
616
644
|
);
|
|
617
645
|
});
|
|
@@ -623,10 +651,20 @@ export function createBoxImpostorMaterialVariant(descriptor, maps, {filtering =
|
|
|
623
651
|
// attributes by geometric coverage; an
|
|
624
652
|
// empty neighbor must not turn a rough edge into a glossy highlight.
|
|
625
653
|
const coverage = max(surfaceCoverage(orm.a,base.a), 1e-10);
|
|
654
|
+
// Decode only the winning capture. Visibility and depth passes need just
|
|
655
|
+
// the hit, and shaded passes already fetch its base color and coverage.
|
|
656
|
+
const hitNormal = Fn(() => {
|
|
657
|
+
const face = hit.get("face");
|
|
658
|
+
const { n, right, up } = faceBasis(face.div(2), face.mod(2).equal(0).select(1, -1));
|
|
659
|
+
const sampled = texture(maps.normalDepth, hit.get("uv")).level(0);
|
|
660
|
+
const local = unpackNormal(sampled.rg.div(coverage));
|
|
661
|
+
const direction = fromBox(right.mul(local.x).add(up.mul(local.y)).add(n.mul(local.z))).normalize().toVar();
|
|
662
|
+
return direction.mul(dot(direction, ray).greaterThan(0).select(-1, 1));
|
|
663
|
+
})();
|
|
626
664
|
let color = base.div(coverage),
|
|
627
665
|
surfaceOrm = orm.rgb.div(coverage),
|
|
628
666
|
emission = texture(maps.emissive, hit.get("uv")).level(0).rgb.div(coverage),
|
|
629
|
-
normal =
|
|
667
|
+
normal = hitNormal;
|
|
630
668
|
if (settings.interpolation !== "none") {
|
|
631
669
|
const fallbackColor = color,
|
|
632
670
|
fallbackOrm = surfaceOrm,
|