@threenative/runtime-native 0.3.11 → 0.3.13
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/android/app/src/main/java/com/mystral/engine/MystralActivity.java +4 -1
- package/build/web/tn-native-engine-web-threads.mjs +1 -1
- package/build/web/tn-native-engine-web-threads.wasm +0 -0
- package/build/web/tn-native-engine-web.mjs +1 -1
- package/build/web/tn-native-engine-web.wasm +0 -0
- package/package.json +7 -7
- package/scripts/bundle-native-engine.mjs +64 -12
- package/scripts/desktop-distribution.mjs +3 -0
- package/scripts/package-android.mjs +2 -0
- package/scripts/package-engine-desktop.mjs +12 -6
- package/scripts/profile-production.mjs +2 -1
- package/scripts/verify-starter-desktop-base.mjs +9 -2
- package/src/engine/player/core-assets.mjs +30 -0
- package/src/engine/player/core-compressed-texture-preparation.mjs +16 -0
- package/src/engine/player/core-host.mjs +21 -2
- package/src/engine/player/core-three.mjs +83 -11
- package/src/engine/player/core-tsl.mjs +37 -9
- package/src/engine/player/core-unused.mjs +4 -0
- package/src/engine/player/core-webgpu.mjs +37 -12
|
@@ -15,7 +15,12 @@ withConstValues(constants, { Vector2, Vector3, Vector4, Color });
|
|
|
15
15
|
|
|
16
16
|
// three's `uniform.value = x` (shared with the Wasm back end): a number goes through at once; an
|
|
17
17
|
// edited Color or VectorN goes through `syncUniforms`, which the renderer calls before each frame.
|
|
18
|
-
const live = liveUniforms(
|
|
18
|
+
const live = liveUniforms(
|
|
19
|
+
globalThis.tsl.uniform,
|
|
20
|
+
(node, lanes) => globalThis.tsl.setUniform(node, ...lanes),
|
|
21
|
+
// PRD-828: a sync's changed uniforms cross as one call.
|
|
22
|
+
globalThis.tsl.setUniforms && ((nodes, counts, lanes) => globalThis.tsl.setUniforms(nodes, counts, lanes)),
|
|
23
|
+
);
|
|
19
24
|
// A boolean uniform (the exposure meter's `enabled`) is the live float compared with zero, as on the Wasm back end.
|
|
20
25
|
export const uniform = booleanUniforms(live.uniform, (scalar) => globalThis.tsl.notEqual(scalar, 0));
|
|
21
26
|
export const uniformArray = live.uniformArray;
|
|
@@ -25,13 +30,19 @@ export const syncUniforms = live.sync;
|
|
|
25
30
|
export const { float, int, uint, vec2, vec3, color } = constants;
|
|
26
31
|
export const vec4 = markNormalTarget(constants.vec4, globalThis.tsl.normalView);
|
|
27
32
|
export const Fn = withFnBuilder(globalThis.tsl.Fn);
|
|
33
|
+
// three's compute(node, count, workgroupSize) is node.compute(...), which the engine binds (PRD-784 P5-9).
|
|
34
|
+
// An absent workgroup size stays absent: the engine refuses an undefined argument.
|
|
35
|
+
export const compute = (node, count, workgroupSize) =>
|
|
36
|
+
workgroupSize === undefined ? node.compute(count) : node.compute(count, workgroupSize);
|
|
37
|
+
// three's lights([...]) takes one array; each light crosses as its own engine object.
|
|
38
|
+
export const lights = (list = []) => globalThis.tsl.lights(...list);
|
|
28
39
|
export const {
|
|
29
|
-
atomicAdd, atomicStore, atomicLoad, Break, Continue, Return, log, lightShadowMatrix, attribute, uv, renderOutput, If, Loop, luminance, viewZToOrthographicDepth, viewZToPerspectiveDepth, logarithmicDepthToViewZ, vertexIndex,
|
|
40
|
+
atomicAdd, atomicSub, atomicMax, atomicMin, atomicAnd, atomicOr, atomicXor, atomicStore, atomicLoad, Break, Continue, Return, Discard, log, lightShadowMatrix, attribute, uv, renderOutput, If, Loop, luminance, viewZToOrthographicDepth, viewZToPerspectiveDepth, logarithmicDepthToViewZ, vertexIndex,
|
|
30
41
|
add, sub, mul, div, negate, lessThan, greaterThan, equal, lessThanEqual, greaterThanEqual, and, or, not, all, any, abs, sin, cos,
|
|
31
42
|
floor, fract, sqrt, exp, exp2, log2, normalize, length, min, max, pow, step, dot,
|
|
32
43
|
distance, cross, mix, clamp, smoothstep, select, positionLocal, positionWorld, positionWorldDirection,
|
|
33
|
-
normalViewGeometry, instanceIndex, cameraViewMatrix, modelWorldMatrix, ivec2, uvec2, nodeObject, reflect, textureLoad, textureSize,
|
|
34
|
-
mx_noise_float, mx_worley_noise_float, mx_worley_noise_vec2, pmremTexture,
|
|
44
|
+
normalViewGeometry, instanceIndex, cameraViewMatrix, modelWorldMatrix, ivec2, ivec3, ivec4, uvec2, uvec3, uvec4, nodeObject, reflect, textureLoad, textureSize,
|
|
45
|
+
mx_noise_float, mx_worley_noise_float, mx_worley_noise_vec2, pmremTexture,
|
|
35
46
|
convertToTexture, screenUV, materialColor, materialEmissive, materialMetalness, materialRoughness,
|
|
36
47
|
cameraPosition, cameraProjectionMatrix, cameraWorldMatrix, positionGeometry, normalWorld, varying,
|
|
37
48
|
cameraNear, cameraFar, screenSize, depth, viewportSharedTexture, viewportDepthTexture, linearDepth, viewportLinearDepth,
|
|
@@ -42,12 +53,15 @@ export const {
|
|
|
42
53
|
atan, mod, fwidth, saturation, mat2, hash, time, deltaTime, transformDirection, normalWorldGeometry,
|
|
43
54
|
getViewPosition, frameGroup, renderGroup, objectGroup, transformNormalToView, property,
|
|
44
55
|
} = globalThis.tsl;
|
|
56
|
+
// three's viewportCoordinate is screenCoordinate.sub(viewport.xy) (ScreenNode.js). Every native pass
|
|
57
|
+
// draws the full target, so viewport.xy is (0, 0) and the two are equal.
|
|
58
|
+
export const viewportCoordinate = screenCoordinate;
|
|
45
59
|
|
|
46
60
|
export const { storageTexture, textureStore } = defineStorageTextures(globalThis.tsl);
|
|
47
61
|
|
|
48
62
|
// three's storage buffers over engine BufferAttributes (shared with the Wasm back end): `storage`,
|
|
49
63
|
// `instancedArray` and `attributeArray` build the engine's storage node, whose kernels `renderer.compute` runs.
|
|
50
|
-
export const { storage, instancedArray, attributeArray, StorageBufferAttribute, StorageInstancedBufferAttribute } =
|
|
64
|
+
export const { storage, instancedArray, attributeArray, StorageBufferAttribute, StorageInstancedBufferAttribute, IndirectStorageBufferAttribute } =
|
|
51
65
|
defineStorage(globalThis.tsl, BufferAttribute);
|
|
52
66
|
|
|
53
67
|
// three's pass(), mrt() and MRT slots over the player's one scene pass (shared with the Wasm back
|
|
@@ -85,8 +99,9 @@ export const rtt = defineRtt(globalThis.tsl.rtt, { NodeMaterial: globalThis.Node
|
|
|
85
99
|
import { defineWgslFn } from "../../../../three-native/src/wgsl-fn.ts";
|
|
86
100
|
export const wgslFn = defineWgslFn(globalThis.tsl.wgslFunction);
|
|
87
101
|
|
|
88
|
-
|
|
89
|
-
|
|
102
|
+
// three's TextureNode.value: assigning another texture swaps the one the node samples (ProbeVolume swaps its volume).
|
|
103
|
+
const swappable = (make) => (value, ...args) => {
|
|
104
|
+
const node = make(value, ...args);
|
|
90
105
|
let current = value;
|
|
91
106
|
return Object.defineProperty(node, "value", {
|
|
92
107
|
get: () => current,
|
|
@@ -96,7 +111,10 @@ export function texture(value, ...args) {
|
|
|
96
111
|
current = next;
|
|
97
112
|
},
|
|
98
113
|
});
|
|
99
|
-
}
|
|
114
|
+
};
|
|
115
|
+
export const texture = swappable((...args) => globalThis.tsl.texture(...args));
|
|
116
|
+
export const texture3D = swappable((...args) => globalThis.tsl.texture3D(...args));
|
|
117
|
+
export const cubeTexture = swappable((...args) => globalThis.tsl.cubeTexture(...args));
|
|
100
118
|
|
|
101
119
|
export const {
|
|
102
120
|
EPSILON, INFINITY, PI, PI2, TWO_PI, HALF_PI, radians,
|
|
@@ -112,8 +130,18 @@ export const {
|
|
|
112
130
|
// Refused at use, as on Wasm: the engine draws a lamp's cube shadow taps (shadowFilterOptions) and the
|
|
113
131
|
// virtual shadow map (virtualShadowOptions) in C++, so the three-only bodies of core's soft-shadow.ts
|
|
114
132
|
// and VirtualShadowNode.setup name these and never call them here.
|
|
115
|
-
export const cubeTexture = unsupportedExport("cubeTexture");
|
|
116
133
|
export const Stack = unsupportedExport("Stack");
|
|
117
134
|
export const getShadowMaterial = unsupportedExport("getShadowMaterial");
|
|
118
135
|
export const shadow = unsupportedExport("shadow");
|
|
119
136
|
export const shadowPositionWorld = unsupportedExport("shadowPositionWorld");
|
|
137
|
+
export const element = unsupportedExport("element");
|
|
138
|
+
export const instancedBufferAttribute = unsupportedExport("instancedBufferAttribute");
|
|
139
|
+
export const instancedDynamicBufferAttribute = unsupportedExport("instancedDynamicBufferAttribute");
|
|
140
|
+
export const positionView = unsupportedExport("positionView");
|
|
141
|
+
export const transformNormal = unsupportedExport("transformNormal");
|
|
142
|
+
export const varyingProperty = unsupportedExport("varyingProperty");
|
|
143
|
+
// Core's rough diffuse lighting model reads these on three's renderer only; the engine shades roughDiffuse in C++.
|
|
144
|
+
// biome-ignore lint/style/useNamingConvention: the name is three/tsl's export, which core imports.
|
|
145
|
+
export const F_Schlick = unsupportedExport("F_Schlick");
|
|
146
|
+
export const specularColor = unsupportedExport("specularColor");
|
|
147
|
+
export const specularF90 = unsupportedExport("specularF90");
|
|
@@ -19,3 +19,7 @@ export const {
|
|
|
19
19
|
positionPrevious, storage, tangentGeometry, tangentLocal, uint, vec4,
|
|
20
20
|
context, mrt, output, velocity,
|
|
21
21
|
} = globalThis;
|
|
22
|
+
// three-mesh-bvh/webgpu's TSL ray query: core's GPUSceneBVH reads these at import, and a scene that builds one is refused.
|
|
23
|
+
export const bvhIntersectFirstHit = unsupportedExport("bvhIntersectFirstHit");
|
|
24
|
+
export const bvhNodeStruct = unsupportedExport("bvhNodeStruct");
|
|
25
|
+
export const rayStruct = unsupportedExport("rayStruct");
|
|
@@ -17,24 +17,26 @@ for (const name of ["DirectionalLightShadow", "PointLightShadow", "SpotLightShad
|
|
|
17
17
|
}
|
|
18
18
|
import { BufferAttribute, Color, DataTexture, Material, NormalBlending } from "./core-three.mjs";
|
|
19
19
|
import { unsupportedExport } from "../../../../three-native/src/refused.ts";
|
|
20
|
-
import { PassNode, StorageBufferAttribute, StorageInstancedBufferAttribute, syncUniforms, updateSecondaryPasses } from "./core-tsl.mjs";
|
|
20
|
+
import { IndirectStorageBufferAttribute, PassNode, StorageBufferAttribute, StorageInstancedBufferAttribute, syncUniforms, updateSecondaryPasses } from "./core-tsl.mjs";
|
|
21
21
|
import { readStorageBytes } from "../../../../three-native/src/storage.ts";
|
|
22
22
|
import { GAME_SPANS } from "../../../../core/src/profiling/Spans.ts";
|
|
23
23
|
import { defineToneMappingLibrary } from "../../../../three-native/src/tone-mapping.ts";
|
|
24
24
|
import { ShadowMap } from "../../../../three-native/src/shadow-map.ts";
|
|
25
25
|
import { defineSphereReflectionCapture } from "../../../../three-native/src/sphere-reflection-capture.ts";
|
|
26
|
-
import { defineRenderTargets } from "../../../../three-native/src/render-target.ts";
|
|
26
|
+
import { defineRenderTargets, textureCopyArguments } from "../../../../three-native/src/render-target.ts";
|
|
27
27
|
import { defineQuadMesh } from "../../../../three-native/src/quad-mesh.ts";
|
|
28
28
|
import { defineTempNode } from "../../../../three-native/src/temp-node.ts";
|
|
29
29
|
import { defineRendererUtils } from "../../../../three-native/src/renderer-utils.ts";
|
|
30
30
|
import { GPU_STAGES, SHADOW_STAGE } from "../../../../three-native/src/gpu-stages.ts";
|
|
31
31
|
|
|
32
|
-
export const { StorageTexture, MeshBasicNodeMaterial, MeshStandardNodeMaterial, SpriteNodeMaterial } = globalThis;
|
|
32
|
+
export const { StorageTexture, Storage3DTexture, MeshBasicNodeMaterial, MeshStandardNodeMaterial, MeshPhysicalNodeMaterial, SpriteNodeMaterial } = globalThis;
|
|
33
33
|
Object.setPrototypeOf(StorageTexture.prototype, globalThis.Texture.prototype);
|
|
34
|
+
Object.setPrototypeOf(Storage3DTexture.prototype, globalThis.Texture.prototype);
|
|
34
35
|
Object.setPrototypeOf(MeshBasicNodeMaterial.prototype, globalThis.MeshBasicMaterial.prototype);
|
|
35
36
|
Object.setPrototypeOf(MeshStandardNodeMaterial.prototype, globalThis.MeshStandardMaterial.prototype);
|
|
37
|
+
Object.setPrototypeOf(MeshPhysicalNodeMaterial.prototype, globalThis.MeshPhysicalMaterial.prototype);
|
|
36
38
|
Object.setPrototypeOf(SpriteNodeMaterial.prototype, globalThis.SpriteMaterial.prototype);
|
|
37
|
-
for (const material of [MeshBasicNodeMaterial, MeshStandardNodeMaterial, SpriteNodeMaterial]) {
|
|
39
|
+
for (const material of [MeshBasicNodeMaterial, MeshStandardNodeMaterial, MeshPhysicalNodeMaterial, SpriteNodeMaterial]) {
|
|
38
40
|
material.prototype.isNodeMaterial = true;
|
|
39
41
|
material.prototype[`is${material.name}`] = true;
|
|
40
42
|
}
|
|
@@ -61,12 +63,11 @@ class NativeBackend {
|
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
function drawTarget(renderer, target, root, camera, deferred) {
|
|
66
|
+
function drawTarget(renderer, target, root, camera, deferred, layer = 0) {
|
|
65
67
|
syncUniforms();
|
|
66
68
|
renderer.library.apply(renderer.toneMapping);
|
|
67
69
|
globalThis.tn.setRendererState(renderer); // the target clears to the renderer's current clear colour
|
|
68
|
-
|
|
69
|
-
else globalThis.tn.renderTarget(target, root, camera);
|
|
70
|
+
globalThis.tn.renderTarget(target, root, camera, deferred === true, renderer.autoClear !== false, layer);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
// Every offscreen PassNode plans its draw into its own target; the player records it in this frame, after the post
|
|
@@ -80,6 +81,8 @@ export class WebGPURenderer {
|
|
|
80
81
|
// The native scene pass draws to the player-owned surface, not a retained frame target.
|
|
81
82
|
supportsRetainedTargetSubrect = false;
|
|
82
83
|
renderScale = 1;
|
|
84
|
+
// three's autoClear: false draws into a render target over its contents (the player's own frame always clears).
|
|
85
|
+
autoClear = true;
|
|
83
86
|
get temporalUpscale() { return globalThis.tn.renderInfo().temporalUpscale === true; }
|
|
84
87
|
setRenderScale(scale) {
|
|
85
88
|
if (!Number.isFinite(scale) || scale < 0.25 || scale > 1)
|
|
@@ -116,6 +119,13 @@ export class WebGPURenderer {
|
|
|
116
119
|
if (segments[0] > 0) stages[SHADOW_STAGE] = segments[0];
|
|
117
120
|
return stages;
|
|
118
121
|
},
|
|
122
|
+
// The same sample split by pass, as the Wasm engine publishes it (PRD-871): the scene pass, every shadow map (sun
|
|
123
|
+
// and lamps), and the rest (other passes, output, gather). Core's `gpuFrameSample` hands it to TN_FRAME_BUDGET.
|
|
124
|
+
get gpuSplit() {
|
|
125
|
+
const { samples, source, segments } = globalThis.tn.renderInfo().gpuTiming;
|
|
126
|
+
if (!(samples > 0)) return undefined;
|
|
127
|
+
return { frame: source, main: segments[1], shadow: segments[0] + segments[5], other: segments[2] + segments[3] + segments[4] };
|
|
128
|
+
},
|
|
119
129
|
},
|
|
120
130
|
frame: 0,
|
|
121
131
|
reset() {},
|
|
@@ -156,6 +166,9 @@ export class WebGPURenderer {
|
|
|
156
166
|
const { width, height } = globalThis.tn.surfaceSize();
|
|
157
167
|
return target.set(width, height);
|
|
158
168
|
}
|
|
169
|
+
// render() publishes the frame, and the player draws it after the frame callback: the engine runs
|
|
170
|
+
// onBeforeRender then, so core's geometry capture keeps its hooks until the next frame.
|
|
171
|
+
drawsAfterFrame = true;
|
|
159
172
|
render(scene, camera) {
|
|
160
173
|
updateTempNodes(this, scene, camera);
|
|
161
174
|
drawSecondaryPasses(this);
|
|
@@ -212,13 +225,23 @@ export class WebGPURenderer {
|
|
|
212
225
|
}
|
|
213
226
|
// Drops the attribute's GPU copy; the next use uploads its CPU contents again.
|
|
214
227
|
deleteAttribute(attribute) { globalThis.tn.deleteStorage(attribute); return this; }
|
|
228
|
+
// three's initTexture and copyTextureToTexture (as the Wasm back end's): `source.dataReady = false` uploads nothing,
|
|
229
|
+
// because the copies write the texels. A call before the player opens its renderer runs when it opens.
|
|
230
|
+
initTexture(texture) { globalThis.tn.initTexture(texture, texture?.source?.dataReady === false); }
|
|
231
|
+
copyTextureToTexture(source, destination, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = 0) {
|
|
232
|
+
globalThis.tn.copyTexture(source, destination, ...textureCopyArguments(srcRegion, dstPosition, srcLevel, dstLevel));
|
|
233
|
+
}
|
|
215
234
|
dispose() {}
|
|
216
235
|
}
|
|
217
236
|
|
|
218
237
|
// three's render targets (shared with the Wasm back end): render() while a target is set draws into
|
|
219
238
|
// it at the call, and readRenderTargetPixelsAsync reads it back once the GPU copy lands.
|
|
220
239
|
defineRenderTargets(WebGPURenderer.prototype, (renderer) => ({
|
|
221
|
-
draw: (target, root, camera) => drawTarget(renderer, target, root, camera),
|
|
240
|
+
draw: (target, root, camera, layer) => drawTarget(renderer, target, root, camera, false, layer),
|
|
241
|
+
clear: (target, color, depth) => {
|
|
242
|
+
globalThis.tn.setRendererState(renderer); // the clear colour
|
|
243
|
+
globalThis.tn.clearTarget(target, color, depth);
|
|
244
|
+
},
|
|
222
245
|
read: (target, x, y, width, height) => globalThis.tn.readTarget(target, x, y, width, height),
|
|
223
246
|
}));
|
|
224
247
|
// three's QuadMesh over the engine Mesh (shared with the Wasm back end).
|
|
@@ -273,14 +296,14 @@ export class RenderPipeline {
|
|
|
273
296
|
export { PassNode };
|
|
274
297
|
// three's NodeUpdateType, the constants a node's update schedule names.
|
|
275
298
|
export const NodeUpdateType = Object.freeze({ NONE: "none", FRAME: "frame", RENDER: "render", OBJECT: "object" });
|
|
276
|
-
// three's StorageBufferAttribute and
|
|
277
|
-
// as storage buffers (defined with the storage
|
|
278
|
-
|
|
299
|
+
// three's StorageBufferAttribute, StorageInstancedBufferAttribute and IndirectStorageBufferAttribute: BufferAttributes
|
|
300
|
+
// that TSL storage() binds as storage buffers, and that a geometry's setIndirect() takes (defined with the storage
|
|
301
|
+
// nodes, in core-tsl.mjs).
|
|
302
|
+
export { StorageBufferAttribute, StorageInstancedBufferAttribute, IndirectStorageBufferAttribute };
|
|
279
303
|
export const MeshLambertNodeMaterial = unsupportedExport("MeshLambertNodeMaterial");
|
|
280
304
|
export const MeshMatcapNodeMaterial = unsupportedExport("MeshMatcapNodeMaterial");
|
|
281
305
|
export const MeshNormalNodeMaterial = unsupportedExport("MeshNormalNodeMaterial");
|
|
282
306
|
export const MeshPhongNodeMaterial = unsupportedExport("MeshPhongNodeMaterial");
|
|
283
|
-
export const MeshPhysicalNodeMaterial = unsupportedExport("MeshPhysicalNodeMaterial");
|
|
284
307
|
export const MeshToonNodeMaterial = unsupportedExport("MeshToonNodeMaterial");
|
|
285
308
|
|
|
286
309
|
// three's BlendMode (renderers/common/BlendMode.js): the blend state an MRT output names through
|
|
@@ -310,6 +333,8 @@ NodeMaterial.prototype.isNodeMaterial = true;
|
|
|
310
333
|
export const RendererUtils = defineRendererUtils(Color);
|
|
311
334
|
// Refused at use: only VirtualShadowNode.setup builds one, and the engine draws that map in C++.
|
|
312
335
|
export const AssignNode = unsupportedExport("AssignNode");
|
|
336
|
+
export const BundleGroup = unsupportedExport("BundleGroup");
|
|
337
|
+
export const EventNode = unsupportedExport("EventNode");
|
|
313
338
|
|
|
314
339
|
WebGPURenderer.prototype.SphereReflectionCapture = defineSphereReflectionCapture(
|
|
315
340
|
async (scene, x, y, z, size, face, renderer) => {
|