threedog 1.2.0 → 1.3.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.
- package/CHANGELOG.md +14 -0
- package/core/base/errorCodes.js +9 -0
- package/core/engine/Engine.js +1 -1
- package/core/engine/startup.js +3 -2
- package/core/inspect/UrlState.js +4 -1
- package/core/scene/Views.js +23 -8
- package/core/scene/gameLights.js +3 -1
- package/docs/CODEMAP.md +2 -1
- package/docs/COMMANDS.md +1 -1
- package/docs/THREE.md +2 -0
- package/docs/recipes/16-dev-bridge.md +1 -0
- package/docs/recipes/46-blender-art-route.md +1 -1
- package/docs/recipes/56-webgpu-tsl.md +2 -1
- package/docs/recipes/60-judge-the-picture.md +1 -1
- package/docs/recipes/62-picture-code.md +2 -0
- package/docs/recipes/63-third-person-start.md +1 -0
- package/examples/action/.threedog/content-index.json +1 -1
- package/examples/perf-island/.threedog/content-index.json +1 -1
- package/examples/styletest/.threedog/content-index.json +1 -1
- package/examples/world/.threedog/content-index.json +1 -1
- package/package.json +2 -1
- package/render/PostFX.js +18 -1
- package/render/backend.js +10 -5
- package/render/bindingLimits.js +59 -0
- package/render/fx/compareLevel.tsl.js +23 -0
- package/render/fx/index.js +2 -0
- package/render/fx/postWebGPU.tsl.js +15 -0
- package/render/shaderErrors.js +42 -6
- package/types/core.d.ts +1 -1
- package/types/generated/core/scene/Views.d.ts +17 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
What changed in each version and how a game upgrades.
|
|
4
4
|
|
|
5
|
+
## 1.3.0 (2026-11-12)
|
|
6
|
+
|
|
7
|
+
- Fixed: on WebGPU the engine now asks the device for the adapter's own `maxBufferSize`, `maxStorageBufferBindingSize`, `maxSampledTexturesPerShaderStage` and `maxSamplersPerShaderStage` (as it already did for the color attachment limits) instead of WebGPU's defaults. Before, `voxelGI` on a scene of about a million triangles or more failed every frame with `Buffer size exceeds the max buffer size limit` (its triangle buffer passed the default 256 MB), and a material with more than 16 textures counting the lights' shadow maps failed with only `Invalid PipelineLayout`. Measured on one desktop GPU: buffer 256 MB to 2 GB, storage binding 128 MB to 2 GB, textures per stage 16 to 48; samplers stay where the adapter's own limit is 16. A game's own renderer keeps the limits the game gave it.
|
|
8
|
+
- Fixed: `sunShafts` (and any shader that compares a shadow map inside a loop of varying length) now compiles on D3D backends that use FXC. Before, it failed with `FXC compile failed with error: E_FAIL` and every frame that drew it was invalid. three's WGSL builder writes each compare sample with a screen derivative, which a one-level shadow map never needs; the engine now writes those as `textureSampleCompareLevel` (same arguments, same picture), listed in `describe().threePatches` as `compare-sample-level` and undone with `threePatches.off('compare-sample-level')`. A compare texture with mipmaps keeps three's call.
|
|
9
|
+
- New: `views.show({ position, target, fov })` shows a pose with no view declared, and `applyState({ view })`, the URL's `?view=` and `threedog state view=` take a pose as `x,y,z,targetX,targetY,targetZ[,fov]` next to a view name, so the camera can be placed on a running page before `threedog snap`. `threedog shot --cam` now goes this way too (its own code path is gone; the option is unchanged).
|
|
10
|
+
- Fixed: the type of `autoView.manual(key)` now takes `'aspect'` and `'sunDir'`, which the code and the docs already did.
|
|
11
|
+
- Fixed: a post effect whose own pass the device refuses to build (a shader the driver's compiler rejects, as `sunShafts` was on FXC) is now held off, and the frame draws without it. Before, `describe().render.post` kept showing it on while every frame that drew it was invalid. The engine puts an 'internal' error scope around the device's `createRenderPipeline` (three's own scope catches validation errors only), listed in `describe().threePatches` as `pipeline-internal-scope`. The page error names the material and the effect with the code `post-effect-failed` and ends with the device's words; `describe().render.post` shows `on: false` with the reason in `held`. It stays held until it is removed and added again. An effect that is only an expression (no pass of its own) is compiled into its neighbors' pass and cannot be told apart, so it is named by material only.
|
|
12
|
+
- New: a WebGPU material whose shader stage binds more sampled textures or samplers than the device allows (16 each on most: layers, shadow maps, environment) stops at its build with a `texture-bindings` error naming the material and mesh, the stage, the count against the limit and how many are shadow maps or environment maps, instead of the device's nameless `Invalid PipelineLayout`.
|
|
13
|
+
- New: `threedog init --scene-only` (and `new-game --scene-only`) starts a showcase scene with a camera, `picture/`, start screen, autosave and Esc menu, and no `content/` and no `assets.js`.
|
|
14
|
+
- Changed: `engine.budget` has a default guide for `shadowMaps`, 7 (the sun and one point light fit; a point light is six maps). Like the guide for lights nothing is cut at it; `engine.budget.enable({ shadowMaps: n })` sets your own. Before, two shadowed point lights could triple a frame's triangles with no line about it. The picture check ranks the line by the share of the frame's scene passes beyond the guide and prints the frame's triangles.
|
|
15
|
+
- Check rules: R70 (a file imported only for its side effects must be in the engine's `sideEffects` list, or a bundler drops it silently) and R71 (a parameter that takes one of a few named strings lists the same strings in the code's JSDoc and in the d.ts).
|
|
16
|
+
- Docs: recipe 62 section 2 says how to put the sun on a path of the game's own (`engine.autoView.manual('sunDir')`, then write `uSunDir` in `onRender`).
|
|
17
|
+
- Docs: recipe 63 section 7 says `world()` stays in a scene with no content (the player is a record in it); recipe 56 "Mistakes" says computed vertex colors are linear.
|
|
18
|
+
|
|
5
19
|
## 1.2.0 (2026-11-10)
|
|
6
20
|
|
|
7
21
|
- Fixed: shadows on tier 'low' no longer smear. With `engine.shadows.cascades(...)` the single low-tier map now covers `maxFar / count` (shifted toward the view), so its texels are as fine as one cascade's; a game's `count: 1` still covers all of `maxFar`. The engine sun's PCF radius follows its map size (2 on the low-tier 1024 map). A radius or map size the game set (any value other than the engine's default) is kept across tier changes. Trade-off: on tier 'low' far shadows end sooner (recipe 45).
|
package/core/base/errorCodes.js
CHANGED
|
@@ -486,6 +486,11 @@ export const ERROR_CODES = {
|
|
|
486
486
|
docs: ['api/post.md', 'recipes/52-around-the-picture.md §"Post effect chain"'],
|
|
487
487
|
fix: 'A post effect is malformed or clashes: engine.post.add takes a three.js Pass, a node function (WebGPU) or { name, create | node | fuse }, ' +
|
|
488
488
|
'with a unique name and a known slot. Change an existing effect with its handle (engine.post.get(name).set(params), .enabled); add one with engine.post.add (the one way).' },
|
|
489
|
+
'post-effect-failed': {
|
|
490
|
+
docs: ['recipes/52-around-the-picture.md §"Post effect chain"'],
|
|
491
|
+
fix: "The device could not build the shader of a post effect's own pass (a driver compiler error, or a device limit), so the engine holds that effect off and " +
|
|
492
|
+
'the frame draws without it. The message ends with what the device said. Same picture on other devices: nothing to do. ' +
|
|
493
|
+
'To run it here: change the option the error points at, then remove the effect and add it again.' },
|
|
489
494
|
'own-frame': {
|
|
490
495
|
docs: ['THREE.md', 'recipes/52-around-the-picture.md §"Post effect chain"'],
|
|
491
496
|
fix: 'The game draws the canvas itself (its own composer.render() / renderer.render outside engine.onRender), so the engine yielded ' +
|
|
@@ -700,6 +705,10 @@ export const ERROR_CODES = {
|
|
|
700
705
|
fix: "One program needs more vertex inputs than the device has (16 on most; WebGPU also 8 vertex buffers). The message counts what stacked up: geometry attributes the " +
|
|
701
706
|
"material reads, the instance matrix (4) and color (1), last frame's matrix for temporalAA's velocity buffer (4), engine patches, your own attribute nodes. " +
|
|
702
707
|
'Drop what is not read, pack per-instance values into one vec4, or move them to a storage buffer (instancedArray from three/tsl); temporalAA off frees 4.' },
|
|
708
|
+
'texture-bindings': {
|
|
709
|
+
docs: ['recipes/56-webgpu-tsl.md §"The engine\'s shader"'],
|
|
710
|
+
fix: "One shader stage binds more sampled textures or samplers than the device allows (16 each on most). The message names the material and counts them, with the shadow maps " +
|
|
711
|
+
"and environment / cube maps among them. Use fewer texture layers, pack maps into one texture's channels, or cast shadows from fewer lights." },
|
|
703
712
|
'webgpu-needs-tsl': {
|
|
704
713
|
docs: ['recipes/56-webgpu-tsl.md §"Turning it on"'],
|
|
705
714
|
fix: "On WebGPURenderer the engine draws with node materials. Either threedog/tsl is not loaded (add import 'threedog/tsl' at the top of the entry), " +
|
package/core/engine/Engine.js
CHANGED
|
@@ -151,7 +151,7 @@ export class Engine {
|
|
|
151
151
|
watchNodePrograms(r); // WebGPU: generated code per material, for debug.view('shaderCost') (render/backend.js)
|
|
152
152
|
this._records = recordSweep(r); // WebGPU: meshes that left the scene free their records (render/recordSweep.js)
|
|
153
153
|
if (isWebGPU(r)) dressNodeTwins(r); // WebGPU: classic materials get their patches as nodes (render/patches.js)
|
|
154
|
-
nameShaderErrors(r);
|
|
154
|
+
nameShaderErrors(r, id => this.post?._pipelineFailed(id) ?? ''); // compile errors name the patch and slot (render/shaderErrors.js); a game's own handler stays
|
|
155
155
|
this._deviceTier = tierFirst || detectTier(r);
|
|
156
156
|
/** @internal real screen pixels per art pixel, null when off (core/scene/pixelRatio.js) @type {number | null} */ this._pixelSize = null;
|
|
157
157
|
if (owned || pixelRatio != null) firstRatio(r, this._deviceTier, pixelRatio);
|
package/core/engine/startup.js
CHANGED
|
@@ -15,7 +15,7 @@ import { startHeadlessLoad } from './headlessLoad.js';
|
|
|
15
15
|
import * as THREE from 'three';
|
|
16
16
|
import { isWebGPU, backendName, whyNoWebGPU, firstNodeMaterial, webglOnlyOn, tier as detectTier, timerContext, rendererSwapped, compileThrough, borrowRenderer } from '../../render/backend.js';
|
|
17
17
|
import { bindUniforms } from '../../render/engineUniforms.js';
|
|
18
|
-
import { nameShaderErrors } from '../../render/shaderErrors.js';
|
|
18
|
+
import { nameShaderErrors, watchPipelineBuilds } from '../../render/shaderErrors.js';
|
|
19
19
|
import { forcedTier } from '../scene/tier.js';
|
|
20
20
|
import { GpuTimer } from '../scene/adaptive.js';
|
|
21
21
|
import { tierRatio, carryRatio, pixelSizeOn } from '../scene/pixelRatio.js';
|
|
@@ -169,6 +169,7 @@ export const startupMethods = {
|
|
|
169
169
|
}
|
|
170
170
|
if (reason && want.fallback === 'webgl') this._swapToWebGL(r);
|
|
171
171
|
else if (!r.initialized) { await r.init(); this._alive(); }
|
|
172
|
+
watchPipelineBuilds(this.renderer); // the device exists now: a pipeline its compiler refuses is named (render/shaderErrors.js)
|
|
172
173
|
const backend = backendName(this.renderer);
|
|
173
174
|
// the probe said yes but three still fell back (a device lost in between): say so all the same
|
|
174
175
|
if (!forced && backend === 'webgl2') reason ??= 'three fell back to its WebGL2 backend during init()';
|
|
@@ -206,7 +207,7 @@ export const startupMethods = {
|
|
|
206
207
|
r.toneMapping = old.toneMapping; r.toneMappingExposure = old.toneMappingExposure; r.outputColorSpace = old.outputColorSpace;
|
|
207
208
|
r.setClearColor(old.getClearColor(new THREE.Color()), old.getClearAlpha());
|
|
208
209
|
r.info.autoReset = false;
|
|
209
|
-
nameShaderErrors(r); bindUniforms(r, this.uniforms);
|
|
210
|
+
nameShaderErrors(r, id => this.post?._pipelineFailed(id) ?? ''); bindUniforms(r, this.uniforms);
|
|
210
211
|
try { old.dispose(); } catch { /* never initialized: nothing of it reached the GPU */ }
|
|
211
212
|
this.renderer = r;
|
|
212
213
|
movedOwned(this, new Map([[old, r]])); // owned rows name the renderer object they live on (tween exemptions, core/ops/owned.js)
|
package/core/inspect/UrlState.js
CHANGED
|
@@ -23,6 +23,7 @@ import { warnMissing, warnOnce, DEV } from '../base/validate.js';
|
|
|
23
23
|
import { xzOf, yOf } from '../base/math.js';
|
|
24
24
|
import { unsettled } from '../engine/headlessLoad.js';
|
|
25
25
|
import { codedError } from '../base/errorHints.js';
|
|
26
|
+
import { Views } from '../scene/Views.js';
|
|
26
27
|
|
|
27
28
|
// fresh deletes saves, so it acts only on a clear yes (a bare ?fresh reads as ''); anything that is neither a yes nor a no is refused in _expand, never ignored
|
|
28
29
|
const FRESH_ON = [true, 1, '1', ''], FRESH_OFF = [false, 0, '0', 'false'];
|
|
@@ -152,7 +153,9 @@ export class UrlState {
|
|
|
152
153
|
await new Promise(r => setTimeout(r, 0)); // main-loop: yield to the browser (background threads, Promise continuations) without advancing game time
|
|
153
154
|
}
|
|
154
155
|
await this._ask(p, this._moduleKeys(p), turn); // advancing moves time and the day, so align them last
|
|
155
|
-
|
|
156
|
+
// a name of engine.views, or a pose (an object, or the text a URL carries); a page with its own ?view= names (no engine.views declared) handles those itself
|
|
157
|
+
const view = typeof p.view === 'string' ? Views.pose(p.view) ?? p.view : p.view;
|
|
158
|
+
if (view && (typeof view !== 'string' || e.views.list().length) && e.views.show(view)) {
|
|
156
159
|
if (e.headless) e._frameHooks(0, true); // one loading frame: the modules see the new focus, so _settle has something to wait for
|
|
157
160
|
await this._settle(); // a picture of the view must not be taken before the world around it has loaded
|
|
158
161
|
}
|
package/core/scene/Views.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Named fixed camera views declared by the game, so a screenshot of "the same place" can be taken again after any change:
|
|
2
2
|
// engine.views.define('gate', { position: [10, 4, 12], target: [0, 1, 0], fov: 50 });
|
|
3
3
|
// engine.views.show('gate'); // or the URL ?view=gate, or `npm run shot -- -w my-game --view gate`
|
|
4
|
+
// engine.views.show({ position: [0, 20, -300], target: [0, 15, -500] }); // a pose with no name: a look from outside nobody declared (?view=0,20,-300,0,15,-500, `threedog state view=...`, `shot --cam`)
|
|
4
5
|
// A view takes over the camera with engine.takeCamera('views') (the same claim cutscenes use) until release() or the handle's remove(): a cutscene that
|
|
5
6
|
// held the camera before gets it back, instead of the camera going to nobody. It is a diagnostic aid, not a camera mode.
|
|
6
7
|
import { warnMissing } from '../base/validate.js';
|
|
@@ -10,6 +11,14 @@ import { holdFov, baseFov } from './view.js';
|
|
|
10
11
|
|
|
11
12
|
const vec3 = a => Array.isArray(a) && a.length === 3 && a.every(Number.isFinite);
|
|
12
13
|
|
|
14
|
+
/** A view as given, checked: { position, target, fov } @param {string} where @param {any} v */
|
|
15
|
+
function checked(where, v) {
|
|
16
|
+
readParams(where, keysSchema(['position', 'target', 'fov']), v);
|
|
17
|
+
if (!vec3(v.position)) throw codedError('views-define', `${where}: position must be [x, y, z], got ${JSON.stringify(v.position)}`);
|
|
18
|
+
if (v.target !== undefined && !vec3(v.target)) throw codedError('views-define', `${where}: target must be [x, y, z], got ${JSON.stringify(v.target)}`);
|
|
19
|
+
return { position: v.position, target: v.target ?? [0, 0, 0], fov: v.fov };
|
|
20
|
+
}
|
|
21
|
+
|
|
13
22
|
export class Views {
|
|
14
23
|
/** @param {any} engine */
|
|
15
24
|
constructor(engine) {
|
|
@@ -23,10 +32,7 @@ export class Views {
|
|
|
23
32
|
* @returns {{ remove(): void }}
|
|
24
33
|
*/
|
|
25
34
|
define(name, v) {
|
|
26
|
-
|
|
27
|
-
if (!vec3(v.position)) throw codedError('views-define', `views.define('${name}'): position must be [x, y, z], got ${JSON.stringify(v.position)}`);
|
|
28
|
-
if (v.target !== undefined && !vec3(v.target)) throw codedError('views-define', `views.define('${name}'): target must be [x, y, z], got ${JSON.stringify(v.target)}`);
|
|
29
|
-
const rec = { position: v.position, target: v.target ?? [0, 0, 0], fov: v.fov };
|
|
35
|
+
const rec = checked(`views.define('${name}')`, v);
|
|
30
36
|
this.map.set(name, rec);
|
|
31
37
|
return { remove: () => { if (this.map.get(name) === rec) { if (this.current === name) this.release(); this.map.delete(name); } } };
|
|
32
38
|
}
|
|
@@ -35,11 +41,20 @@ export class Views {
|
|
|
35
41
|
/** @returns {string[]} the declared view names */
|
|
36
42
|
list() { return [...this.map.keys()]; }
|
|
37
43
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @param {string}
|
|
44
|
+
* A pose written as text, 'x,y,z,targetX,targetY,targetZ[,fov]' (meters, fov in degrees): the form a URL's ?view= and `threedog state view=` carry. null when the text is not one
|
|
45
|
+
* @param {string} text @returns {{ position: number[], target: number[], fov?: number } | null}
|
|
46
|
+
*/
|
|
47
|
+
static pose(text) {
|
|
48
|
+
const n = String(text).split(',').map(s => (s.trim() === '' ? NaN : Number(s)));
|
|
49
|
+
return [6, 7].includes(n.length) && n.every(Number.isFinite) ? { position: n.slice(0, 3), target: n.slice(3, 6), ...(n.length === 7 && { fov: n[6] }) } : null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Put the camera on a view and keep it there (the camera rigs leave it alone) until release() or the returned handle's remove(); null for an unknown name.
|
|
53
|
+
* A pose { position, target?, fov? } in place of a name shows that pose without declaring it (current reads '(pose)')
|
|
54
|
+
* @param {string | { position: number[], target?: number[], fov?: number }} view @returns {{ remove(): void } | null}
|
|
40
55
|
*/
|
|
41
|
-
show(
|
|
42
|
-
const v = this.map.get(
|
|
56
|
+
show(view) {
|
|
57
|
+
const name = typeof view === 'string' ? view : '(pose)', v = typeof view === 'string' ? this.map.get(view) : checked('views.show()', view);
|
|
43
58
|
if (!v) { warnMissing('view', name, this.list()); return null; }
|
|
44
59
|
const e = this.engine;
|
|
45
60
|
// focus: the world loads around what the view looks at, not around a player far away (the view was an empty sheet of ground without it)
|
package/core/scene/gameLights.js
CHANGED
|
@@ -84,7 +84,9 @@ export function watchGameLights(e) {
|
|
|
84
84
|
e.budget.metric('lights', () => count(l => isShown(l) && l.intensity > 0), { limit: MANY });
|
|
85
85
|
e.budget.metric('shadowLights', () => e.renderer.shadowMap.enabled ? count(l => isShown(l) && l.castShadow && l.intensity > 0) : 0);
|
|
86
86
|
const maps = () => shadowMaps(e.renderer, e.scene);
|
|
87
|
-
|
|
87
|
+
// a guide like the one for lights (nothing is cut at it): the sun and one point light (six maps) fit; a second shadowed point light, or one beside cascades,
|
|
88
|
+
// is where the frame's triangles multiply (two of them took a 12 M triangle scene to 42 M) and nothing said so
|
|
89
|
+
e.budget.metric('shadowMaps', () => maps().reduce((n, m) => n + m.faces, 0), { limit: 7 });
|
|
88
90
|
e.budget.metric('shadowMapSize', () => maps().reduce((n, m) => Math.max(n, m.shadow.mapSize.x, m.shadow.mapSize.y), 0));
|
|
89
91
|
e._gameLights = {
|
|
90
92
|
/** The game's own point / spot lights (not a module's, not a pool's) */
|
package/docs/CODEMAP.md
CHANGED
|
@@ -106,6 +106,7 @@ Type = what the module may own (core/engine/moduleTypes.js): world, picture, act
|
|
|
106
106
|
**render/**
|
|
107
107
|
- PostFX.js: Post effects in five slots (both renderers)
|
|
108
108
|
- backend.js: Renderer facts that differ between WebGLRenderer and WebGPU…
|
|
109
|
+
- bindingLimits.js: Sampled textures and samplers of a WebGPURenderer program, …
|
|
109
110
|
- cascades.js: Cascaded shadows of one DirectionalLight: 2-4 maps along th…
|
|
110
111
|
- cascades.tsl.js: Cascaded shadows on WebGPURenderer (the WebGPU half of casc…
|
|
111
112
|
- daylight.js: Day and night as a signal
|
|
@@ -114,7 +115,7 @@ Type = what the module may own (core/engine/moduleTypes.js): world, picture, act
|
|
|
114
115
|
- engineUniforms.js: Engine uniforms (helper of patches.js)
|
|
115
116
|
- fogLook.js: What fog a scene is drawn with, for the parts that match so…
|
|
116
117
|
- fuse.js: Fused post pass
|
|
117
|
-
- fx/ threedog/tsl entry: the TSL Fn library — cel.tsl.js, cloudShadow.tsl.js, detail.tsl.js, library.tsl.js, lightShaft.tsl.js, lighting.tsl.js, nodeErrors.tsl.js, noise.tsl.js, objectOrigin.tsl.js, particles.tsl.js, patchNodes.tsl.js, pcss.tsl.js, postWebGPU.tsl.js, season.tsl.js, sky.tsl.js, uniforms.tsl.js, water.tsl.js, wind.tsl.js
|
|
118
|
+
- fx/ threedog/tsl entry: the TSL Fn library — cel.tsl.js, cloudShadow.tsl.js, compareLevel.tsl.js, detail.tsl.js, library.tsl.js, lightShaft.tsl.js, lighting.tsl.js, nodeErrors.tsl.js, noise.tsl.js, objectOrigin.tsl.js, particles.tsl.js, patchNodes.tsl.js, pcss.tsl.js, postWebGPU.tsl.js, season.tsl.js, sky.tsl.js, uniforms.tsl.js, water.tsl.js, wind.tsl.js
|
|
118
119
|
- fxNumbers.js: The numbers inside the engine's shared shader functions, wr…
|
|
119
120
|
- hotGlsl.js: Shader hot reload in dev
|
|
120
121
|
- impostor.tsl.js: Impostor cards for far plants (vegetation.define({ impostor…
|
package/docs/COMMANDS.md
CHANGED
|
@@ -105,7 +105,7 @@ They drive the running game. Run them inside the game folder or with `-w game`;
|
|
|
105
105
|
| `threedog skip` | jump the clock like sleeping: skip to=06:00 / skip seconds=600 (engine.skip: op time.skip, sky clock and time-keeping modules catch up; optional fade=0.6 save=auto). to works with calendar() alone; the sky only follows the clock when installed |
|
|
106
106
|
| `threedog press` | press a key or action: press interact / press KeyE / press e (held 0.1 s, then renders 1/60 s; --for 0.02 shortens the hold) |
|
|
107
107
|
| `threedog hold` | hold for N seconds: hold moveForward 1.5. moveForward walks along the camera's heading, so with a follow camera at its start angle it goes diagonally, not along an axis: place things by reading player after a short hold |
|
|
108
|
-
| `threedog state` | change the scenario without a reload: state time=18:30 weather=rain pos=40,-20 (pos=x,z has no height: the hero stands on the highest support over that spot, a ledge included; to stand under it, js "engine.player.placeAt([x, y, z])") |
|
|
108
|
+
| `threedog state` | change the scenario without a reload: state time=18:30 weather=rain pos=40,-20; view=name or view=x,y,z,tx,ty,tz[,fov] puts the camera on a declared view or a pose, for the next snap (pos=x,z has no height: the hero stands on the highest support over that spot, a ledge included; to stand under it, js "engine.player.placeAt([x, y, z])") |
|
|
109
109
|
| `threedog js` | evaluate an expression in the page (engine is available, await works; one expression prints its value, several statements print what they return): js "engine.calendar.timeOfDay"; long scripts: js --file path. A script that calls assert(cond, msg) or expect(v).toBe/toEqual/toBeCloseTo/toBeGreaterThan(x, msg) (or expect(v, msg)) runs as checks in ONE call: failed checks are recorded and the script goes on, a throw stops it; output ✓ 7 checks passed, or the failures then ✗ 2 of 7 checks failed; exit 1 on failure; --verbose adds passes, log lines and the return value. A script without those calls is the plain form. Both modes get the globals engine, step(seconds), log(...), assert, expect. --wait <seconds>, default 120: how long a script may wait on a page that looks stopped (driven by manual step, nothing loading, no clock tick); the command then ends and says the script may be waiting on the game clock, and the script may still run in the page |
|
|
110
110
|
| `threedog snap-describe` | describe snapshot instead of a screenshot, a baseline of the gameplay part of describe(): snap-describe save\|diff name [--only a,b] [--ignore x.y] [--tolerance 0.5] (recipes/16-dev-bridge.md section 7); in tests one line expectDescribe({ check, ev }, name, { only, tolerance }) from @threedog/tools/describe-snapshot |
|
|
111
111
|
| `threedog snap` | save a screenshot to .threedog/shots/name.png and run the picture check on the page, as threedog shot does (snap name, or snap path/to/file.png used as given; --play first leaves the title as shot --play; --width N scales the returned image down, the saved file stays full size; --no-picture skips the check) |
|
package/docs/THREE.md
CHANGED
|
@@ -59,6 +59,7 @@ see it, for every engine on the page; `engine.dispose()` does not undo a change.
|
|
|
59
59
|
| `occlusion-layers-test` | `layers.test` of a mesh `engine.occlusion` hides, an own property while it is hidden | `engine.camera` skips the mesh; every other camera, shadows and rays see it. `mask`, `visible` and clones stay yours | no; `engine.occlusion.enabled = false` removes it |
|
|
60
60
|
| `shadow-accessors` | `Mesh.prototype.customDepthMaterial / customDistanceMaterial` become accessors | Unassigned, they return a shadow material only for a mesh whose material carries a vertex-moving engine patch (wind), so its shadow sways too; otherwise `undefined` as in three. An assignment always wins | yes |
|
|
61
61
|
| `fog-linear` | `ShaderChunk.fog_pars_fragment`, `tonemapping_fragment` and `fog_fragment` (page-wide, WebGL) | Fog is mixed once, in linear space before the tone curve and the output encoding, on the canvas, under the composer and on WebGPU alike (three mixes after both, so far fog changed colour when the first effect turned on). Adds the GLSL helpers threedogFogColor and threedogFogFactor and the define `THREEDOG_FOG_DONE`; a material `fog` slot patch replaces this mix. A shader without the fog chunks keeps three's code | yes: `threePatches.off('fog-linear')` turns off only the engine's mix (distant fog mixes after tone mapping again); the helpers and the guard stay, so a fog slot patch keeps working |
|
|
62
|
+
| `compare-sample-level` | `WGSLNodeBuilder.prototype.generateTextureCompare` wrapped | WebGPU only: a shadow map compare is written as `textureSampleCompareLevel` (no screen derivative, same picture), so one inside a loop compiles on D3D's FXC (`sunShafts`); a mipmapped compare texture keeps three's call. | yes |
|
|
62
63
|
| `node-setup-position` | `NodeMaterial.prototype.setupPosition` wrapped | WebGPU only: runs the engine's vertex-moving patches (wind) first; other node materials unchanged | yes |
|
|
63
64
|
| `scene-add-hook` | `Object3D.prototype.add / remove` wrapped (page-wide) | None to the call itself; the engine sees what enters and leaves its scene at any depth (adopting `scene.add`, cascades, cloud shadow, light counts). Another library wrapping the same methods stacks with it | yes (`scene.add` no longer adopted) |
|
|
64
65
|
| `mesh-material-accessor` | `material` on each object entering the engine's scene: an own get / set on that object (a class accessor, e.g. troika text, still runs) | In devtools `mesh.material` shows as an accessor; `mesh.material = other` works as in three and is seen | yes (new objects) |
|
|
@@ -74,6 +75,7 @@ see it, for every engine on the page; `engine.dispose()` does not undo a change.
|
|
|
74
75
|
| `post-background-tone` | `onBeforeRender` of three's own background mesh, while the engine draws straight to the canvas | A texture background is tone-mapped as it is through the post chain; your own `renderer.render` keeps three's rule | yes |
|
|
75
76
|
| `node-twin-dress` | `renderer.library.fromMaterial` of a WebGPURenderer wrapped | WebGPU only: the node twin of a classic material gets its patches | no (patched materials would lose their picture on WebGPU) |
|
|
76
77
|
| `node-builder-hook` | `renderer.debug.onNodeBuilderCreated` of a WebGPURenderer wrapped | WebGPU only: your own hook still runs; a later write of yours replaces the engine's | yes |
|
|
78
|
+
| `pipeline-internal-scope` | `createRenderPipeline` of the renderer's GPUDevice wrapped | WebGPU only: an 'internal' error scope around the call; a pipeline the driver refuses is named, its post effect held | yes |
|
|
77
79
|
| `device-lost-hook` | `renderer.onDeviceLost` of a WebGPURenderer wrapped | WebGPU only: three's hook still runs; a later write of yours replaces the engine's | yes |
|
|
78
80
|
| `page-exit-pointer-lock` | `document.exitPointerLock` wrapped (one wrapper for all live engines, gone with the last) | a game-requested unlock reads as the player pressing Esc | yes |
|
|
79
81
|
| `occlusion-readback` | `resolveOccludedAsync` of the WebGPU backend (that one instance), once `engine.occlusion` is on | WebGPU only: an AbortError from a buffer destroyed with the renderer is dropped; any other error still reaches you | no (disposing an engine while occlusion answers are on their way would report an unhandled rejection) |
|
|
@@ -29,6 +29,7 @@ Every command and its options are in `../COMMANDS.md`. What each does to the gam
|
|
|
29
29
|
- `press interact` takes an action name or key (`KeyE`, `e`, `Escape`). **It advances game time**: 0.1 s held + one rendered frame of 1/60 s, about 0.117 s; shorten the hold with `--for 0.02` when timing matters.
|
|
30
30
|
- `op shop.buy shop=trader item=medkit n=2` runs as source `bridge`. Values follow the op's `args` shape (`n=2` a number, `position=3,0,-2` an array). **Change state with this, not `js`**: `js` writes skip the op log.
|
|
31
31
|
- `ops` lists every offer checked with `can`; `inspect [id | x,z]` adds what is around, with reasons (recipes/23-ops.md section 8); `explain op ...` / `explain quest ...` says why one cannot run or where a quest is stuck (`--full` adds the last attempt and events around it).
|
|
32
|
+
- `state view=gate` or `state view=0,5,12,0,1,0,50` (a pose: position, target, fov) places the camera for the next `snap`.
|
|
32
33
|
- `state time=18:30 weather=rain pos=40,-20` sets the scene like URL parameters (`engine.applyState`). A weather name must be in the game's table (`describe weather`; `weather({ types: presets.weather.temperate })`, which `--open-world` games start with): what could not be applied fails with the reason and exit 1.
|
|
33
34
|
- `js "engine.calendar.timeOfDay"`: `engine` is available directly and `await` works inside; multi-line statements need their own `return` (`js "const p = engine.player.position; return p.x + p.z"`). Long scripts: `js --file script.js`.
|
|
34
35
|
- `scenario barter` runs `tests/scenarios/barter.json` (recipes/23-ops.md section 7), prints failed checks and leaves the loop halted.
|
|
@@ -54,7 +54,7 @@ colliders, template / id nodes, spawn / trigger_ / npc_ / marker_ points; warnin
|
|
|
54
54
|
It needs `@gltf-transform/cli` (`npm i -D @gltf-transform/cli`); its current release pulls a `glob`/`minimatch` that `npm audit` flags (moderate, build time only), so add `"overrides": { "@donmccurdy/caporal": { "glob": "^14.0.4" } }` to your package.json. `--force` redoes unchanged files too.
|
|
55
55
|
|
|
56
56
|
### The same shot again, before and after
|
|
57
|
-
Declare fixed views once: `engine.views.define('gate', { position: [10, 4, 12], target: [0, 1, 0], fov: 50 })` (`views.show(name)` also works in code). Then
|
|
57
|
+
Declare fixed views once: `engine.views.define('gate', { position: [10, 4, 12], target: [0, 1, 0], fov: 50 })` (`views.show(name)` also works in code, a pose `{ position, target, fov }` too). Then
|
|
58
58
|
`npm run shot -- -w my-game --view gate --keep` takes the picture from there in any game (the page's own `?view=` still wins where a page handles it, as
|
|
59
59
|
in the picture test). After a change, `npm run shot -- -w my-game --view gate --compare .threedog/shots/<before>.png` prints both file names, one pixel-diff
|
|
60
60
|
number (0 = identical) and the brightness / saturation / contrast / detail differences. A view holds the camera (`engine.takeCamera`) until `views.release()` or the handle `show()` returns is removed; a cutscene that held it before gets it back.
|
|
@@ -102,7 +102,7 @@ engine.add(mesh);
|
|
|
102
102
|
three's shadow pass draws with the material's `positionNode`, so the shadow moves too. On an `InstancedMesh` with rotated or scaled instances the offset must turn with each (`instanceOffset`, or the patch form below).
|
|
103
103
|
|
|
104
104
|
A program takes 16 vertex inputs on most devices; past that the build stops with a `[vertex-inputs]` error that counts what stacked up and how to
|
|
105
|
-
fit. `objectOrigin()` costs 1 per program, `instanceOffset()` 3 more.
|
|
105
|
+
fit. `objectOrigin()` costs 1 per program, `instanceOffset()` 3 more. Textures, samplers: 16 a stage (`[texture-bindings]`).
|
|
106
106
|
|
|
107
107
|
## Patches with a `tsl` field (optional convenience)
|
|
108
108
|
`applyEffects(mat, { wind, season, clouds, patches })` (recipe 43) works on node materials: the engine's own patches carry a TSL version, and a
|
|
@@ -312,6 +312,7 @@ import { RenderPipeline } from 'three/webgpu';
|
|
|
312
312
|
// wrong: new PostProcessing(renderer) from older three examples (three 0.187 names it RenderPipeline), and a second pipeline beside the engine's
|
|
313
313
|
console.log(engine.post.object()?.pipeline instanceof RenderPipeline); // the engine's own, once its chain is built; add effects with engine.post.add
|
|
314
314
|
```
|
|
315
|
+
Vertex colors you compute are linear: `new THREE.Color().setHSL(h, s, l)` reads its numbers in the working (linear) space, so a color picked by eye comes out too light: pass `THREE.SRGBColorSpace` as the fourth argument, or write a hex value.
|
|
315
316
|
Also: three's `uniform` takes a value, not a `{ value }` object, so passing it `engine.uniforms.uWind` throws; use `uniforms(engine).uWind`.
|
|
316
317
|
A type mismatch never errors: look at the result (`engine.debug.view('lighting')`, `threedog shot`).
|
|
317
318
|
WebGPURenderer builds one program per distinct set of patch uniform objects: the same `applyEffects` options, or one patch object passed to every material,
|
|
@@ -61,7 +61,7 @@ hard-edged or pitch-dark look may want exactly what was measured. All of them re
|
|
|
61
61
|
| fog covers X% | how much of the picture is fog color; printed before a line about the night, since the fog comes first | `scene.fog` |
|
|
62
62
|
|
|
63
63
|
Limits a game sets per device go through the same check: `engine.budget.enable(engine.tier === 'low' ? { lights: 4 } : { lights: 12 })`. A limit you wrote is
|
|
64
|
-
reported as your own intent; the engine's default line
|
|
64
|
+
reported as your own intent; the engine's default line (lights 8, shadow maps 7) is only a fact.
|
|
65
65
|
|
|
66
66
|
## Same knob, different styles
|
|
67
67
|
A knob is a direction, not a setting. Three styles, the same three knobs, moved different ways:
|
|
@@ -68,6 +68,8 @@ Read `.value` in JS, or share the object in a shader (`uniforms: { uDaylight: en
|
|
|
68
68
|
picture, not physics: a styled game mixes them in only if it wants. Gameplay that changes the picture (a cutscene dims the world) goes through a signal
|
|
69
69
|
of your own that the picture code reads.
|
|
70
70
|
|
|
71
|
+
A sun on a path of your own: `engine.autoView.manual('sunDir')` once, then write `engine.uniforms.uSunDir.value` in the picture's `onRender` before the lights read it; the dome's sun follows.
|
|
72
|
+
|
|
71
73
|
Written every frame: `uSkyTop` and `uSkyHorizon` take `engine.sky.top` / `engine.sky.horizon`, `uDaylight` and `uTimeOfDay` take a `daylight` / `timeOfDay` measure; a direct write is lost and warns once (`signal-overwritten`). `uSunDir` (the same vector as `engine.sky.sunDir`) and `camera.aspect` stay as written: `engine.autoView.manual('sunDir', false)` gives one back.
|
|
72
74
|
|
|
73
75
|
## 3. The hook: `engine.onRender`, not `onFrame`
|
|
@@ -90,4 +90,5 @@ engine.collision.addBlocked((x, z) => maze[Math.floor(z)]?.[Math.floor(x)] === '
|
|
|
90
90
|
engine.collision.addBox([4, 0, -6], { halfWidth: 1, halfDepth: 0.2, height: 3 }); // one wall, crate or door frame
|
|
91
91
|
engine.cameraRig.yaw = Math.PI; // heading: yaw 0 looks toward -z, PI toward +z (recipe 21 §3)
|
|
92
92
|
```
|
|
93
|
+
`world()` stays even with no content and no saves (the player is a record in it); `content()`, `hud()`, `settings()` can go.
|
|
93
94
|
Walls from your own geometry are only picture until a collider (api/collision.md) says no. Later third-person: `engine.setCamera('follow')` (recipe 21 §1).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":
|
|
1
|
+
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":1794404132033.9805,"size":481,"from":0,"count":4,"indexIds":0,"positional":[]},"content/audio.js":{"kind":"audio","mtime":1794404132035.9958,"size":430,"from":0,"count":1,"indexIds":0,"positional":[]},"content/items.js":{"kind":"items","mtime":1794404132040.0073,"size":204,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1794404132042.007,"size":209,"from":0,"count":1,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794404132043.01,"size":707,"from":0,"count":8,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794404132046.5588,"size":835,"from":0,"count":4,"indexIds":0,"positional":[]},"content/views.js":{"kind":"views","mtime":1794404132049.1821,"size":539,"from":0,"count":2,"indexIds":0,"positional":[]}},"ids":{"attack":[{"file":"content/actions.js","kind":"actions","line":4,"placed":false}],"retry":[{"file":"content/actions.js","kind":"actions","line":5,"placed":false}],"save":[{"file":"content/actions.js","kind":"actions","line":6,"placed":false}],"load":[{"file":"content/actions.js","kind":"actions","line":7,"placed":false}],"sounds":[{"file":"content/audio.js","kind":"audio","line":4,"placed":false}],"gem":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"room":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"floor":[{"file":"content/props.js","kind":"props","line":3,"placed":true},{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wall-n":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"wall-s":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"wall-w":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"wall-e":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"pillar-1":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"pillar-2":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"slime-1":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"wall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"pillar":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"slime":[{"file":"content/templates.js","kind":"templates","line":9,"placed":false}],"corner":[{"file":"content/views.js","kind":"views","line":4,"placed":false}],"door":[{"file":"content/views.js","kind":"views","line":5,"placed":false}]}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"files":{"content/props.js":{"kind":"props","mtime":
|
|
1
|
+
{"version":1,"files":{"content/props.js":{"kind":"props","mtime":1794404132069.7053,"size":1370,"from":0,"count":15,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794404132071.7058,"size":232,"from":0,"count":2,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794404132073.7058,"size":522,"from":0,"count":1,"indexIds":0,"positional":[]}},"ids":{"tree-1":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"tree-2":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"tree-3":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"tree-4":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"tree-5":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"tree-6":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"tree-7":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"sheep-1":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"sheep-2":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"sheep-3":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"sheep-4":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"sheep-5":[{"file":"content/props.js","kind":"props","line":15,"placed":true}],"sheep-6":[{"file":"content/props.js","kind":"props","line":16,"placed":true}],"sheep-7":[{"file":"content/props.js","kind":"props","line":17,"placed":true}],"sheep-8":[{"file":"content/props.js","kind":"props","line":18,"placed":true}],"tree":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"sheep":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"wheat":[{"file":"content/vegetation.js","kind":"vegetation","line":6,"placed":false}]}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"files":{"content/items.js":{"kind":"items","mtime":
|
|
1
|
+
{"version":1,"files":{"content/items.js":{"kind":"items","mtime":1794404132140.8713,"size":471,"from":0,"count":3,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1794404132141.8728,"size":352,"from":0,"count":1,"indexIds":0,"positional":[]},"content/places.js":{"kind":"places","mtime":1794404132144.3772,"size":345,"from":0,"count":2,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794404132145.3877,"size":1208,"from":0,"count":12,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794404132148.3994,"size":394,"from":0,"count":6,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794404132150.5015,"size":1840,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"apple":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"key":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":5,"placed":false},{"file":"content/props.js","kind":"props","line":10,"placed":true}],"guide":[{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"stage":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"pine":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"round-tree":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"rock":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"flower-a":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"flower-b":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"flower-c":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"stone":[{"file":"content/props.js","kind":"props","line":11,"placed":true}],"metal":[{"file":"content/props.js","kind":"props","line":12,"placed":true}],"glass":[{"file":"content/props.js","kind":"props","line":13,"placed":true}],"shadow-stage":[{"file":"content/props.js","kind":"props","line":14,"placed":true}],"room":[{"file":"content/props.js","kind":"props","line":15,"placed":true},{"file":"content/templates.js","kind":"templates","line":8,"placed":false}],"woodBlock":[{"file":"content/templates.js","kind":"templates","line":3,"placed":false}],"stoneBlock":[{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"metalBall":[{"file":"content/templates.js","kind":"templates","line":5,"placed":false}],"glassPanes":[{"file":"content/templates.js","kind":"templates","line":6,"placed":false}],"shadowStage":[{"file":"content/templates.js","kind":"templates","line":7,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":4,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":10,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":16,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":20,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":25,"placed":false}]}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":
|
|
1
|
+
{"version":1,"files":{"content/actions.js":{"kind":"actions","mtime":1794404132453.4592,"size":458,"from":0,"count":4,"indexIds":0,"positional":[]},"content/audio.js":{"kind":"audio","mtime":1794404132455.9714,"size":2152,"from":0,"count":3,"indexIds":0,"positional":[]},"content/bodies.js":{"kind":"bodies","mtime":1794404132458.5864,"size":838,"from":0,"count":8,"indexIds":0,"positional":[]},"content/containers.js":{"kind":"containers","mtime":1794404132460.5818,"size":252,"from":0,"count":1,"indexIds":0,"positional":[]},"content/dialogues.js":{"kind":"dialogues","mtime":1794404132463.1018,"size":1861,"from":0,"count":1,"indexIds":0,"positional":[]},"content/items.js":{"kind":"items","mtime":1794404132468.3752,"size":589,"from":0,"count":4,"indexIds":0,"positional":[]},"content/npcs.js":{"kind":"npcs","mtime":1794404132470.3616,"size":654,"from":0,"count":1,"indexIds":0,"positional":[]},"content/pickups.js":{"kind":"pickups","mtime":1794404132472.3635,"size":699,"from":0,"count":8,"indexIds":8,"positional":[0,1,2,3,4,5,6,7]},"content/places.js":{"kind":"places","mtime":1794404132474.367,"size":498,"from":0,"count":3,"indexIds":0,"positional":[]},"content/props.js":{"kind":"props","mtime":1794404132475.3657,"size":1123,"from":0,"count":8,"indexIds":0,"positional":[]},"content/quests.js":{"kind":"quests","mtime":1794404132478.3652,"size":825,"from":0,"count":1,"indexIds":0,"positional":[]},"content/templates.js":{"kind":"templates","mtime":1794404132481.8801,"size":484,"from":0,"count":1,"indexIds":0,"positional":[]},"content/vegetation.js":{"kind":"vegetation","mtime":1794404132484.4043,"size":1967,"from":0,"count":5,"indexIds":0,"positional":[]}},"ids":{"save":[{"file":"content/actions.js","kind":"actions","line":4,"placed":false}],"load":[{"file":"content/actions.js","kind":"actions","line":5,"placed":false}],"kick":[{"file":"content/actions.js","kind":"actions","line":6,"placed":false}],"chop":[{"file":"content/actions.js","kind":"actions","line":7,"placed":false}],"sounds":[{"file":"content/audio.js","kind":"audio","line":7,"placed":false}],"ambience":[{"file":"content/audio.js","kind":"audio","line":14,"placed":false}],"footsteps":[{"file":"content/audio.js","kind":"audio","line":23,"placed":false}],"crate-0":[{"file":"content/bodies.js","kind":"bodies","line":4,"placed":false}],"crate-1":[{"file":"content/bodies.js","kind":"bodies","line":5,"placed":false}],"crate-2":[{"file":"content/bodies.js","kind":"bodies","line":6,"placed":false}],"crate-3":[{"file":"content/bodies.js","kind":"bodies","line":7,"placed":false}],"crate-4":[{"file":"content/bodies.js","kind":"bodies","line":8,"placed":false}],"crate-5":[{"file":"content/bodies.js","kind":"bodies","line":9,"placed":false}],"ball":[{"file":"content/bodies.js","kind":"bodies","line":10,"placed":false}],"barrel":[{"file":"content/bodies.js","kind":"bodies","line":11,"placed":false}],"fisher-basket":[{"file":"content/containers.js","kind":"containers","line":3,"placed":false}],"fisher":[{"file":"content/dialogues.js","kind":"dialogues","line":4,"placed":false},{"file":"content/npcs.js","kind":"npcs","line":3,"placed":false}],"film":[{"file":"content/items.js","kind":"items","line":3,"placed":false}],"berry":[{"file":"content/items.js","kind":"items","line":4,"placed":false}],"feather":[{"file":"content/items.js","kind":"items","line":5,"placed":false}],"wood":[{"file":"content/items.js","kind":"items","line":6,"placed":false}],"pickup:feather:0":[{"file":"content/pickups.js","kind":"pickups","line":3,"placed":true}],"pickup:berry:1":[{"file":"content/pickups.js","kind":"pickups","line":4,"placed":true}],"pickup:berry:2":[{"file":"content/pickups.js","kind":"pickups","line":5,"placed":true}],"pickup:feather:3":[{"file":"content/pickups.js","kind":"pickups","line":6,"placed":true}],"pickup:berry:4":[{"file":"content/pickups.js","kind":"pickups","line":7,"placed":true}],"pickup:berry:5":[{"file":"content/pickups.js","kind":"pickups","line":8,"placed":true}],"pickup:feather:6":[{"file":"content/pickups.js","kind":"pickups","line":9,"placed":true}],"pickup:berry:7":[{"file":"content/pickups.js","kind":"pickups","line":10,"placed":true}],"home":[{"file":"content/places.js","kind":"places","line":3,"placed":false}],"river":[{"file":"content/places.js","kind":"places","line":4,"placed":false}],"water":[{"file":"content/places.js","kind":"places","line":5,"placed":false}],"prop:pine:0":[{"file":"content/props.js","kind":"props","line":4,"placed":true}],"prop:pine:1":[{"file":"content/props.js","kind":"props","line":5,"placed":true}],"prop:roundTree:2":[{"file":"content/props.js","kind":"props","line":6,"placed":true}],"prop:rock:3":[{"file":"content/props.js","kind":"props","line":7,"placed":true}],"prop:rock:4":[{"file":"content/props.js","kind":"props","line":8,"placed":true}],"prop:flower:5":[{"file":"content/props.js","kind":"props","line":9,"placed":true}],"prop:flower:6":[{"file":"content/props.js","kind":"props","line":10,"placed":true}],"cabin":[{"file":"content/props.js","kind":"props","line":11,"placed":true},{"file":"content/templates.js","kind":"templates","line":4,"placed":false}],"first-light":[{"file":"content/quests.js","kind":"quests","line":4,"placed":false}],"松树":[{"file":"content/vegetation.js","kind":"vegetation","line":5,"placed":false}],"圆树":[{"file":"content/vegetation.js","kind":"vegetation","line":11,"placed":false}],"石头":[{"file":"content/vegetation.js","kind":"vegetation","line":17,"placed":false}],"草":[{"file":"content/vegetation.js","kind":"vegetation","line":21,"placed":false}],"野花":[{"file":"content/vegetation.js","kind":"vegetation","line":26,"placed":false}]}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "threedog",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Web 3D game engine on three.js: core + optional modules, no built-in art (the picture comes from your own style), built to be driven by an AI",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -83,6 +83,7 @@
|
|
|
83
83
|
"./render/effects.js",
|
|
84
84
|
"./render/fx/index.js",
|
|
85
85
|
"./render/fx/particles.tsl.js",
|
|
86
|
+
"./render/fx/compareLevel.tsl.js",
|
|
86
87
|
"./render/fx/patchNodes.tsl.js",
|
|
87
88
|
"./render/fx/postWebGPU.tsl.js",
|
|
88
89
|
"./render/fx/sky.tsl.js",
|
package/render/PostFX.js
CHANGED
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
// and stays synchronous (a dynamic import would leave the first frames without post and make _sync async).
|
|
11
11
|
import * as THREE from 'three';
|
|
12
12
|
import { webglPost } from './postWebGL.js';
|
|
13
|
-
import { codedError } from '../core/base/errorHints.js';
|
|
13
|
+
import { codedError, coded } from '../core/base/errorHints.js';
|
|
14
14
|
import { warnOnce } from '../core/base/validate.js';
|
|
15
|
+
import { reportError } from '../core/base/errors.js';
|
|
15
16
|
import { readParams, keysSchema } from '../core/base/params.js';
|
|
16
17
|
import { isWebGPU, webgpuPart, ownMsaa } from './backend.js';
|
|
17
18
|
import { MSAA_KEY, onTierChange } from '../core/scene/tier.js';
|
|
@@ -276,11 +277,27 @@ export class PostFX {
|
|
|
276
277
|
*/
|
|
277
278
|
_held(h) {
|
|
278
279
|
if (!h._on()) return null;
|
|
280
|
+
if (h._failed) return h._failed;
|
|
279
281
|
const w = runsHere(h._def, this.engine);
|
|
280
282
|
if (!w?.held) return null; // a mistake (node-only effect on the game's WebGLRenderer) is not held: postWebGL's sync throws it by name
|
|
281
283
|
warnOnce(`post effect '${h.name}' held off: ${w.why}`);
|
|
282
284
|
return w.why;
|
|
283
285
|
}
|
|
286
|
+
/**
|
|
287
|
+
* The device refused a pipeline of this material (render/shaderErrors.js). When one effect's own pass draws with it, that effect is held and the chain
|
|
288
|
+
* rebuilt without it: an invalid pipeline fails every frame it is drawn in, the whole frame with it. It stays held until it is removed and added again
|
|
289
|
+
* (a new handle), since the same shader on the same device fails the same way.
|
|
290
|
+
* @param {number} id material id @returns {string} what was done, '' when no effect owns the material @internal
|
|
291
|
+
*/
|
|
292
|
+
_pipelineFailed(id) {
|
|
293
|
+
const h = this._be.ownerOf?.(this, id);
|
|
294
|
+
if (!h) return '';
|
|
295
|
+
if (!h._failed) {
|
|
296
|
+
h._failed = 'the device refused its shader (the page error names it); held until it is removed and added again';
|
|
297
|
+
try { this._sync(); } catch (err) { reportError(this.engine, err, 'post chain', { soft: true }); } // from a device callback: nothing above to catch it
|
|
298
|
+
}
|
|
299
|
+
return coded('post-effect-failed', `it draws post effect '${h.name}', which is now held off so the rest of the frame draws (describe().render.post says so)`);
|
|
300
|
+
}
|
|
284
301
|
/**
|
|
285
302
|
* What antialiases the picture now: the samples really in effect, and the effect standing in for MSAA (asking for 'velocity' means a temporal resolve, so the scene pass runs without samples).
|
|
286
303
|
* @returns {{ samples: number, replacedBy: string | null }} @internal
|
package/render/backend.js
CHANGED
|
@@ -12,6 +12,7 @@ import { warnOnce } from '../core/base/validate.js';
|
|
|
12
12
|
import { notePatch, patchOn } from '../core/scene/threePatches.js';
|
|
13
13
|
import { isShown } from '../core/base/util.js';
|
|
14
14
|
import { checkVertexInputs } from './vertexInputs.js';
|
|
15
|
+
import { checkBindingLimits } from './bindingLimits.js';
|
|
15
16
|
|
|
16
17
|
/** Samples of the MSAA the post chain's targets use, on both renderers */
|
|
17
18
|
export const MSAA_SAMPLES = 4;
|
|
@@ -54,9 +55,9 @@ export const programList = r => isWebGPU(r) ? [] : r.info.programs ?? [];
|
|
|
54
55
|
// last render object built per material is kept (weakly: the material's lifetime) and its NodeBuilderState read on demand.
|
|
55
56
|
// RECENT: the last builds in order, also weak, so a compile error (which three reports without its render object) can be matched back to one.
|
|
56
57
|
const NODE_PROGRAMS = new WeakMap(), RECENT = [], RECENT_MAX = 256;
|
|
57
|
-
notePatch('node-builder-hook', "renderer.debug.onNodeBuilderCreated of a WebGPURenderer: remembers the render object built per material and counts each program's vertex inputs " +
|
|
58
|
+
notePatch('node-builder-hook', "renderer.debug.onNodeBuilderCreated of a WebGPURenderer: remembers the render object built per material and counts each program's vertex inputs, sampled textures and samplers " +
|
|
58
59
|
"before its code is written (that builder's buildCode), a game's own hook still runs (render/backend.js)", () => {},
|
|
59
|
-
{ scope: 'engine renderer', lost: "on WebGPU: shader errors no longer name the material, shaderCost and the program costs in inspect.perf stay empty, and a program over the device's vertex inputs fails with three's raw pipeline error" });
|
|
60
|
+
{ scope: 'engine renderer', lost: "on WebGPU: shader errors no longer name the material, shaderCost and the program costs in inspect.perf stay empty, and a program over the device's vertex inputs or texture bindings fails with three's raw pipeline error" });
|
|
60
61
|
/** @internal core/engine/Engine.js: on WebGPURenderer, remember the render object three builds per material (a game's own hook still runs) @param {any} r */
|
|
61
62
|
export function watchNodePrograms(r) {
|
|
62
63
|
const d = r?.debug;
|
|
@@ -67,7 +68,7 @@ export function watchNodePrograms(r) {
|
|
|
67
68
|
NODE_PROGRAMS.set(ro.material, ro); RECENT.push(new WeakRef(ro)); if (RECENT.length > RECENT_MAX) RECENT.shift();
|
|
68
69
|
const code = builder.buildCode;
|
|
69
70
|
// the material's own build only: three's plain stand-in after a failed build gets the same render object, and must not fail again
|
|
70
|
-
builder.buildCode = function () { if (this.material === ro.material) checkVertexInputs(this, r); return code.call(this); };
|
|
71
|
+
builder.buildCode = function () { if (this.material === ro.material) { checkVertexInputs(this, r); checkBindingLimits(this, r); } return code.call(this); };
|
|
71
72
|
}
|
|
72
73
|
prev?.(builder, ro);
|
|
73
74
|
};
|
|
@@ -531,13 +532,17 @@ export async function whyNoWebGPU(limits, powerPreference) {
|
|
|
531
532
|
let adapter;
|
|
532
533
|
try { adapter = await gpu.requestAdapter({ featureLevel: 'compatibility', powerPreference }); } catch (err) { return `requestAdapter() failed: ${err?.message ?? err}`; }
|
|
533
534
|
if (!adapter) return 'requestAdapter() returned no adapter';
|
|
534
|
-
//
|
|
535
|
-
if (limits) for (const k of
|
|
535
|
+
// WebGPU hands out its default limits unless a higher one is asked for, whatever the hardware can do; asking what this adapter supports costs nothing and lifts each where it can
|
|
536
|
+
if (limits) for (const k of ADAPTER_LIMITS) limits[k] ??= adapter.limits[k];
|
|
536
537
|
if (deviceFrom === gpu) return null;
|
|
537
538
|
try { (await adapter.requestDevice()).destroy?.(); } catch (err) { return `requestDevice() failed: ${err?.message ?? err}`; }
|
|
538
539
|
deviceFrom = gpu;
|
|
539
540
|
return null;
|
|
540
541
|
}
|
|
542
|
+
// The defaults a game's picture can pass, asked for at the adapter's own value in the one place the engine requests a device (a game's own renderer keeps the game's limits):
|
|
543
|
+
// the post chain's merged scene targets pass 32 bytes per pixel (render/fx/postWebGPU.tsl.js); a material with several texture layers, plus the lights' shadow maps, passes
|
|
544
|
+
// 16 textures and samplers per stage; voxelGI's triangle buffer (three's VXGIVolume, about 200 bytes a triangle) passes a 256 MB buffer and a 128 MB storage binding
|
|
545
|
+
const ADAPTER_LIMITS = ['maxColorAttachmentBytesPerSample', 'maxColorAttachments', 'maxSampledTexturesPerShaderStage', 'maxSamplersPerShaderStage', 'maxBufferSize', 'maxStorageBufferBindingSize'];
|
|
541
546
|
let deviceFrom = null; // the navigator.gpu that gave a device (a page's stand-in for it is another object, so it is asked again)
|
|
542
547
|
|
|
543
548
|
/** Each material on a scene object, once @param {any} scene @param {(m: any, o: any) => void} fn */
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// Sampled textures and samplers of a WebGPURenderer program, counted before three writes its code.
|
|
2
|
+
// A shader stage binds at most maxSampledTexturesPerShaderStage textures and maxSamplersPerShaderStage samplers (16 each on most devices). They stack up from
|
|
3
|
+
// parts that know nothing of each other: the material's own maps (a ground with 4 layers of color, normal and ARM plus a mask is 13), every shadow-casting
|
|
4
|
+
// light's shadow map, the environment map. Over the limit the device's only word is `Invalid PipelineLayout` / a bind group layout error that names no
|
|
5
|
+
// material. Counted where every node has asked for its bindings and no code exists yet (the builder's buildCode, as render/vertexInputs.js does): the throw
|
|
6
|
+
// lands in three's build-error path, which logs it and draws its plain stand-in instead. Real WebGPU only (the WebGL2 backend has no such limits here).
|
|
7
|
+
import { codedError } from '../core/base/errorHints.js';
|
|
8
|
+
|
|
9
|
+
const STAGES = ['vertex', 'fragment'];
|
|
10
|
+
/** @param {any} t a texture @returns {'shadow maps' | 'environment / cube maps' | 'other maps'} three has no flag for "this is the environment": a depth texture is a shadow
|
|
11
|
+
* map, a texture not mapped as plain UVs (cube, equirect, the PMREM of scene.environment) is an environment */
|
|
12
|
+
const kindOf = t => t?.isDepthTexture ? 'shadow maps' : t?.isCubeTexture || (t?.mapping ?? 300) !== 300 ? 'environment / cube maps' : 'other maps';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Per shader stage: the sampled textures and the samplers three bound for the program being built, and which textures are shadow maps / environment.
|
|
16
|
+
* three keeps them in builder.bindings[stage][group] (WGSLNodeBuilder.getUniformFromNode): a NodeSampledTexture (isSampledTexture; it extends Sampler, so
|
|
17
|
+
* isSampler is true for it too) and, beside each filterable one, a NodeSampler. Storage textures are no sampled textures (their own limit).
|
|
18
|
+
* @internal render/backend.js watchNodePrograms and tests/vertex-inputs @param {any} builder
|
|
19
|
+
* @returns {Record<string, { textures: number, samplers: number, kinds: Record<string, number> }>}
|
|
20
|
+
*/
|
|
21
|
+
export function bindingCounts(builder) {
|
|
22
|
+
/** @type {Record<string, { textures: number, samplers: number, kinds: Record<string, number> }>} */
|
|
23
|
+
const out = {};
|
|
24
|
+
for (const stage of STAGES) {
|
|
25
|
+
const c = out[stage] = { textures: 0, samplers: 0, kinds: {} };
|
|
26
|
+
for (const group of Object.values(builder.bindings?.[stage] ?? {})) for (const b of /** @type {any[]} */ (group)) {
|
|
27
|
+
if (b.isSampledTexture) {
|
|
28
|
+
if (b.store) continue;
|
|
29
|
+
c.textures++;
|
|
30
|
+
const k = kindOf(b.texture ?? b.textureNode?.value);
|
|
31
|
+
c.kinds[k] = (c.kinds[k] ?? 0) + 1;
|
|
32
|
+
} else if (b.isSampler) c.samplers++;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @internal render/backend.js watchNodePrograms, for every node program before its code is written.
|
|
40
|
+
* Throws, naming the material and what stacked up, when a stage binds more textures or samplers than the device allows (real WebGPU only) @param {any} builder @param {any} r
|
|
41
|
+
*/
|
|
42
|
+
export function checkBindingLimits(builder, r) {
|
|
43
|
+
const l = r.backend?.device?.limits;
|
|
44
|
+
if (!l) return;
|
|
45
|
+
const counts = bindingCounts(builder), over = [];
|
|
46
|
+
for (const stage of STAGES) {
|
|
47
|
+
const c = counts[stage];
|
|
48
|
+
for (const [what, n, max] of [['sampled textures', c.textures, l.maxSampledTexturesPerShaderStage], ['samplers', c.samplers, l.maxSamplersPerShaderStage]]) {
|
|
49
|
+
if (n <= max) continue;
|
|
50
|
+
const kinds = Object.entries(c.kinds).map(([k, v]) => `${v} ${k}`).join(', ');
|
|
51
|
+
over.push(`the ${stage} stage binds ${n} ${what}, this device takes ${max}${kinds ? ` (${kinds})` : ''}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (!over.length) return;
|
|
55
|
+
const m = builder.material, o = builder.object;
|
|
56
|
+
throw codedError('texture-bindings', `[threedog] ${m?.type}${m?.name ? ` '${m.name}'` : ''} (#${m?.id}) on ${o?.type ?? 'object'} '${o?.name || '(unnamed)'}': ${over.join('; ')}. `
|
|
57
|
+
+ 'To fit: fewer texture layers, pack maps into one texture\'s channels (roughness / ao / metalness in one ARM texture), fewer shadow-casting lights (castShadow = false), '
|
|
58
|
+
+ 'or drop the environment map on this material.');
|
|
59
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// A depth-compare sample that takes no screen derivative, on WebGPURenderer.
|
|
2
|
+
// three r187's WGSL builder writes every compare sample as textureSampleCompare, which takes screen derivatives to choose a mip level. A depth texture the
|
|
3
|
+
// renderer compares against (a shadow map) has one level, so the derivative chooses nothing; and WGSL only allows that call in uniform control flow, a rule three
|
|
4
|
+
// switches off for the whole shader ('diagnostic( off, derivative_uniformity )'). Tint then lets it through, and D3D's FXC refuses it inside a loop it cannot
|
|
5
|
+
// unroll: three's GodraysNode marches the shadow map in a loop whose count comes from a uniform, so sunShafts failed with 'FXC compile failed with error: E_FAIL'
|
|
6
|
+
// and every frame after it was invalid. textureSampleCompareLevel takes the same arguments, samples level 0, and is valid in any control flow: the same
|
|
7
|
+
// picture for a one-level texture. A compare texture that does carry mipmaps keeps three's call.
|
|
8
|
+
import { WGSLNodeBuilder } from 'three/webgpu';
|
|
9
|
+
import { notePatch, patchOn } from '../../core/scene/threePatches.js';
|
|
10
|
+
|
|
11
|
+
// @types/three does not declare the builder's generate methods
|
|
12
|
+
const ID = 'compare-sample-level', proto = /** @type {any} */ (WGSLNodeBuilder.prototype), generateTextureCompare = proto.generateTextureCompare;
|
|
13
|
+
/** @param {any} texture */
|
|
14
|
+
const oneLevel = texture => texture.generateMipmaps !== true && !(texture.mipmaps?.length > 1);
|
|
15
|
+
if (!generateTextureCompare._threedogLevel) { // already wrapped (module loaded twice)
|
|
16
|
+
proto.generateTextureCompare = Object.assign(/** @this {any} @param {any} texture @param {any[]} rest */ function (texture, ...rest) {
|
|
17
|
+
const snippet = generateTextureCompare.call(this, texture, ...rest);
|
|
18
|
+
return patchOn(ID) && oneLevel(texture) && typeof snippet === 'string' ? snippet.replace('textureSampleCompare(', 'textureSampleCompareLevel(') : snippet;
|
|
19
|
+
}, { _threedogLevel: true });
|
|
20
|
+
notePatch(ID, "WGSLNodeBuilder.prototype.generateTextureCompare: a compare sample of a one-level depth texture (every shadow map) is written as textureSampleCompareLevel, which needs no screen derivative",
|
|
21
|
+
() => { proto.generateTextureCompare = generateTextureCompare; },
|
|
22
|
+
{ lost: "on a D3D backend that compiles with FXC, a shader that compares a shadow map inside a loop of varying length (sunShafts) no longer compiles, and every frame that draws it is invalid" });
|
|
23
|
+
}
|
package/render/fx/index.js
CHANGED
|
@@ -8,6 +8,8 @@ export { uniforms } from './uniforms.tsl.js';
|
|
|
8
8
|
export { lightShaft } from './lightShaft.tsl.js';
|
|
9
9
|
// Registers what a patch's `tsl` field does on a NodeMaterial (render/patches.js looks it up; nothing to call)
|
|
10
10
|
import './patchNodes.tsl.js';
|
|
11
|
+
// Depth-compare samples without a screen derivative, so a shadow map can be compared inside a loop (three's GodraysNode) on every backend
|
|
12
|
+
import './compareLevel.tsl.js';
|
|
11
13
|
// Registers the node versions of the particle / weather shaders (modules/particles and modules/weather drawing them up on WebGPURenderer)
|
|
12
14
|
import './particles.tsl.js';
|
|
13
15
|
// Registers the WebGPU post chain (render/PostFX.js looks it up when the renderer is a WebGPURenderer; nothing to call)
|
|
@@ -197,6 +197,21 @@ const webgpuPost = {
|
|
|
197
197
|
P.pipeline.outputNode = color; P.pipeline.needsUpdate = true;
|
|
198
198
|
P.output = color; P.order = order; P.key = key;
|
|
199
199
|
},
|
|
200
|
+
/**
|
|
201
|
+
* The effect whose own pass draws with this material, or null: a display node keeps its fullscreen materials as plain fields (three's GTAO, bloom,
|
|
202
|
+
* godrays, SSR ...). Stages in chain order, each read through the node it handed back: an effect's output contains the stages before it, so the
|
|
203
|
+
* first stage that has the material owns it. An effect that is only an expression is compiled into the next pass with its neighbors and owns none.
|
|
204
|
+
*/
|
|
205
|
+
ownerOf(post, id) {
|
|
206
|
+
const is = m => m?.isMaterial && m.id === id, has = n => Object.values(n).some(v => (Array.isArray(v) ? v.some(is) : is(v)));
|
|
207
|
+
for (const s of post._pipe?.stages ?? []) {
|
|
208
|
+
if (typeof s.e === 'string') continue;
|
|
209
|
+
let found = !!s.impl?.nodes.some(has);
|
|
210
|
+
if (!found) s.out?.traverse?.(n => { found ||= has(n); });
|
|
211
|
+
if (found) return s.e;
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
},
|
|
200
215
|
dispose(post) {
|
|
201
216
|
if (post._pipeOut) { post._pipeOut.scenePass.dispose(); post._pipeOut.pipeline.dispose(); post._pipeOut = null; }
|
|
202
217
|
const P = post._pipe;
|
package/render/shaderErrors.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { setConsoleFunction, getConsoleFunction } from 'three';
|
|
8
8
|
import { isWebGPU, findNodeBuild } from './backend.js';
|
|
9
9
|
import { materialPatches } from './patches.js';
|
|
10
|
+
import { notePatch, patchOn } from '../core/scene/threePatches.js';
|
|
10
11
|
|
|
11
12
|
const BEGIN = /^\s*\/\/ threedog:begin patch=(\S+) slot=(\S+)/, END = /^\s*\/\/ threedog:end/;
|
|
12
13
|
// a GLSL file served by the vite preset's threedog-live plugin (shader hot reload, render/hotGlsl.js): `// threedog:begin file=<path>`
|
|
@@ -63,10 +64,11 @@ function stageLogs(gl, vs, fs) {
|
|
|
63
64
|
* Hook renderer.debug.onShaderError (when nothing else holds it) so compile errors name the patch and slot.
|
|
64
65
|
* @internal core/engine/Engine.js
|
|
65
66
|
* @param {import('three').WebGLRenderer} renderer
|
|
67
|
+
* @param {(materialId: number) => string} [onFail] WebGPU: called when the device refused a pipeline of that material; returns what was done about it ('' = nothing)
|
|
66
68
|
*/
|
|
67
|
-
export function nameShaderErrors(renderer) {
|
|
69
|
+
export function nameShaderErrors(renderer, onFail) {
|
|
68
70
|
const d = /** @type {any} */ (renderer).debug;
|
|
69
|
-
if (isWebGPU(renderer)) { nameNodeErrors(renderer); return; }
|
|
71
|
+
if (isWebGPU(renderer)) { if (onFail) ON_FAIL.set(renderer, onFail); nameNodeErrors(renderer); return; }
|
|
70
72
|
if (!d || d.onShaderError) return;
|
|
71
73
|
d.onShaderError = (gl, program, vs, fs) => {
|
|
72
74
|
const parts = [];
|
|
@@ -103,10 +105,44 @@ function nodeOwner(ro) {
|
|
|
103
105
|
* @returns {string}
|
|
104
106
|
*/
|
|
105
107
|
function explainPipelineError(message) {
|
|
106
|
-
const m = /
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
const m = /[Rr]ender pipeline creation failed \(renderPipeline_.*_(\d+)\)/.exec(message); // 'Async render pipeline ...' from compileAsync too
|
|
109
|
+
return m ? `${pipelineFailed(+m[1])} three's WGSL lines follow.` : '';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// renderer -> what the engine does about a pipeline that failed for one material (core/engine/Engine.js gives it): the post chain holds the effect
|
|
113
|
+
// that draws with it. Why here: the device reports a failed pipeline by its label only, and this file is where a label becomes a material and its owner.
|
|
114
|
+
const ON_FAIL = new WeakMap();
|
|
115
|
+
/** "[threedog] WebGPU pipeline failed for <owner>: <what the engine did about it, or how to find the cause>." @param {number} id material id @param {any} [r] the renderer, when the report came with one */
|
|
116
|
+
function pipelineFailed(id, r) {
|
|
117
|
+
const ro = findNodeBuild(x => x.material?.id === id), did = ON_FAIL.get(r ?? ro?.renderer)?.(id);
|
|
118
|
+
return `[threedog] WebGPU pipeline failed for ${ro ? nodeOwner(ro) : `material #${id} (not among the recent builds)`}: ${did || NODE_HINT}.`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// What three's own scope misses: it wraps pipeline creation in a 'validation' error scope, and a shader the driver's compiler refuses (FXC on D3D)
|
|
122
|
+
// is a GPUInternalError, no validation error. The pipeline stays invalid, three keeps drawing with it, and every frame that does is lost. So the
|
|
123
|
+
// device's createRenderPipeline gets an 'internal' scope of its own: the failure then arrives with the pipeline's label, whatever words the browser
|
|
124
|
+
// uses for it. three's async path (compileAsync) reports such a failure itself, through the console line explainPipelineError reads.
|
|
125
|
+
notePatch('pipeline-internal-scope', "createRenderPipeline of the WebGPURenderer's GPUDevice: an 'internal' error scope around three's call, so a pipeline the driver's compiler refuses is named with its material, and a post effect that owns it is held", () => {},
|
|
126
|
+
{ scope: 'engine renderer', lost: 'a pipeline the driver refuses keeps failing every frame with no name, and its post effect stays on' });
|
|
127
|
+
const scoped = new WeakSet();
|
|
128
|
+
/** @internal core/engine/startup.js, once the renderer has its device @param {any} r a WebGPURenderer */
|
|
129
|
+
export function watchPipelineBuilds(r) {
|
|
130
|
+
const device = r?.backend?.device;
|
|
131
|
+
if (!device?.pushErrorScope || scoped.has(device)) return;
|
|
132
|
+
scoped.add(device);
|
|
133
|
+
const create = device.createRenderPipeline;
|
|
134
|
+
device.createRenderPipeline = function (desc) {
|
|
135
|
+
if (!patchOn('pipeline-internal-scope')) return create.call(this, desc);
|
|
136
|
+
const label = String(desc?.label ?? ''); // read now: three reuses one descriptor object and resets it after the call
|
|
137
|
+
this.pushErrorScope('internal');
|
|
138
|
+
try { return create.call(this, desc); }
|
|
139
|
+
finally {
|
|
140
|
+
this.popErrorScope().then(err => {
|
|
141
|
+
const m = err && /^renderPipeline_.*_(\d+)$/.exec(label);
|
|
142
|
+
if (m) console.error(`${pipelineFailed(+m[1], r)} The device said: ${err.message}`);
|
|
143
|
+
}, () => { /* the device was lost: its own report covers it */ });
|
|
144
|
+
}
|
|
145
|
+
};
|
|
110
146
|
}
|
|
111
147
|
|
|
112
148
|
/** The explanation for three's node build-error log ('THREE.TSL: TypeError: ...', NodeManager), or '' (another message) @param {string} message */
|
package/types/core.d.ts
CHANGED
|
@@ -1667,7 +1667,7 @@ export interface View {
|
|
|
1667
1667
|
* warning). 'camera' hands the pose back after a direct write (take it with engine.takeCamera(owner)). Pass false to hand back; remove() does the same.
|
|
1668
1668
|
* @example const mine = engine.autoView.manual('far'); engine.camera.far = 5000; mine.remove();
|
|
1669
1669
|
*/
|
|
1670
|
-
manual(key: 'far' | 'fov' | 'pixelRatio' | 'camera', on?: boolean): { remove(): void };
|
|
1670
|
+
manual(key: 'far' | 'fov' | 'aspect' | 'pixelRatio' | 'sunDir' | 'camera', on?: boolean): { remove(): void };
|
|
1671
1671
|
}
|
|
1672
1672
|
/** engine.shadows.cache options: an Object3D (its whole subtree), a list of them, or a test on each mesh (recipes/45) */
|
|
1673
1673
|
export interface ShadowCacheOptions { static: import('three').Object3D | import('three').Object3D[] | ((mesh: import('three').Object3D) => boolean); }
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
// Generated by npm run map, do not edit by hand. Source: packages/engine/core/scene/Views.js (edit the JSDoc in the source, then run npm run map)
|
|
2
2
|
export class Views {
|
|
3
|
+
/**
|
|
4
|
+
* A pose written as text, 'x,y,z,targetX,targetY,targetZ[,fov]' (meters, fov in degrees): the form a URL's ?view= and `threedog state view=` carry. null when the text is not one
|
|
5
|
+
* @param {string} text @returns {{ position: number[], target: number[], fov?: number } | null}
|
|
6
|
+
*/
|
|
7
|
+
static pose(text: string): {
|
|
8
|
+
position: number[];
|
|
9
|
+
target: number[];
|
|
10
|
+
fov?: number;
|
|
11
|
+
} | null;
|
|
3
12
|
/** @param {any} engine */
|
|
4
13
|
constructor(engine: any);
|
|
5
14
|
map: Map<any, any>;
|
|
@@ -21,10 +30,15 @@ export class Views {
|
|
|
21
30
|
/** @returns {string[]} the declared view names */
|
|
22
31
|
list(): string[];
|
|
23
32
|
/**
|
|
24
|
-
* Put the camera on a view and keep it there (the camera rigs leave it alone) until release() or the returned handle's remove(); null for an unknown name
|
|
25
|
-
*
|
|
33
|
+
* Put the camera on a view and keep it there (the camera rigs leave it alone) until release() or the returned handle's remove(); null for an unknown name.
|
|
34
|
+
* A pose { position, target?, fov? } in place of a name shows that pose without declaring it (current reads '(pose)')
|
|
35
|
+
* @param {string | { position: number[], target?: number[], fov?: number }} view @returns {{ remove(): void } | null}
|
|
26
36
|
*/
|
|
27
|
-
show(
|
|
37
|
+
show(view: string | {
|
|
38
|
+
position: number[];
|
|
39
|
+
target?: number[];
|
|
40
|
+
fov?: number;
|
|
41
|
+
}): {
|
|
28
42
|
remove(): void;
|
|
29
43
|
} | null;
|
|
30
44
|
/** Give the camera back (to the previous holder, e.g. a running cutscene, or to the rig) */
|