@needle-tools/three-mesh-effects 0.3.1 → 0.3.3
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 +13 -0
- package/README.md +22 -6
- package/SKILL.md +7 -5
- package/build/box-impostor-runtime.js +212 -87
- package/build/box-impostor-runtime.js.map +4 -4
- package/build/impostor-runtime.js +128 -48
- package/build/impostor-runtime.js.map +4 -4
- package/build/index.js +4 -0
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display.js +178 -81
- package/build/internal/box-impostor/box-impostor-display.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-material.js +163 -71
- package/build/internal/box-impostor/box-impostor-material.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-projection.js +38 -18
- package/build/internal/box-impostor/box-impostor-projection.js.map +4 -4
- package/build/internal/box-impostor/box-impostor-runtime.js +193 -76
- package/build/internal/box-impostor/box-impostor-runtime.js.map +4 -4
- package/build/internal/impostor/impostor-node-material.js +128 -48
- package/build/internal/impostor/impostor-node-material.js.map +4 -4
- package/build/internal/pixel-impostor/pixel-impostor-display.js +84 -38
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +4 -4
- package/build/internal/rendering/captured-surface-depth.js +35 -0
- package/build/internal/rendering/captured-surface-depth.js.map +7 -0
- package/build/internal/rendering/captured-surface-material.js +28 -0
- package/build/internal/rendering/captured-surface-material.js.map +7 -0
- package/build/internal/rendering/renderer-support.js +31 -0
- package/build/internal/rendering/renderer-support.js.map +7 -0
- package/build/pixel-impostor-runtime.js +84 -38
- package/build/pixel-impostor-runtime.js.map +4 -4
- package/build/types/box-impostor/box-impostor-display.d.ts +9 -1
- package/build/types/box-impostor/box-impostor-material.d.ts +4 -0
- package/build/types/box-impostor/box-impostor-runtime.d.ts +5 -11
- package/build/types/impostor/impostor-node-material.d.ts +2 -15
- package/build/types/rendering/captured-surface-depth.d.ts +5 -0
- package/build/types/rendering/captured-surface-depth.js +1 -0
- package/build/types/rendering/captured-surface-material.d.ts +8 -0
- package/build/types/rendering/captured-surface-material.js +1 -0
- package/build/types/rendering/renderer-support.d.ts +27 -0
- package/build/types/rendering/renderer-support.js +1 -0
- package/package.json +3 -3
- package/src/box-impostor/box-impostor-display.js +23 -11
- package/src/box-impostor/box-impostor-material.js +94 -44
- package/src/box-impostor/box-impostor-projection.js +3 -14
- package/src/box-impostor/box-impostor-runtime.js +6 -4
- package/src/impostor/impostor-node-material.js +26 -43
- package/src/pixel-impostor/pixel-impostor-display.js +5 -13
- package/src/public/index.js +5 -0
- package/src/rendering/captured-surface-depth.js +55 -0
- package/src/rendering/captured-surface-material.js +27 -0
- package/src/rendering/renderer-support.js +50 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/rendering/captured-surface-depth.js"],
|
|
4
|
+
"sourcesContent": ["// @ts-check\nimport {\n Fn,\n cameraFar,\n cameraNear,\n cameraProjectionMatrix,\n modelViewMatrix,\n vec4,\n viewZToLogarithmicDepth,\n viewZToOrthographicDepth,\n viewZToPerspectiveDepth,\n viewZToReversedOrthographicDepth,\n viewZToReversedPerspectiveDepth,\n} from 'three/tsl';\n\n/** Match the renderer's depth convention after reconstructing a local hit.\n * @param {import('three/webgpu').Node<'vec3'>} position\n * @param {number} [shadowBias]\n */\nexport function capturedSurfaceDepth(position, shadowBias = 0) {\n return Fn(\n (\n /** @type {unknown} */ _,\n /** @type {import('three/webgpu').NodeBuilder} */ builder,\n ) => {\n // Resolve the shared hit before either projection branch consumes it.\n const z = modelViewMatrix\n .mul(vec4(position, 1))\n .z.toVar('capturedSurfaceViewZ');\n const reversed = builder.renderer.reversedDepthBuffer === true;\n // One material can alternate between a perspective view and orthographic\n // shadow cameras without a new pipeline; select using the active projection.\n const perspective = cameraProjectionMatrix\n .mul(vec4(0, 0, 0, 1))\n .w.equal(0);\n const perspectiveDepth =\n builder.renderer.logarithmicDepthBuffer === true\n ? viewZToLogarithmicDepth(z, cameraNear, cameraFar)\n : (reversed\n ? viewZToReversedPerspectiveDepth\n : viewZToPerspectiveDepth)(z, cameraNear, cameraFar);\n const result = perspective.select(\n perspectiveDepth,\n (reversed\n ? viewZToReversedOrthographicDepth\n : viewZToOrthographicDepth)(z, cameraNear, cameraFar),\n );\n return shadowBias &&\n 'isShadowPassMaterial' in builder.material &&\n builder.material.isShadowPassMaterial\n ? result.add(reversed ? -shadowBias : shadowBias).clamp(0, 1)\n : result;\n },\n )();\n}\n"],
|
|
5
|
+
"mappings": ";;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMA,SAAS,qBAAqB,UAAU,aAAa,GAAG;AAC7D,SAAO;AAAA,IACL,CACyB,GAC2B,YAC/C;AAEH,YAAM,IAAI,gBACP,IAAI,KAAK,UAAU,CAAC,CAAC,EACrB,EAAE,MAAM,sBAAsB;AACjC,YAAM,WAAW,QAAQ,SAAS,wBAAwB;AAG1D,YAAM,cAAc,uBACjB,IAAI,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC,EACpB,EAAE,MAAM,CAAC;AACZ,YAAM,mBACJ,QAAQ,SAAS,2BAA2B,OACxC,wBAAwB,GAAG,YAAY,SAAS,KAC/C,WACG,kCACA,yBAAyB,GAAG,YAAY,SAAS;AAC3D,YAAM,SAAS,YAAY;AAAA,QACzB;AAAA,SACC,WACG,mCACA,0BAA0B,GAAG,YAAY,SAAS;AAAA,MACxD;AACA,aAAO,cACL,0BAA0B,QAAQ,YAClC,QAAQ,SAAS,uBACf,OAAO,IAAI,WAAW,CAAC,aAAa,UAAU,EAAE,MAAM,GAAG,CAAC,IAC1D;AAAA,IACN;AAAA,EACF,EAAE;AACJ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// src/rendering/captured-surface-material.js
|
|
4
|
+
import { MeshStandardNodeMaterial } from "three/webgpu";
|
|
5
|
+
import { context, modelViewMatrix, modelWorldMatrix, vec4 } from "three/tsl";
|
|
6
|
+
var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
|
|
7
|
+
/** @type {import('three/webgpu').Node<'vec3'> | null} */
|
|
8
|
+
capturedPositionNode = null;
|
|
9
|
+
/**
|
|
10
|
+
* @override
|
|
11
|
+
* @param {import('three/webgpu').NodeBuilder} builder
|
|
12
|
+
*/
|
|
13
|
+
setupLighting(builder) {
|
|
14
|
+
const lighting = super.setupLighting(builder);
|
|
15
|
+
if (!this.capturedPositionNode) return lighting;
|
|
16
|
+
const world = modelWorldMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;
|
|
17
|
+
const view = modelViewMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;
|
|
18
|
+
return context(lighting, {
|
|
19
|
+
positionView: view,
|
|
20
|
+
positionWorld: world,
|
|
21
|
+
shadowPositionWorld: world
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
export {
|
|
26
|
+
CapturedSurfaceMaterial
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=captured-surface-material.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/rendering/captured-surface-material.js"],
|
|
4
|
+
"sourcesContent": ["// @ts-check\nimport { MeshStandardNodeMaterial } from 'three/webgpu';\nimport { context, modelViewMatrix, modelWorldMatrix, vec4 } from 'three/tsl';\n\n/** Light reconstructed surfaces at their hit position, not the carrier face.\n * View directions stay on the same ray; local lights also need the hit distance.\n */\nexport class CapturedSurfaceMaterial extends MeshStandardNodeMaterial {\n /** @type {import('three/webgpu').Node<'vec3'> | null} */\n capturedPositionNode = null;\n\n /**\n * @override\n * @param {import('three/webgpu').NodeBuilder} builder\n */\n setupLighting(builder) {\n const lighting = super.setupLighting(builder);\n if (!this.capturedPositionNode) return lighting;\n const world = modelWorldMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;\n const view = modelViewMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;\n return context(lighting, {\n positionView: view,\n positionWorld: world,\n shadowPositionWorld: world,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": ";;;AACA,SAAS,gCAAgC;AACzC,SAAS,SAAS,iBAAiB,kBAAkB,YAAY;AAK1D,IAAM,0BAAN,cAAsC,yBAAyB;AAAA;AAAA,EAEpE,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMvB,cAAc,SAAS;AACrB,UAAM,WAAW,MAAM,cAAc,OAAO;AAC5C,QAAI,CAAC,KAAK,qBAAsB,QAAO;AACvC,UAAM,QAAQ,iBAAiB,IAAI,KAAK,KAAK,sBAAsB,CAAC,CAAC,EAAE;AACvE,UAAM,OAAO,gBAAgB,IAAI,KAAK,KAAK,sBAAsB,CAAC,CAAC,EAAE;AACrE,WAAO,QAAQ,UAAU;AAAA,MACvB,cAAc;AAAA,MACd,eAAe;AAAA,MACf,qBAAqB;AAAA,IACvB,CAAC;AAAA,EACH;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
|
|
3
|
+
// src/rendering/renderer-support.js
|
|
4
|
+
import * as TSL from "three/tsl";
|
|
5
|
+
function rendererSupportsImpostorNodeMaterials(renderer) {
|
|
6
|
+
if (typeof Reflect.get(TSL, "struct") !== "function") return false;
|
|
7
|
+
return renderer?.isWebGPURenderer === true || renderer?.capabilities?.supportsNodeMaterials === true;
|
|
8
|
+
}
|
|
9
|
+
var pending = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
async function enableRendererNodeMaterials(renderer) {
|
|
11
|
+
if (rendererSupportsImpostorNodeMaterials(renderer) || !renderer?.isWebGLRenderer || !renderer.setNodesHandler || typeof Reflect.get(TSL, "struct") !== "function") return;
|
|
12
|
+
let setup = pending.get(renderer);
|
|
13
|
+
if (!setup) {
|
|
14
|
+
setup = import("three/addons/tsl/WebGLNodesHandler.js").then(({ WebGLNodesHandler }) => {
|
|
15
|
+
if (rendererSupportsImpostorNodeMaterials(renderer)) return;
|
|
16
|
+
renderer.setNodesHandler?.(new WebGLNodesHandler());
|
|
17
|
+
renderer.capabilities ??= {};
|
|
18
|
+
renderer.capabilities.supportsNodeMaterials = true;
|
|
19
|
+
}).catch((error) => {
|
|
20
|
+
pending.delete(renderer);
|
|
21
|
+
throw error;
|
|
22
|
+
});
|
|
23
|
+
pending.set(renderer, setup);
|
|
24
|
+
}
|
|
25
|
+
await setup;
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
enableRendererNodeMaterials,
|
|
29
|
+
rendererSupportsImpostorNodeMaterials
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=renderer-support.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/rendering/renderer-support.js"],
|
|
4
|
+
"sourcesContent": ["// @ts-check\nimport * as TSL from 'three/tsl';\n\n/**\n * @typedef {object} ImpostorRenderer\n * @property {boolean=} isWebGPURenderer\n * @property {boolean=} isWebGLRenderer\n * @property {(object & {supportsNodeMaterials?: boolean})=} capabilities\n * @property {((handler: import('three/addons/tsl/WebGLNodesHandler.js').WebGLNodesHandler) => void)=} setNodesHandler\n */\n\n/**\n * Reports whether a renderer can compile Baker's TSL impostor material.\n * WebGPURenderer supports node materials directly. Classic WebGLRenderer\n * integrations must advertise that they installed a compatible nodes handler.\n *\n * @param {ImpostorRenderer | undefined} renderer\n */\nexport function rendererSupportsImpostorNodeMaterials(renderer) {\n\tif (typeof Reflect.get(TSL, 'struct') !== 'function') return false;\n\treturn renderer?.isWebGPURenderer === true\n\t\t|| renderer?.capabilities?.supportsNodeMaterials === true;\n}\n\n/** @type {WeakMap<ImpostorRenderer, Promise<void>>} */\nconst pending = new WeakMap();\n\n/** Enable Three's existing TSL handler only when an enabled asset needs it.\n * Hosts with their own compiler advertise supportsNodeMaterials to retain it.\n * @param {ImpostorRenderer | undefined} renderer */\nexport async function enableRendererNodeMaterials(renderer) {\n\tif (rendererSupportsImpostorNodeMaterials(renderer) ||\n\t\t!renderer?.isWebGLRenderer || !renderer.setNodesHandler ||\n\t\ttypeof Reflect.get(TSL, 'struct') !== 'function') return;\n\tlet setup = pending.get(renderer);\n\tif (!setup) {\n\t\tsetup = import('three/addons/tsl/WebGLNodesHandler.js').then(({WebGLNodesHandler}) => {\n\t\t\tif (rendererSupportsImpostorNodeMaterials(renderer)) return;\n\t\t\trenderer.setNodesHandler?.(new WebGLNodesHandler());\n\t\t\trenderer.capabilities ??= {};\n\t\t\trenderer.capabilities.supportsNodeMaterials = true;\n\t\t}).catch(error => {\n\t\t\tpending.delete(renderer);\n\t\t\tthrow error;\n\t\t});\n\t\tpending.set(renderer, setup);\n\t}\n\tawait setup;\n}\n\n"],
|
|
5
|
+
"mappings": ";;;AACA,YAAY,SAAS;AAiBd,SAAS,sCAAsC,UAAU;AAC/D,MAAI,OAAO,QAAQ,IAAI,KAAK,QAAQ,MAAM,WAAY,QAAO;AAC7D,SAAO,UAAU,qBAAqB,QAClC,UAAU,cAAc,0BAA0B;AACvD;AAGA,IAAM,UAAU,oBAAI,QAAQ;AAK5B,eAAsB,4BAA4B,UAAU;AAC3D,MAAI,sCAAsC,QAAQ,KACjD,CAAC,UAAU,mBAAmB,CAAC,SAAS,mBACxC,OAAO,QAAQ,IAAI,KAAK,QAAQ,MAAM,WAAY;AACnD,MAAI,QAAQ,QAAQ,IAAI,QAAQ;AAChC,MAAI,CAAC,OAAO;AACX,YAAQ,OAAO,uCAAuC,EAAE,KAAK,CAAC,EAAC,kBAAiB,MAAM;AACrF,UAAI,sCAAsC,QAAQ,EAAG;AACrD,eAAS,kBAAkB,IAAI,kBAAkB,CAAC;AAClD,eAAS,iBAAiB,CAAC;AAC3B,eAAS,aAAa,wBAAwB;AAAA,IAC/C,CAAC,EAAE,MAAM,WAAS;AACjB,cAAQ,OAAO,QAAQ;AACvB,YAAM;AAAA,IACP,CAAC;AACD,YAAQ,IAAI,UAAU,KAAK;AAAA,EAC5B;AACA,QAAM;AACP;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -144,20 +144,71 @@ function registerNeedlePixelImpostorLoader(loader) {
|
|
|
144
144
|
return loader;
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
// src/rendering/captured-surface-material.js
|
|
148
|
+
import { MeshStandardNodeMaterial } from "three/webgpu";
|
|
149
|
+
import { context, modelViewMatrix, modelWorldMatrix, vec4 } from "three/tsl";
|
|
150
|
+
var CapturedSurfaceMaterial = class extends MeshStandardNodeMaterial {
|
|
151
|
+
/** @type {import('three/webgpu').Node<'vec3'> | null} */
|
|
152
|
+
capturedPositionNode = null;
|
|
153
|
+
/**
|
|
154
|
+
* @override
|
|
155
|
+
* @param {import('three/webgpu').NodeBuilder} builder
|
|
156
|
+
*/
|
|
157
|
+
setupLighting(builder) {
|
|
158
|
+
const lighting = super.setupLighting(builder);
|
|
159
|
+
if (!this.capturedPositionNode) return lighting;
|
|
160
|
+
const world = modelWorldMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;
|
|
161
|
+
const view = modelViewMatrix.mul(vec4(this.capturedPositionNode, 1)).xyz;
|
|
162
|
+
return context(lighting, {
|
|
163
|
+
positionView: view,
|
|
164
|
+
positionWorld: world,
|
|
165
|
+
shadowPositionWorld: world
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
// src/rendering/captured-surface-depth.js
|
|
171
|
+
import {
|
|
172
|
+
Fn,
|
|
173
|
+
cameraFar,
|
|
174
|
+
cameraNear,
|
|
175
|
+
cameraProjectionMatrix,
|
|
176
|
+
modelViewMatrix as modelViewMatrix2,
|
|
177
|
+
vec4 as vec42,
|
|
178
|
+
viewZToLogarithmicDepth,
|
|
179
|
+
viewZToOrthographicDepth,
|
|
180
|
+
viewZToPerspectiveDepth,
|
|
181
|
+
viewZToReversedOrthographicDepth,
|
|
182
|
+
viewZToReversedPerspectiveDepth
|
|
183
|
+
} from "three/tsl";
|
|
184
|
+
function capturedSurfaceDepth(position, shadowBias = 0) {
|
|
185
|
+
return Fn(
|
|
186
|
+
(_, builder) => {
|
|
187
|
+
const z = modelViewMatrix2.mul(vec42(position, 1)).z.toVar("capturedSurfaceViewZ");
|
|
188
|
+
const reversed = builder.renderer.reversedDepthBuffer === true;
|
|
189
|
+
const perspective = cameraProjectionMatrix.mul(vec42(0, 0, 0, 1)).w.equal(0);
|
|
190
|
+
const perspectiveDepth = builder.renderer.logarithmicDepthBuffer === true ? viewZToLogarithmicDepth(z, cameraNear, cameraFar) : (reversed ? viewZToReversedPerspectiveDepth : viewZToPerspectiveDepth)(z, cameraNear, cameraFar);
|
|
191
|
+
const result = perspective.select(
|
|
192
|
+
perspectiveDepth,
|
|
193
|
+
(reversed ? viewZToReversedOrthographicDepth : viewZToOrthographicDepth)(z, cameraNear, cameraFar)
|
|
194
|
+
);
|
|
195
|
+
return shadowBias && "isShadowPassMaterial" in builder.material && builder.material.isShadowPassMaterial ? result.add(reversed ? -shadowBias : shadowBias).clamp(0, 1) : result;
|
|
196
|
+
}
|
|
197
|
+
)();
|
|
198
|
+
}
|
|
199
|
+
|
|
147
200
|
// src/pixel-impostor/pixel-impostor-display.js
|
|
148
201
|
import * as THREE from "three";
|
|
149
|
-
import { MeshBasicNodeMaterial, MeshStandardNodeMaterial } from "three/webgpu";
|
|
202
|
+
import { MeshBasicNodeMaterial, MeshStandardNodeMaterial as MeshStandardNodeMaterial2 } from "three/webgpu";
|
|
150
203
|
import {
|
|
151
204
|
Break,
|
|
152
|
-
Fn,
|
|
205
|
+
Fn as Fn2,
|
|
153
206
|
If,
|
|
154
207
|
Loop,
|
|
155
208
|
abs,
|
|
156
209
|
attribute,
|
|
157
|
-
cameraProjectionMatrix,
|
|
210
|
+
cameraProjectionMatrix as cameraProjectionMatrix2,
|
|
158
211
|
cameraProjectionMatrixInverse,
|
|
159
|
-
cameraFar,
|
|
160
|
-
cameraNear,
|
|
161
212
|
cameraPosition,
|
|
162
213
|
cameraWorldMatrix,
|
|
163
214
|
ceil,
|
|
@@ -169,8 +220,8 @@ import {
|
|
|
169
220
|
max,
|
|
170
221
|
min,
|
|
171
222
|
mix,
|
|
172
|
-
modelViewMatrix,
|
|
173
|
-
modelWorldMatrix,
|
|
223
|
+
modelViewMatrix as modelViewMatrix3,
|
|
224
|
+
modelWorldMatrix as modelWorldMatrix2,
|
|
174
225
|
modelWorldMatrixInverse,
|
|
175
226
|
mod,
|
|
176
227
|
normalMap as normalMapNode,
|
|
@@ -189,10 +240,8 @@ import {
|
|
|
189
240
|
uv,
|
|
190
241
|
vec2,
|
|
191
242
|
vec3,
|
|
192
|
-
vec4,
|
|
193
|
-
vertexColor
|
|
194
|
-
viewZToOrthographicDepth,
|
|
195
|
-
viewZToPerspectiveDepth
|
|
243
|
+
vec4 as vec43,
|
|
244
|
+
vertexColor
|
|
196
245
|
} from "three/tsl";
|
|
197
246
|
function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
198
247
|
const binding = descriptor;
|
|
@@ -283,7 +332,7 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
283
332
|
const bytes = uvec4(texture(indexAtlas, linearTextureUv(texel, indexAtlasSize)).mul(255).round());
|
|
284
333
|
return bytes.x.bitOr(bytes.y.shiftLeft(8)).bitOr(bytes.z.shiftLeft(16)).bitOr(bytes.w.shiftLeft(24));
|
|
285
334
|
};
|
|
286
|
-
const traceVolumeNode =
|
|
335
|
+
const traceVolumeNode = Fn2(([sampleOffset]) => {
|
|
287
336
|
const rasterPixelSize = screenPixelSize.mul(dpr);
|
|
288
337
|
const sampleCoordinate = screenCoordinate.div(rasterPixelSize).floor().mul(rasterPixelSize).add(
|
|
289
338
|
rasterPixelSize.mul(vec2(0.5).add(sampleOffset))
|
|
@@ -291,8 +340,8 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
291
340
|
const sampleUv = sampleCoordinate.div(screenSize);
|
|
292
341
|
const nearView = getViewPosition(sampleUv, float(0), cameraProjectionMatrixInverse);
|
|
293
342
|
const farView = getViewPosition(sampleUv, float(1), cameraProjectionMatrixInverse);
|
|
294
|
-
const nearWorld = cameraWorldMatrix.mul(
|
|
295
|
-
const farWorld = cameraWorldMatrix.mul(
|
|
343
|
+
const nearWorld = cameraWorldMatrix.mul(vec43(nearView, 1));
|
|
344
|
+
const farWorld = cameraWorldMatrix.mul(vec43(farView, 1));
|
|
296
345
|
const rayOrigin = modelWorldMatrixInverse.mul(nearWorld).xyz;
|
|
297
346
|
const rayFar = modelWorldMatrixInverse.mul(farWorld).xyz;
|
|
298
347
|
const rayDirection = rayFar.sub(rayOrigin).normalize();
|
|
@@ -317,7 +366,7 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
317
366
|
const nextDistance = cellFraction.mul(vec3(1).sub(positiveAxis)).add(vec3(1).sub(cellFraction).mul(positiveAxis));
|
|
318
367
|
const nextCrossing = nextDistance.div(absoluteVelocity).toVar();
|
|
319
368
|
const crossingDelta = vec3(1).div(absoluteVelocity);
|
|
320
|
-
const result =
|
|
369
|
+
const result = vec43(0, 0, 0, 0).toVar();
|
|
321
370
|
const travelled = nearestDistance.toVar();
|
|
322
371
|
Loop(maximumSteps, () => {
|
|
323
372
|
const outside = cell.x.lessThan(0).or(cell.y.lessThan(0)).or(cell.z.lessThan(0)).or(cell.x.greaterThanEqual(planar)).or(cell.y.greaterThanEqual(layers)).or(cell.z.greaterThanEqual(planar));
|
|
@@ -341,7 +390,7 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
341
390
|
cellOccupied = texture(atlas, atlasUv).a.greaterThan(0.5);
|
|
342
391
|
}
|
|
343
392
|
If(cellOccupied, () => {
|
|
344
|
-
result.assign(
|
|
393
|
+
result.assign(vec43(
|
|
345
394
|
rayOrigin.add(rayDirection.mul(travelled)),
|
|
346
395
|
linearCell.add(1)
|
|
347
396
|
));
|
|
@@ -369,10 +418,6 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
369
418
|
/** @type {unknown} */
|
|
370
419
|
traceVolumeNode
|
|
371
420
|
);
|
|
372
|
-
const reconstructedDepth = Fn(([localPosition], builder) => {
|
|
373
|
-
const viewZ = modelViewMatrix.mul(vec4(localPosition, 1)).z;
|
|
374
|
-
return builder.camera.isPerspectiveCamera ? viewZToPerspectiveDepth(viewZ, cameraNear, cameraFar) : viewZToOrthographicDepth(viewZ, cameraNear, cameraFar);
|
|
375
|
-
}, "float");
|
|
376
421
|
const createRaycastMaterial = (antialias, pbr) => {
|
|
377
422
|
const centerHit = traceVolume(vec2(0));
|
|
378
423
|
const occupied = centerHit.w.greaterThan(0);
|
|
@@ -414,9 +459,9 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
414
459
|
);
|
|
415
460
|
}
|
|
416
461
|
const baseSample = texture(atlas, hitAtlasUv);
|
|
417
|
-
const ormSample = ormAtlas ? texture(ormAtlas, hitAtlasUv) :
|
|
462
|
+
const ormSample = ormAtlas ? texture(ormAtlas, hitAtlasUv) : vec43(1, 1, 0, 1);
|
|
418
463
|
const hitPosition = hit.xyz;
|
|
419
|
-
const hitToCamera = modelWorldMatrixInverse.mul(
|
|
464
|
+
const hitToCamera = modelWorldMatrixInverse.mul(vec43(cameraPosition, 1)).xyz.sub(hitPosition);
|
|
420
465
|
const faceSign = step(0, hitToCamera).mul(2).sub(1);
|
|
421
466
|
const hitCellCenter = hitCell.add(0.5).div(volumeDimensions).sub(0.5).mul(sizeNode).sub(raycastOffsetNode);
|
|
422
467
|
const cellDelta = hitPosition.sub(hitCellCenter).div(sizeNode).mul(volumeDimensions);
|
|
@@ -435,13 +480,13 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
435
480
|
const projectedNormal = bakedNormal.dot(geometricNormal).lessThan(0).select(bakedNormal.negate(), bakedNormal);
|
|
436
481
|
const shadingNormal = mix(geometricNormal, projectedNormal, projectedNormalMix).normalize();
|
|
437
482
|
const materialName = `Pixel impostor \xB7 volume raycast \xB7 ${antialias ? "AA" : "fast"} \xB7 ${pbr ? "PBR maps" : "plain lit"}`;
|
|
438
|
-
const material = new
|
|
483
|
+
const material = new CapturedSurfaceMaterial({
|
|
439
484
|
name: materialName,
|
|
440
485
|
side: THREE.FrontSide,
|
|
441
486
|
depthTest: true,
|
|
442
487
|
depthWrite: true
|
|
443
488
|
});
|
|
444
|
-
material.colorNode =
|
|
489
|
+
material.colorNode = vec43(
|
|
445
490
|
baseSample.rgb.mul(float(1).sub(unlitMix)),
|
|
446
491
|
antialias ? baseSample.a.mul(coverage) : baseSample.a
|
|
447
492
|
);
|
|
@@ -452,13 +497,14 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
452
497
|
material.roughnessNode = ormSample.g.max(0.04);
|
|
453
498
|
material.metalnessNode = ormSample.b;
|
|
454
499
|
}
|
|
455
|
-
material.receivedShadowPositionNode =
|
|
500
|
+
material.receivedShadowPositionNode = modelWorldMatrix2.mul(vec43(hitPosition, 1)).xyz;
|
|
456
501
|
material.maskNode = occupied.and(
|
|
457
502
|
baseSample.a.greaterThan(Number(descriptor.alphaCutoff) || 0.5)
|
|
458
503
|
);
|
|
459
504
|
material.maskShadowNode = antialias ? coverage.greaterThanEqual(0.5) : occupied;
|
|
460
505
|
material.alphaToCoverage = antialias;
|
|
461
|
-
material.
|
|
506
|
+
material.capturedPositionNode = hitPosition;
|
|
507
|
+
material.depthNode = capturedSurfaceDepth(hitPosition);
|
|
462
508
|
material.toneMapped = true;
|
|
463
509
|
material.userData.screenPixelSize = screenPixelSize;
|
|
464
510
|
material.userData.pixelImpostorRaycastAntialias = antialias;
|
|
@@ -504,7 +550,7 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
504
550
|
shell
|
|
505
551
|
);
|
|
506
552
|
const geometryBaseSample = texture(atlas, uv());
|
|
507
|
-
const geometryOrmSample = ormAtlas ? texture(ormAtlas, uv()) :
|
|
553
|
+
const geometryOrmSample = ormAtlas ? texture(ormAtlas, uv()) : vec43(1, 1, 0, 1);
|
|
508
554
|
const geometryNormal = attribute(
|
|
509
555
|
"normal",
|
|
510
556
|
/** @type {const} */
|
|
@@ -513,13 +559,13 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
513
559
|
const geometryProjectedNormal = normalAtlas ? texture(normalAtlas, uv()).xyz.mul(2).sub(1).normalize() : geometryNormal;
|
|
514
560
|
const geometryAlignedNormal = geometryProjectedNormal.dot(geometryNormal).lessThan(0).select(geometryProjectedNormal.negate(), geometryProjectedNormal);
|
|
515
561
|
const createGeometryMaterial = (pbr) => {
|
|
516
|
-
const material = new
|
|
562
|
+
const material = new MeshStandardNodeMaterial2({
|
|
517
563
|
name: `Pixel impostor \xB7 voxel geometry \xB7 ${pbr ? "mapped" : "plain"}`,
|
|
518
564
|
side: THREE.FrontSide,
|
|
519
565
|
depthTest: true,
|
|
520
566
|
depthWrite: true
|
|
521
567
|
});
|
|
522
|
-
material.colorNode =
|
|
568
|
+
material.colorNode = vec43(
|
|
523
569
|
geometryBaseSample.rgb.mul(float(1).sub(unlitMix)),
|
|
524
570
|
geometryBaseSample.a
|
|
525
571
|
);
|
|
@@ -599,13 +645,13 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
599
645
|
/** @type {const} */
|
|
600
646
|
"vec2"
|
|
601
647
|
);
|
|
602
|
-
const centerView =
|
|
603
|
-
const centerClip =
|
|
648
|
+
const centerView = modelViewMatrix3.mul(vec43(voxelCenter, 1));
|
|
649
|
+
const centerClip = cameraProjectionMatrix2.mul(centerView);
|
|
604
650
|
const centerNdc = centerClip.xy.div(centerClip.w);
|
|
605
651
|
const cssViewport = viewportSize;
|
|
606
652
|
const centerCss = centerNdc.mul(0.5).add(0.5).mul(cssViewport);
|
|
607
653
|
const projectVoxelPoint = (point) => {
|
|
608
|
-
const projected =
|
|
654
|
+
const projected = cameraProjectionMatrix2.mul(modelViewMatrix3.mul(vec43(point, 1)));
|
|
609
655
|
return projected.xy.div(projected.w).mul(0.5).add(0.5).mul(cssViewport);
|
|
610
656
|
};
|
|
611
657
|
const projectedX = projectVoxelPoint(voxelCenter.add(vec3(voxelHalfExtents.x, 0, 0)));
|
|
@@ -626,10 +672,10 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
626
672
|
const splatSize = cellSpan.mul(splatPixelSize).mul(splatScale);
|
|
627
673
|
const quadCss = snappedCss.add(voxelCorner.mul(splatSize.mul(0.52)));
|
|
628
674
|
const quadNdc = quadCss.div(cssViewport).mul(2).sub(1);
|
|
629
|
-
const quadClip =
|
|
675
|
+
const quadClip = vec43(quadNdc.mul(centerClip.w), centerClip.z, centerClip.w);
|
|
630
676
|
const quadViewHomogeneous = cameraProjectionMatrixInverse.mul(quadClip);
|
|
631
677
|
const quadView = quadViewHomogeneous.xyz.div(quadViewHomogeneous.w);
|
|
632
|
-
const quadWorld = cameraWorldMatrix.mul(
|
|
678
|
+
const quadWorld = cameraWorldMatrix.mul(vec43(quadView, 1));
|
|
633
679
|
const quadLocalHomogeneous = modelWorldMatrixInverse.mul(quadWorld);
|
|
634
680
|
const quadLocal = quadLocalHomogeneous.xyz.div(quadLocalHomogeneous.w);
|
|
635
681
|
const splatUv = useSurfacePoints ? linearTextureUv(attribute(
|
|
@@ -638,8 +684,8 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
638
684
|
"float"
|
|
639
685
|
), surfaceAtlasSize) : uv();
|
|
640
686
|
const splatColor = texture(atlas, splatUv);
|
|
641
|
-
const splatOrm = ormAtlas ? texture(ormAtlas, splatUv) :
|
|
642
|
-
const cameraLocal = modelWorldMatrixInverse.mul(
|
|
687
|
+
const splatOrm = ormAtlas ? texture(ormAtlas, splatUv) : vec43(1, 1, 0, 1);
|
|
688
|
+
const cameraLocal = modelWorldMatrixInverse.mul(vec43(cameraPosition, 1)).xyz;
|
|
643
689
|
const viewDirection = cameraLocal.sub(voxelCenter).normalize();
|
|
644
690
|
const splatBakedNormal = normalAtlas ? texture(normalAtlas, splatUv).xyz.mul(2).sub(1).normalize() : viewDirection;
|
|
645
691
|
const splatProjectedNormal = splatBakedNormal.dot(viewDirection).lessThan(0).select(splatBakedNormal.negate(), splatBakedNormal);
|
|
@@ -681,14 +727,14 @@ function createPixelImpostorRaycastPreview(asset, bounds, descriptor) {
|
|
|
681
727
|
splatMask = sourceFaceNormal.dot(viewDirection).greaterThanEqual(bestFaceScore.sub(1e-5)).and(splatColor.a.greaterThan(0.5));
|
|
682
728
|
}
|
|
683
729
|
const createSnappedMaterial = (pbr) => {
|
|
684
|
-
const material = new
|
|
730
|
+
const material = new MeshStandardNodeMaterial2({
|
|
685
731
|
name: `Pixel impostor \xB7 vertex-snapped shell \xB7 ${pbr ? "mapped" : "plain"}`,
|
|
686
732
|
side: THREE.FrontSide,
|
|
687
733
|
depthTest: true,
|
|
688
734
|
depthWrite: true
|
|
689
735
|
});
|
|
690
736
|
material.positionNode = quadLocal;
|
|
691
|
-
material.colorNode =
|
|
737
|
+
material.colorNode = vec43(splatColor.rgb.mul(float(1).sub(unlitMix)), splatColor.a);
|
|
692
738
|
material.emissiveNode = splatColor.rgb.mul(pbr ? splatOrm.r : 1).mul(unlitMix);
|
|
693
739
|
material.normalNode = transformNormalToView(splatShadingNormal);
|
|
694
740
|
if (pbr) {
|