@ignifx/core 0.21.0 → 0.22.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/README.md +22 -0
- package/dist/{agx-tone-mapping-Cgt844j6.js → agx-tone-mapping-CCdGk_ly.js} +2 -2
- package/dist/agx-tone-mapping-CCdGk_ly.js.map +1 -0
- package/dist/auto-exposure-uzPn0beO.js.map +1 -1
- package/dist/{bloom-hdr-CLtQj-oY.js → bloom-hdr-xPwkIdHG.js} +5 -6
- package/dist/bloom-hdr-xPwkIdHG.js.map +1 -0
- package/dist/contact-shadows-T523EXaP.js.map +1 -1
- package/dist/effect-task-CMbuO6Kb.js.map +1 -1
- package/dist/{environment-Bf4aphSb.js → environment-7fJbN402.js} +2 -2
- package/dist/{environment-Bf4aphSb.js.map → environment-7fJbN402.js.map} +1 -1
- package/dist/{gtao-Bpu5-0Ne.js → gtao-CVAYWBEJ.js} +10 -11
- package/dist/gtao-CVAYWBEJ.js.map +1 -0
- package/dist/{hdr-output-DBQwMphy.js → hdr-output-_2TU-jWy.js} +8 -8
- package/dist/hdr-output-_2TU-jWy.js.map +1 -0
- package/dist/index.d.ts +61 -48
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +148 -129
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-B-fXKSrY.js → instanced-mesh-instance-BLdAJTj8.js} +3 -3
- package/dist/instanced-mesh-instance-BLdAJTj8.js.map +1 -0
- package/dist/{light-probe-asset-BqfSrJe9.js → light-probe-asset-DGNIwKNb.js} +2 -2
- package/dist/light-probe-asset-DGNIwKNb.js.map +1 -0
- package/dist/{light-probes-DDojYajw.js → light-probes-C8jharz9.js} +6 -6
- package/dist/light-probes-C8jharz9.js.map +1 -0
- package/dist/lightmaps-BUUIIkt9.js.map +1 -1
- package/dist/material-myMbl9mW.js.map +1 -1
- package/dist/{material-plugin-DapJNj04.js → material-plugin-BBxIy6eo.js} +4 -4
- package/dist/material-plugin-BBxIy6eo.js.map +1 -0
- package/dist/{overlay-CjVgsfrm.js → overlay-DokHzP6_.js} +2 -3
- package/dist/overlay-DokHzP6_.js.map +1 -0
- package/dist/{post-effect-Cu3Enpz7.js → post-effect-DEZD-r0I.js} +3 -3
- package/dist/post-effect-DEZD-r0I.js.map +1 -0
- package/dist/{post-effect-compiler-cCq9lcHt.js → post-effect-compiler-unDD3hod.js} +4 -4
- package/dist/post-effect-compiler-unDD3hod.js.map +1 -0
- package/dist/{prefab-overrides-C2GsgOQc.js → prefab-overrides-Bb7jVm7A.js} +3 -3
- package/dist/prefab-overrides-Bb7jVm7A.js.map +1 -0
- package/dist/{prefab-overrides-htDc_5Po.d.ts → prefab-overrides-CkwXhp5A.d.ts} +84 -64
- package/dist/{prefab-overrides-htDc_5Po.d.ts.map → prefab-overrides-CkwXhp5A.d.ts.map} +1 -1
- package/dist/prefab.d.ts +1 -1
- package/dist/prefab.js +1 -1
- package/dist/{reflection-probe-QkD1Fo_d.js → reflection-probe-C2jcreI1.js} +5 -5
- package/dist/reflection-probe-C2jcreI1.js.map +1 -0
- package/dist/{reflection-probes-CAzSuqf8.js → reflection-probes-BMVQfbhm.js} +10 -10
- package/dist/reflection-probes-BMVQfbhm.js.map +1 -0
- package/dist/{render-path-D11i_7X8.js → render-path-CWXHrRa2.js} +2 -2
- package/dist/render-path-CWXHrRa2.js.map +1 -0
- package/dist/scene-color-passes-CM_T2KF-.js +177 -0
- package/dist/scene-color-passes-CM_T2KF-.js.map +1 -0
- package/dist/scene-inputs-CbTkrkOw.js +489 -0
- package/dist/scene-inputs-CbTkrkOw.js.map +1 -0
- package/dist/{shader-declaration-5q__jycG.js → shader-declaration-BGprFBLq.js} +4 -4
- package/dist/shader-declaration-BGprFBLq.js.map +1 -0
- package/dist/{shader-material-TM4f8eKA.js → shader-material-C9sYMGWw.js} +8 -9
- package/dist/shader-material-C9sYMGWw.js.map +1 -0
- package/dist/{shader-material-CJIDFvSb.js → shader-material-vmkJ25II.js} +3 -3
- package/dist/shader-material-vmkJ25II.js.map +1 -0
- package/dist/{shader-pragma-ljmAbVc2.js → shader-pragma-D0MjCOIg.js} +3 -3
- package/dist/shader-pragma-D0MjCOIg.js.map +1 -0
- package/dist/ssgi-Dk20U3oR.js +492 -0
- package/dist/ssgi-Dk20U3oR.js.map +1 -0
- package/dist/{surface-shader-rpPpeosD.js → surface-shader-BfADq9Wx.js} +6 -6
- package/dist/surface-shader-BfADq9Wx.js.map +1 -0
- package/dist/{taa-BwBZLy11.js → taa-nxVA78Ur.js} +5 -6
- package/dist/taa-nxVA78Ur.js.map +1 -0
- package/dist/vec3-2C3LBZnt.js.map +1 -1
- package/package.json +1 -1
- package/dist/agx-tone-mapping-Cgt844j6.js.map +0 -1
- package/dist/bloom-hdr-CLtQj-oY.js.map +0 -1
- package/dist/gtao-Bpu5-0Ne.js.map +0 -1
- package/dist/hdr-output-DBQwMphy.js.map +0 -1
- package/dist/instanced-mesh-instance-B-fXKSrY.js.map +0 -1
- package/dist/light-probe-asset-BqfSrJe9.js.map +0 -1
- package/dist/light-probes-DDojYajw.js.map +0 -1
- package/dist/material-plugin-DapJNj04.js.map +0 -1
- package/dist/overlay-CjVgsfrm.js.map +0 -1
- package/dist/post-effect-Cu3Enpz7.js.map +0 -1
- package/dist/post-effect-compiler-cCq9lcHt.js.map +0 -1
- package/dist/prefab-overrides-C2GsgOQc.js.map +0 -1
- package/dist/reflection-probe-QkD1Fo_d.js.map +0 -1
- package/dist/reflection-probes-CAzSuqf8.js.map +0 -1
- package/dist/render-path-D11i_7X8.js.map +0 -1
- package/dist/scene-color-passes-B93qTOka.js +0 -88
- package/dist/scene-color-passes-B93qTOka.js.map +0 -1
- package/dist/scene-inputs-BxGOsnIZ.js +0 -318
- package/dist/scene-inputs-BxGOsnIZ.js.map +0 -1
- package/dist/shader-declaration-5q__jycG.js.map +0 -1
- package/dist/shader-material-CJIDFvSb.js.map +0 -1
- package/dist/shader-material-TM4f8eKA.js.map +0 -1
- package/dist/shader-pragma-ljmAbVc2.js.map +0 -1
- package/dist/ssgi-DSnhqotl.js +0 -113
- package/dist/ssgi-DSnhqotl.js.map +0 -1
- package/dist/surface-shader-rpPpeosD.js.map +0 -1
- package/dist/taa-BwBZLy11.js.map +0 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { frameGraphTasks } from "./scene-inputs-CbTkrkOw.js";
|
|
2
|
+
import { addTaskAfter, buildFrameGraphTask, createCopyToTextureTask, createSurfaceRenderTargetTexture, disposeRenderTargetTexture, getFrameGraph } from "@babylonjs/lite";
|
|
3
|
+
//#region src/lite/gpu/scene-color-passes.ts
|
|
4
|
+
/**
|
|
5
|
+
* Inserts the passes after the scene task, in order.
|
|
6
|
+
*
|
|
7
|
+
* @param engine - The engine; also the surface the scratch target is sized by.
|
|
8
|
+
* @param scene - The scene.
|
|
9
|
+
* @param presenter - The offscreen render path.
|
|
10
|
+
* @param passes - The effects, first to last.
|
|
11
|
+
* @param isFrameGraphBuilt - Whether the scene is registered, so each task is recorded now.
|
|
12
|
+
* @returns The handle that takes them out again.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
function installSceneColorPasses(engine, scene, presenter, passes, isFrameGraphBuilt) {
|
|
17
|
+
const { task: sceneTask, target: sceneTarget, format, isTargetWritable } = presenter.scenePass;
|
|
18
|
+
const scratches = [];
|
|
19
|
+
const scratchTextures = [];
|
|
20
|
+
const createScratch = (index) => {
|
|
21
|
+
const scratch = createSurfaceRenderTargetTexture(engine, {
|
|
22
|
+
lbl: index === 0 ? "ignifx:scene-color-scratch" : "ignifx:scene-color-scratch-2",
|
|
23
|
+
format,
|
|
24
|
+
samples: 1,
|
|
25
|
+
size: engine
|
|
26
|
+
});
|
|
27
|
+
scratchTextures.push(scratch);
|
|
28
|
+
return scratch.rt;
|
|
29
|
+
};
|
|
30
|
+
const steps = planSceneColorPasses(passes.map((pass) => pass.inPlace === true), sceneTarget, isTargetWritable, scratches, createScratch);
|
|
31
|
+
const tasks = [];
|
|
32
|
+
const free = () => {
|
|
33
|
+
const list = frameGraphTasks(scene);
|
|
34
|
+
for (const task of tasks) {
|
|
35
|
+
task.executionEnabled = false;
|
|
36
|
+
const index = list?.indexOf(task) ?? -1;
|
|
37
|
+
if (list !== null && index >= 0) list.splice(index, 1);
|
|
38
|
+
task.dispose();
|
|
39
|
+
}
|
|
40
|
+
for (const scratch of scratchTextures) disposeRenderTargetTexture(scratch);
|
|
41
|
+
};
|
|
42
|
+
try {
|
|
43
|
+
for (const step of steps) {
|
|
44
|
+
const pass = step.pass === null ? void 0 : passes[step.pass];
|
|
45
|
+
if (pass === void 0) {
|
|
46
|
+
tasks.push(createCopyToTextureTask({
|
|
47
|
+
name: step.target === sceneTarget ? "ignifx:scene-color-copy" : "ignifx:scene-color-stage",
|
|
48
|
+
sourceTexture: step.source,
|
|
49
|
+
targetTexture: step.target
|
|
50
|
+
}, engine, scene));
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
appendTasks(tasks, pass.create(step.source, step.target));
|
|
54
|
+
}
|
|
55
|
+
let after = sceneTask;
|
|
56
|
+
for (const task of tasks) {
|
|
57
|
+
addTaskAfter(scene, task, after);
|
|
58
|
+
after = task;
|
|
59
|
+
}
|
|
60
|
+
if (isFrameGraphBuilt) {
|
|
61
|
+
const graph = getFrameGraph(scene);
|
|
62
|
+
for (const task of tasks) buildFrameGraphTask(graph, task);
|
|
63
|
+
}
|
|
64
|
+
} catch (failure) {
|
|
65
|
+
free();
|
|
66
|
+
throw failure;
|
|
67
|
+
}
|
|
68
|
+
let isDisposed = false;
|
|
69
|
+
return {
|
|
70
|
+
taskCount: tasks.length,
|
|
71
|
+
dispose() {
|
|
72
|
+
if (isDisposed) return;
|
|
73
|
+
isDisposed = true;
|
|
74
|
+
free();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Plans the steps that take the scene colour through every pass and back into the scene target.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* A pass that writes a second target goes where {@link sceneColorPassTarget} says. An in-place pass
|
|
83
|
+
* gets the colour it reads as its target; when that is a scene target no pass may write, a copy
|
|
84
|
+
* moves the colour into a scratch first. A last copy brings the result back when it is not already
|
|
85
|
+
* in the scene target.
|
|
86
|
+
*
|
|
87
|
+
* @param inPlace - For each pass, whether it is {@link SceneColorPass.inPlace}.
|
|
88
|
+
* @param sceneTarget - The scene's colour target.
|
|
89
|
+
* @param isTargetWritable - Whether a pass may write `sceneTarget` (`ScenePass.isTargetWritable` in `./render-path.ts`).
|
|
90
|
+
* @param scratches - The scratch targets made so far; new ones are appended as needed.
|
|
91
|
+
* @param createScratch - Makes the scratch target at an index, 0 or 1.
|
|
92
|
+
* @returns The steps, in the order they run.
|
|
93
|
+
*
|
|
94
|
+
* @internal
|
|
95
|
+
*/
|
|
96
|
+
function planSceneColorPasses(inPlace, sceneTarget, isTargetWritable, scratches, createScratch) {
|
|
97
|
+
const steps = [];
|
|
98
|
+
let source = sceneTarget;
|
|
99
|
+
for (let pass = 0; pass < inPlace.length; pass += 1) {
|
|
100
|
+
if (inPlace[pass] === true) {
|
|
101
|
+
if (source === sceneTarget && !isTargetWritable) {
|
|
102
|
+
const staged = sceneColorPassTarget(source, sceneTarget, isTargetWritable, scratches, createScratch);
|
|
103
|
+
steps.push({
|
|
104
|
+
pass: null,
|
|
105
|
+
source,
|
|
106
|
+
target: staged
|
|
107
|
+
});
|
|
108
|
+
source = staged;
|
|
109
|
+
}
|
|
110
|
+
steps.push({
|
|
111
|
+
pass,
|
|
112
|
+
source,
|
|
113
|
+
target: source
|
|
114
|
+
});
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const target = sceneColorPassTarget(source, sceneTarget, isTargetWritable, scratches, createScratch);
|
|
118
|
+
steps.push({
|
|
119
|
+
pass,
|
|
120
|
+
source,
|
|
121
|
+
target
|
|
122
|
+
});
|
|
123
|
+
source = target;
|
|
124
|
+
}
|
|
125
|
+
if (source !== sceneTarget) steps.push({
|
|
126
|
+
pass: null,
|
|
127
|
+
source,
|
|
128
|
+
target: sceneTarget
|
|
129
|
+
});
|
|
130
|
+
return steps;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Appends what a pass created to the task list.
|
|
134
|
+
*
|
|
135
|
+
* @param tasks - The list.
|
|
136
|
+
* @param created - One task or several.
|
|
137
|
+
*/
|
|
138
|
+
function appendTasks(tasks, created) {
|
|
139
|
+
if (isTaskList(created)) tasks.push(...created);
|
|
140
|
+
else tasks.push(created);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Whether a pass returned several tasks.
|
|
144
|
+
*
|
|
145
|
+
* @param created - What `create` returned.
|
|
146
|
+
* @returns `true` for a list.
|
|
147
|
+
*/
|
|
148
|
+
function isTaskList(created) {
|
|
149
|
+
return Array.isArray(created);
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Picks where the next scene-colour pass writes: back into the scene target when that is allowed
|
|
153
|
+
* and the pass does not read it, otherwise the scratch target the pass does not read.
|
|
154
|
+
*
|
|
155
|
+
* @param source - What the pass reads.
|
|
156
|
+
* @param sceneTarget - The scene's colour target.
|
|
157
|
+
* @param isTargetWritable - Whether a pass may write `sceneTarget` (`ScenePass.isTargetWritable` in `./render-path.ts`).
|
|
158
|
+
* @param scratches - The scratch targets made so far; a new one is appended when needed.
|
|
159
|
+
* @param createScratch - Makes the scratch target at an index, 0 or 1.
|
|
160
|
+
* @returns The target, never `source`.
|
|
161
|
+
*
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
function sceneColorPassTarget(source, sceneTarget, isTargetWritable, scratches, createScratch) {
|
|
165
|
+
if (source !== sceneTarget && isTargetWritable) return sceneTarget;
|
|
166
|
+
const index = source === scratches[0] ? 1 : 0;
|
|
167
|
+
let scratch = scratches[index];
|
|
168
|
+
if (scratch === void 0) {
|
|
169
|
+
scratch = createScratch(index);
|
|
170
|
+
scratches[index] = scratch;
|
|
171
|
+
}
|
|
172
|
+
return scratch;
|
|
173
|
+
}
|
|
174
|
+
//#endregion
|
|
175
|
+
export { installSceneColorPasses, planSceneColorPasses, sceneColorPassTarget };
|
|
176
|
+
|
|
177
|
+
//# sourceMappingURL=scene-color-passes-CM_T2KF-.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scene-color-passes-CM_T2KF-.js","names":[],"sources":["../src/lite/gpu/scene-color-passes.ts"],"sourcesContent":["import {\n addTaskAfter,\n buildFrameGraphTask,\n createCopyToTextureTask,\n createSurfaceRenderTargetTexture,\n disposeRenderTargetTexture,\n getFrameGraph,\n} from \"@babylonjs/lite\";\nimport { frameGraphTasks } from \"./scene-inputs.js\";\nimport type { ScenePresenter } from \"./render-path.js\";\nimport type { EngineContext, RenderTarget, RenderTargetTextureResult, SceneContext, Task } from \"@babylonjs/lite\";\n\n/**\n * Scene-colour passes (`docs/architecture/07-rendering.md` §2.7): Lite screen-space effects that\n * read the lit scene colour and the shared scene-input depth, and whose result replaces the scene\n * colour before anything else reads it. Its own chunk, loaded with the first such effect\n * (`CONSTITUTION.md` §2.5).\n *\n * ```text\n * scene ─→ S ─ pass 1 ─→ scratch ─ pass 2 ─→ S ─ … [─ copy ─→ S] ─→ present / output pass / chain\n * ```\n *\n * `S` is the presenter's {@link ScenePresenter.scenePass} target: `sceneColor` on the plain path,\n * the linear `rgba16float` target under `rendering.hdr`, so the passes see linear colour ahead of\n * the output pass there. Lite's composite cannot write its own source, so under HDR the passes\n * ping-pong between `S` and one scratch target of the same format, and a copy brings an odd count\n * back into `S`. On the plain path no pass may write `S` (`ScenePass.isTargetWritable` in `./render-path.ts`): the\n * passes ping-pong between two scratch targets and the copy always runs. Every task sits right after\n * the scene task, ahead of the present blit, the HDR output pass and a `PostProcessStack` chain\n * alike, which therefore need no change.\n *\n * A pass may instead add to the colour it reads through the blend unit\n * ({@link SceneColorPass.inPlace}, SSGI): it gets one target as both. Under HDR that is `S` itself,\n * or the scratch an earlier pass wrote. On the plain path, where `S` cannot be written, a copy\n * stages `S` into a scratch first:\n *\n * ```text\n * scene ─→ S ─ copy ─→ scratch ─ in-place pass ─→ scratch ─ copy ─→ S\n * ```\n *\n * The scratch targets are eager surface targets (`createSurfaceRenderTargetTexture`), the kind the\n * HDR target is: a task that writes one in `record()` does not reallocate it, so several tasks can\n * write the same scratch, and a resize is followed by the frame graph's rebuild.\n */\n\n/**\n * One scene-colour effect, as the installer sees it.\n *\n * @internal\n */\nexport interface SceneColorPass {\n /**\n * `true` for a pass that blends its result onto the colour it reads instead of writing a second\n * target. Its {@link SceneColorPass.create} is then called with the same target twice, one an\n * effect task may write.\n */\n readonly inPlace?: boolean;\n /**\n * Creates the effect's tasks.\n *\n * @param source - The colour it reads.\n * @param target - The colour it writes: never `source`, unless the pass is\n * {@link SceneColorPass.inPlace}, when it is `source`.\n * @returns The task, or the tasks in the order they run.\n */\n create(source: RenderTarget, target: RenderTarget): Task | readonly Task[];\n}\n\n/**\n * The installed passes.\n *\n * @internal\n */\nexport interface InstalledSceneColorPasses {\n /** How many tasks were added, copy included. */\n readonly taskCount: number;\n /** Removes and disposes every task and the scratch target. Idempotent. */\n dispose(): void;\n}\n\n/**\n * Inserts the passes after the scene task, in order.\n *\n * @param engine - The engine; also the surface the scratch target is sized by.\n * @param scene - The scene.\n * @param presenter - The offscreen render path.\n * @param passes - The effects, first to last.\n * @param isFrameGraphBuilt - Whether the scene is registered, so each task is recorded now.\n * @returns The handle that takes them out again.\n *\n * @internal\n */\nexport function installSceneColorPasses(\n engine: EngineContext,\n scene: SceneContext,\n presenter: ScenePresenter,\n passes: readonly SceneColorPass[],\n isFrameGraphBuilt: boolean,\n): InstalledSceneColorPasses {\n const { task: sceneTask, target: sceneTarget, format, isTargetWritable } = presenter.scenePass;\n const scratches: RenderTarget[] = [];\n const scratchTextures: RenderTargetTextureResult[] = [];\n const createScratch = (index: number): RenderTarget => {\n const scratch = createSurfaceRenderTargetTexture(engine, {\n lbl: index === 0 ? \"ignifx:scene-color-scratch\" : \"ignifx:scene-color-scratch-2\",\n format,\n samples: 1,\n size: engine,\n });\n scratchTextures.push(scratch);\n return scratch.rt;\n };\n const steps = planSceneColorPasses(\n passes.map((pass) => pass.inPlace === true),\n sceneTarget,\n isTargetWritable,\n scratches,\n createScratch,\n );\n const tasks: Task[] = [];\n const free = (): void => {\n const list = frameGraphTasks(scene);\n for (const task of tasks) {\n // Disable first: a disposed task that still executes is a use-after-free.\n task.executionEnabled = false;\n const index = list?.indexOf(task) ?? -1;\n if (list !== null && index >= 0) {\n list.splice(index, 1);\n }\n task.dispose();\n }\n for (const scratch of scratchTextures) {\n disposeRenderTargetTexture(scratch);\n }\n };\n try {\n for (const step of steps) {\n const pass = step.pass === null ? undefined : passes[step.pass];\n if (pass === undefined) {\n tasks.push(\n createCopyToTextureTask(\n {\n name: step.target === sceneTarget ? \"ignifx:scene-color-copy\" : \"ignifx:scene-color-stage\",\n sourceTexture: step.source,\n targetTexture: step.target,\n },\n engine,\n scene,\n ),\n );\n continue;\n }\n appendTasks(tasks, pass.create(step.source, step.target));\n }\n let after = sceneTask;\n for (const task of tasks) {\n addTaskAfter(scene, task, after);\n after = task;\n }\n if (isFrameGraphBuilt) {\n const graph = getFrameGraph(scene);\n for (const task of tasks) {\n buildFrameGraphTask(graph, task);\n }\n }\n } catch (failure) {\n // A pass that could not be created or recorded leaves nothing behind in the frame graph.\n free();\n throw failure;\n }\n let isDisposed = false;\n return {\n taskCount: tasks.length,\n dispose(): void {\n if (isDisposed) {\n return;\n }\n isDisposed = true;\n free();\n },\n };\n}\n\n/**\n * One step of the plan: a pass, or a copy when `pass` is `null`.\n *\n * @internal\n */\nexport interface SceneColorStep<T> {\n /** The index of the pass that runs, or `null` for a copy. */\n readonly pass: number | null;\n /** The colour the step reads. */\n readonly source: T;\n /** The colour it writes; `source` for an in-place pass. */\n readonly target: T;\n}\n\n/**\n * Plans the steps that take the scene colour through every pass and back into the scene target.\n *\n * @remarks\n * A pass that writes a second target goes where {@link sceneColorPassTarget} says. An in-place pass\n * gets the colour it reads as its target; when that is a scene target no pass may write, a copy\n * moves the colour into a scratch first. A last copy brings the result back when it is not already\n * in the scene target.\n *\n * @param inPlace - For each pass, whether it is {@link SceneColorPass.inPlace}.\n * @param sceneTarget - The scene's colour target.\n * @param isTargetWritable - Whether a pass may write `sceneTarget` (`ScenePass.isTargetWritable` in `./render-path.ts`).\n * @param scratches - The scratch targets made so far; new ones are appended as needed.\n * @param createScratch - Makes the scratch target at an index, 0 or 1.\n * @returns The steps, in the order they run.\n *\n * @internal\n */\nexport function planSceneColorPasses<T>(\n inPlace: readonly boolean[],\n sceneTarget: T,\n isTargetWritable: boolean,\n scratches: T[],\n createScratch: (index: number) => T,\n): SceneColorStep<T>[] {\n const steps: SceneColorStep<T>[] = [];\n let source = sceneTarget;\n for (let pass = 0; pass < inPlace.length; pass += 1) {\n if (inPlace[pass] === true) {\n if (source === sceneTarget && !isTargetWritable) {\n const staged = sceneColorPassTarget(source, sceneTarget, isTargetWritable, scratches, createScratch);\n steps.push({ pass: null, source, target: staged });\n source = staged;\n }\n steps.push({ pass, source, target: source });\n continue;\n }\n const target = sceneColorPassTarget(source, sceneTarget, isTargetWritable, scratches, createScratch);\n steps.push({ pass, source, target });\n source = target;\n }\n if (source !== sceneTarget) {\n steps.push({ pass: null, source, target: sceneTarget });\n }\n return steps;\n}\n\n/**\n * Appends what a pass created to the task list.\n *\n * @param tasks - The list.\n * @param created - One task or several.\n */\nfunction appendTasks(tasks: Task[], created: Task | readonly Task[]): void {\n if (isTaskList(created)) {\n tasks.push(...created);\n } else {\n tasks.push(created);\n }\n}\n\n/**\n * Whether a pass returned several tasks.\n *\n * @param created - What `create` returned.\n * @returns `true` for a list.\n */\nfunction isTaskList(created: Task | readonly Task[]): created is readonly Task[] {\n return Array.isArray(created);\n}\n\n/**\n * Picks where the next scene-colour pass writes: back into the scene target when that is allowed\n * and the pass does not read it, otherwise the scratch target the pass does not read.\n *\n * @param source - What the pass reads.\n * @param sceneTarget - The scene's colour target.\n * @param isTargetWritable - Whether a pass may write `sceneTarget` (`ScenePass.isTargetWritable` in `./render-path.ts`).\n * @param scratches - The scratch targets made so far; a new one is appended when needed.\n * @param createScratch - Makes the scratch target at an index, 0 or 1.\n * @returns The target, never `source`.\n *\n * @internal\n */\nexport function sceneColorPassTarget<T>(\n source: T,\n sceneTarget: T,\n isTargetWritable: boolean,\n scratches: T[],\n createScratch: (index: number) => T,\n): T {\n if (source !== sceneTarget && isTargetWritable) {\n return sceneTarget;\n }\n const index = source === scratches[0] ? 1 : 0;\n let scratch = scratches[index];\n if (scratch === undefined) {\n scratch = createScratch(index);\n scratches[index] = scratch;\n }\n return scratch;\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { GeometryTextureType, addTaskAfter, addTaskAtStart, buildFrameGraphTask, createCopyToTextureTask, createDepthPyramid, createDepthPyramidTask, createGeometryRendererTask, createSurfaceRenderTargetTexture, disposeRenderTargetTexture, getFrameGraph, onRenderTargetTextureResize, withSampledDepthTexture } from "@babylonjs/lite";
|
|
2
|
+
//#region src/lite/gpu/scene-inputs.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared scene inputs (`docs/architecture/07-rendering.md` §2.12): one geometry pass that
|
|
5
|
+
* screen-space effects (TAA, GTAO, contact shadows, SSGI) read instead of each drawing the scene
|
|
6
|
+
* again. Its own chunk: the renderer imports it only when an effect asks for it, so a project with
|
|
7
|
+
* no such effect loads none of it and its frame graph has none of these tasks (`CONSTITUTION.md`
|
|
8
|
+
* §2.5).
|
|
9
|
+
*
|
|
10
|
+
* ```text
|
|
11
|
+
* [shadow] → geometry ─→ normals copy ─→ velocity copy ─→ [albedo copy] ─→ depth pyramid → scene → …
|
|
12
|
+
* ├ depth (depth32float, sampled)
|
|
13
|
+
* ├ world normal ─(copy)─→ normals
|
|
14
|
+
* ├ velocity ─(copy)─→ velocity
|
|
15
|
+
* └ [albedo ─(copy)─→ albedo]
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* - **Depth** is a surface-sized `depth32float` target with a sampled facade
|
|
19
|
+
* (`withSampledDepthTexture`) handed to the geometry task as its depth. Reverse-Z: 0 is
|
|
20
|
+
* the far plane. `depth24plus-stencil8`, the main pass's format, cannot be bound in compute.
|
|
21
|
+
* - **Normals and velocity** are geometry attachments, which Lite exposes only as task-owned
|
|
22
|
+
* `RenderTarget`s; compute and effect bindings take a `Texture2D`, so each is copied into a target
|
|
23
|
+
* that has one (`docs/architecture/07-rendering.md` §8, upstream ask "geometry attachments as
|
|
24
|
+
* `Texture2D`").
|
|
25
|
+
* - **Albedo** is a third attachment only while a user asked for it ({@link SceneInputsOptions.albedo},
|
|
26
|
+
* SSGI): the first such acquire replaces the geometry task and its copies with ones that also
|
|
27
|
+
* write albedo, keeping every target the other users hold. The old tasks keep drawing until the
|
|
28
|
+
* new geometry task has loaded its material code, so no frame is left without inputs. Albedo
|
|
29
|
+
* stays until the last lease of any kind is released.
|
|
30
|
+
* - **The depth pyramid** is Lite's `createDepthPyramid`: an `r32float` mip chain where each level
|
|
31
|
+
* keeps the `max` (in reverse-Z, the nearest surface) of its four children.
|
|
32
|
+
* - **Ref-counted.** {@link SceneInputsHost.acquire} adds the tasks for the first user;
|
|
33
|
+
* {@link SceneInputs.release} by the last one removes and disposes them.
|
|
34
|
+
* - **Resize and device loss.** The targets are sized by the surface, so `frameGraph.build()`
|
|
35
|
+
* reallocates them, on a resize and on a recovered device alike. The depth target's resize
|
|
36
|
+
* callback rebuilds the pyramid (its pipelines belong to one device) and tells every user through
|
|
37
|
+
* {@link SceneInputs.onChange}, so they can rebind.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* The frame-graph task names, in the order they run.
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
const SCENE_INPUT_TASK_NAMES = {
|
|
45
|
+
geometry: "ignifx:scene-inputs",
|
|
46
|
+
normals: "ignifx:scene-inputs-normals",
|
|
47
|
+
velocity: "ignifx:scene-inputs-velocity",
|
|
48
|
+
albedo: "ignifx:scene-inputs-albedo",
|
|
49
|
+
depthPyramid: "ignifx:scene-inputs-depth-pyramid"
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The texture format of each input.
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
const SCENE_INPUT_FORMATS = {
|
|
57
|
+
depth: "depth32float",
|
|
58
|
+
normals: "rgba16float",
|
|
59
|
+
velocity: "rgba16float",
|
|
60
|
+
albedo: "rgba8unorm",
|
|
61
|
+
depthPyramid: "r32float"
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Creates the scene-inputs owner for one scene. It adds nothing to the frame graph until the first
|
|
65
|
+
* {@link SceneInputsHost.acquire}.
|
|
66
|
+
*
|
|
67
|
+
* @param engine - The engine, which is also the primary surface.
|
|
68
|
+
* @param scene - The render scene.
|
|
69
|
+
* @param report - Called with a message when work the host does after `acquire` returned fails.
|
|
70
|
+
* @returns The host.
|
|
71
|
+
*
|
|
72
|
+
* @internal
|
|
73
|
+
*/
|
|
74
|
+
function createSceneInputsHost(engine, scene, report) {
|
|
75
|
+
let shared = null;
|
|
76
|
+
const leases = /* @__PURE__ */ new Set();
|
|
77
|
+
let isDisposed = false;
|
|
78
|
+
const releaseLease = (lease) => {
|
|
79
|
+
if (!leases.delete(lease) || leases.size > 0 || shared === null) return;
|
|
80
|
+
teardown(scene, shared);
|
|
81
|
+
shared = null;
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
acquire(isFrameGraphBuilt, options) {
|
|
85
|
+
if (isDisposed) return null;
|
|
86
|
+
const wantsAlbedo = options?.albedo === true;
|
|
87
|
+
shared ??= buildSharedInputs(engine, scene, isFrameGraphBuilt, wantsAlbedo);
|
|
88
|
+
const inputs = shared;
|
|
89
|
+
if (wantsAlbedo && inputs.albedo === null) addAlbedo(engine, scene, inputs, isFrameGraphBuilt, report);
|
|
90
|
+
let isReleased = false;
|
|
91
|
+
const own = /* @__PURE__ */ new Set();
|
|
92
|
+
const lease = {
|
|
93
|
+
depth: requireDepthFacade(inputs.depth),
|
|
94
|
+
depthTarget: inputs.depth.rt,
|
|
95
|
+
normals: inputs.normals.texture,
|
|
96
|
+
velocity: inputs.velocity.texture,
|
|
97
|
+
get albedo() {
|
|
98
|
+
return inputs.albedo?.texture ?? null;
|
|
99
|
+
},
|
|
100
|
+
get depthPyramid() {
|
|
101
|
+
return inputs.pyramid.current.texture;
|
|
102
|
+
},
|
|
103
|
+
get depthPyramidMipCount() {
|
|
104
|
+
return inputs.pyramid.current.mipCount;
|
|
105
|
+
},
|
|
106
|
+
get isReleased() {
|
|
107
|
+
return isReleased;
|
|
108
|
+
},
|
|
109
|
+
onChange(callback) {
|
|
110
|
+
inputs.listeners.add(callback);
|
|
111
|
+
own.add(callback);
|
|
112
|
+
return () => {
|
|
113
|
+
inputs.listeners.delete(callback);
|
|
114
|
+
own.delete(callback);
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
release() {
|
|
118
|
+
if (isReleased) return;
|
|
119
|
+
isReleased = true;
|
|
120
|
+
for (const callback of own) inputs.listeners.delete(callback);
|
|
121
|
+
own.clear();
|
|
122
|
+
releaseLease(lease);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
leases.add(lease);
|
|
126
|
+
return lease;
|
|
127
|
+
},
|
|
128
|
+
get userCount() {
|
|
129
|
+
return leases.size;
|
|
130
|
+
},
|
|
131
|
+
dispose() {
|
|
132
|
+
if (isDisposed) return;
|
|
133
|
+
isDisposed = true;
|
|
134
|
+
for (const lease of leases) lease.release();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Builds the targets and tasks, and splices the tasks into the frame graph ahead of the scene pass.
|
|
140
|
+
*
|
|
141
|
+
* @param engine - The engine.
|
|
142
|
+
* @param scene - The scene.
|
|
143
|
+
* @param isFrameGraphBuilt - Whether each task must be recorded now.
|
|
144
|
+
* @param withAlbedo - Whether the geometry pass also writes albedo.
|
|
145
|
+
* @returns The shared state.
|
|
146
|
+
*/
|
|
147
|
+
function buildSharedInputs(engine, scene, isFrameGraphBuilt, withAlbedo) {
|
|
148
|
+
const depth = createSurfaceRenderTargetTexture(engine, {
|
|
149
|
+
lbl: "ignifx:scene-inputs-depth",
|
|
150
|
+
dFormat: SCENE_INPUT_FORMATS.depth,
|
|
151
|
+
samples: 1,
|
|
152
|
+
size: engine
|
|
153
|
+
}, withSampledDepthTexture);
|
|
154
|
+
const normals = createSurfaceRenderTargetTexture(engine, {
|
|
155
|
+
lbl: "ignifx:scene-inputs-normals",
|
|
156
|
+
format: SCENE_INPUT_FORMATS.normals,
|
|
157
|
+
samples: 1,
|
|
158
|
+
size: engine
|
|
159
|
+
});
|
|
160
|
+
const velocity = createSurfaceRenderTargetTexture(engine, {
|
|
161
|
+
lbl: "ignifx:scene-inputs-velocity",
|
|
162
|
+
format: SCENE_INPUT_FORMATS.velocity,
|
|
163
|
+
samples: 1,
|
|
164
|
+
size: engine
|
|
165
|
+
});
|
|
166
|
+
const albedo = withAlbedo ? createAlbedoTarget(engine) : null;
|
|
167
|
+
const geometryTasks = createGeometryTasks(engine, scene, {
|
|
168
|
+
depth,
|
|
169
|
+
normals,
|
|
170
|
+
velocity,
|
|
171
|
+
albedo
|
|
172
|
+
});
|
|
173
|
+
const depthFacade = requireDepthFacade(depth);
|
|
174
|
+
const pyramid = { current: newPyramid(engine, depthFacade) };
|
|
175
|
+
const pyramidTask = createDepthPyramidTask(engine, scene, {
|
|
176
|
+
pyramid: {
|
|
177
|
+
get texture() {
|
|
178
|
+
return pyramid.current.texture;
|
|
179
|
+
},
|
|
180
|
+
get mipCount() {
|
|
181
|
+
return pyramid.current.mipCount;
|
|
182
|
+
},
|
|
183
|
+
build(source, encoder) {
|
|
184
|
+
pyramid.current.build(source, encoder);
|
|
185
|
+
},
|
|
186
|
+
resize(width, height) {
|
|
187
|
+
pyramid.current.resize(width, height);
|
|
188
|
+
},
|
|
189
|
+
dispose() {
|
|
190
|
+
pyramid.current.dispose();
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
source: () => depthFacade
|
|
194
|
+
});
|
|
195
|
+
Reflect.set(pyramidTask, "name", SCENE_INPUT_TASK_NAMES.depthPyramid);
|
|
196
|
+
const last = insertGeometryTasks(scene, geometryTasks, isFrameGraphBuilt);
|
|
197
|
+
addTaskAfter(scene, pyramidTask, last);
|
|
198
|
+
if (isFrameGraphBuilt) buildFrameGraphTask(getFrameGraph(scene), pyramidTask);
|
|
199
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
200
|
+
return {
|
|
201
|
+
depth,
|
|
202
|
+
normals,
|
|
203
|
+
velocity,
|
|
204
|
+
albedo,
|
|
205
|
+
geometryTasks,
|
|
206
|
+
isTornDown: false,
|
|
207
|
+
pyramidTask,
|
|
208
|
+
pyramid,
|
|
209
|
+
listeners,
|
|
210
|
+
stopResizeWatch: onRenderTargetTextureResize(depth, () => {
|
|
211
|
+
pyramid.current.dispose();
|
|
212
|
+
pyramid.current = newPyramid(engine, depthFacade);
|
|
213
|
+
for (const listener of listeners) listener();
|
|
214
|
+
})
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Creates the albedo target.
|
|
219
|
+
*
|
|
220
|
+
* @param engine - The engine, which is also the surface.
|
|
221
|
+
* @returns The target and its sampled facade.
|
|
222
|
+
*/
|
|
223
|
+
function createAlbedoTarget(engine) {
|
|
224
|
+
return createSurfaceRenderTargetTexture(engine, {
|
|
225
|
+
lbl: "ignifx:scene-inputs-albedo",
|
|
226
|
+
format: SCENE_INPUT_FORMATS.albedo,
|
|
227
|
+
samples: 1,
|
|
228
|
+
size: engine
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Creates the geometry task and one copy per colour attachment.
|
|
233
|
+
*
|
|
234
|
+
* @param engine - The engine.
|
|
235
|
+
* @param scene - The scene.
|
|
236
|
+
* @param targets - The depth the pass writes and the targets its attachments are copied into.
|
|
237
|
+
* @param targets.depth - The depth target.
|
|
238
|
+
* @param targets.normals - The normals target.
|
|
239
|
+
* @param targets.velocity - The velocity target.
|
|
240
|
+
* @param targets.albedo - The albedo target, or `null` to leave albedo out of the pass.
|
|
241
|
+
* @returns The tasks, in the order they run.
|
|
242
|
+
*/
|
|
243
|
+
function createGeometryTasks(engine, scene, targets) {
|
|
244
|
+
const textureDescriptions = [{
|
|
245
|
+
type: GeometryTextureType.WORLD_NORMAL,
|
|
246
|
+
format: SCENE_INPUT_FORMATS.normals
|
|
247
|
+
}, {
|
|
248
|
+
type: GeometryTextureType.LINEAR_VELOCITY,
|
|
249
|
+
format: SCENE_INPUT_FORMATS.velocity
|
|
250
|
+
}];
|
|
251
|
+
if (targets.albedo !== null) textureDescriptions.push({
|
|
252
|
+
type: GeometryTextureType.ALBEDO,
|
|
253
|
+
format: SCENE_INPUT_FORMATS.albedo
|
|
254
|
+
});
|
|
255
|
+
const geometry = createGeometryRendererTask({
|
|
256
|
+
name: SCENE_INPUT_TASK_NAMES.geometry,
|
|
257
|
+
size: engine,
|
|
258
|
+
depthTexture: targets.depth.rt,
|
|
259
|
+
textureDescriptions
|
|
260
|
+
}, engine, scene);
|
|
261
|
+
const tasks = [
|
|
262
|
+
geometry,
|
|
263
|
+
createCopyToTextureTask({
|
|
264
|
+
name: SCENE_INPUT_TASK_NAMES.normals,
|
|
265
|
+
sourceTexture: requireAttachment(geometry.geometryWorldNormalTexture, "world normal"),
|
|
266
|
+
targetTexture: targets.normals.rt
|
|
267
|
+
}, engine, scene),
|
|
268
|
+
createCopyToTextureTask({
|
|
269
|
+
name: SCENE_INPUT_TASK_NAMES.velocity,
|
|
270
|
+
sourceTexture: requireAttachment(geometry.geometryLinearVelocityTexture, "linear velocity"),
|
|
271
|
+
targetTexture: targets.velocity.rt
|
|
272
|
+
}, engine, scene)
|
|
273
|
+
];
|
|
274
|
+
if (targets.albedo !== null) tasks.push(createCopyToTextureTask({
|
|
275
|
+
name: SCENE_INPUT_TASK_NAMES.albedo,
|
|
276
|
+
sourceTexture: requireAttachment(geometry.geometryAlbedoTexture, "albedo"),
|
|
277
|
+
targetTexture: targets.albedo.rt
|
|
278
|
+
}, engine, scene));
|
|
279
|
+
return tasks;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Puts the geometry task at the start of the frame graph and its copies right after it.
|
|
283
|
+
*
|
|
284
|
+
* @param scene - The scene.
|
|
285
|
+
* @param tasks - What {@link createGeometryTasks} made.
|
|
286
|
+
* @param isFrameGraphBuilt - Whether each task must be recorded now.
|
|
287
|
+
* @returns The last task inserted.
|
|
288
|
+
*/
|
|
289
|
+
function insertGeometryTasks(scene, tasks, isFrameGraphBuilt) {
|
|
290
|
+
const [geometry, ...copies] = tasks;
|
|
291
|
+
if (geometry === void 0) throw new Error("The scene inputs have no geometry task.");
|
|
292
|
+
addTaskAtStart(scene, geometry);
|
|
293
|
+
let after = geometry;
|
|
294
|
+
for (const copy of copies) {
|
|
295
|
+
addTaskAfter(scene, copy, after);
|
|
296
|
+
after = copy;
|
|
297
|
+
}
|
|
298
|
+
if (isFrameGraphBuilt) {
|
|
299
|
+
const graph = getFrameGraph(scene);
|
|
300
|
+
for (const task of tasks) buildFrameGraphTask(graph, task);
|
|
301
|
+
}
|
|
302
|
+
return after;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Replaces the geometry task and its copies with ones that also write albedo.
|
|
306
|
+
*
|
|
307
|
+
* @remarks
|
|
308
|
+
* Lite fixes a geometry task's attachments at creation. The depth, normals and velocity targets,
|
|
309
|
+
* and the pyramid task that reads the depth, stay as they are, so no other user has to rebind.
|
|
310
|
+
*
|
|
311
|
+
* A geometry task draws nothing until its `_preload` has imported the code for the scene's
|
|
312
|
+
* material families. Lite awaits that at scene registration (`lib/scene/scene-core.js`); for a
|
|
313
|
+
* task added later it only starts on the first draw, which leaves that frame empty
|
|
314
|
+
* (`lib/frame-graph/geometry-renderer-task.js`, `resolveSourceMaterial`). So in a registered scene
|
|
315
|
+
* the new tasks are created first and swapped in once that promise settles, and the old ones draw
|
|
316
|
+
* until then. The albedo target exists from the start and holds nothing until the swap.
|
|
317
|
+
*
|
|
318
|
+
* @param engine - The engine.
|
|
319
|
+
* @param scene - The scene.
|
|
320
|
+
* @param shared - The shared state, updated in place.
|
|
321
|
+
* @param isFrameGraphBuilt - Whether the scene is registered.
|
|
322
|
+
* @param report - Called with a message when the swap fails; the old tasks then stay.
|
|
323
|
+
*/
|
|
324
|
+
function addAlbedo(engine, scene, shared, isFrameGraphBuilt, report) {
|
|
325
|
+
const albedo = createAlbedoTarget(engine);
|
|
326
|
+
shared.albedo = albedo;
|
|
327
|
+
const next = createGeometryTasks(engine, scene, shared);
|
|
328
|
+
const swap = () => {
|
|
329
|
+
if (shared.isTornDown) {
|
|
330
|
+
disposeTasks(next);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
const previous = shared.geometryTasks;
|
|
334
|
+
const textureBefore = albedo.texture.texture;
|
|
335
|
+
carryPreviousViewProjection(previous[0], next[0]);
|
|
336
|
+
try {
|
|
337
|
+
insertGeometryTasks(scene, next, isFrameGraphBuilt);
|
|
338
|
+
} catch (failure) {
|
|
339
|
+
removeTasks(scene, next);
|
|
340
|
+
report(`The scene inputs could not add albedo: ${failure instanceof Error ? failure.message : String(failure)}`);
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
343
|
+
removeTasks(scene, previous);
|
|
344
|
+
shared.geometryTasks = next;
|
|
345
|
+
if (albedo.texture.texture !== textureBefore) for (const listener of shared.listeners) listener();
|
|
346
|
+
};
|
|
347
|
+
const preload = isFrameGraphBuilt ? Reflect.get(next[0] ?? {}, "_preload") : void 0;
|
|
348
|
+
if (typeof preload !== "function") {
|
|
349
|
+
swap();
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
Promise.resolve(Reflect.apply(preload, next[0], [])).then(swap, swap);
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Hands the previous frame's view-projection from one geometry task to its replacement, so the
|
|
356
|
+
* velocity the new task writes for PBR meshes in its first frame is measured from the last frame
|
|
357
|
+
* drawn. A Standard mesh tracks its own previous matrix per geometry view and writes no velocity
|
|
358
|
+
* for that one frame (`lib/material/standard/standard-geometry-output-shader.js`).
|
|
359
|
+
*
|
|
360
|
+
* @remarks
|
|
361
|
+
* The field is private to Lite (`_previousViewProjection`, `lib/frame-graph/geometry-renderer-task.js`)
|
|
362
|
+
* and starts as zeros. If a later Lite renames it, the first frame's velocity is wrong and TAA
|
|
363
|
+
* drops its history for that frame.
|
|
364
|
+
*
|
|
365
|
+
* @param from - The task being replaced.
|
|
366
|
+
* @param to - The task replacing it.
|
|
367
|
+
*/
|
|
368
|
+
function carryPreviousViewProjection(from, to) {
|
|
369
|
+
const source = from === void 0 ? void 0 : Reflect.get(from, "_previousViewProjection");
|
|
370
|
+
const target = to === void 0 ? void 0 : Reflect.get(to, "_previousViewProjection");
|
|
371
|
+
if (source instanceof Float32Array && target instanceof Float32Array && source.length === target.length) target.set(source);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Removes the tasks from the frame graph and frees every task and target.
|
|
375
|
+
*
|
|
376
|
+
* @param scene - The scene.
|
|
377
|
+
* @param shared - What {@link buildSharedInputs} built.
|
|
378
|
+
*/
|
|
379
|
+
function teardown(scene, shared) {
|
|
380
|
+
shared.isTornDown = true;
|
|
381
|
+
shared.stopResizeWatch();
|
|
382
|
+
shared.listeners.clear();
|
|
383
|
+
removeTasks(scene, [...shared.geometryTasks, shared.pyramidTask]);
|
|
384
|
+
disposeRenderTargetTexture(shared.depth);
|
|
385
|
+
disposeRenderTargetTexture(shared.normals);
|
|
386
|
+
disposeRenderTargetTexture(shared.velocity);
|
|
387
|
+
if (shared.albedo !== null) disposeRenderTargetTexture(shared.albedo);
|
|
388
|
+
}
|
|
389
|
+
/**
|
|
390
|
+
* Takes tasks out of the frame graph and disposes them.
|
|
391
|
+
*
|
|
392
|
+
* @param scene - The scene.
|
|
393
|
+
* @param tasks - The tasks.
|
|
394
|
+
*/
|
|
395
|
+
function removeTasks(scene, tasks) {
|
|
396
|
+
for (const task of tasks) {
|
|
397
|
+
task.executionEnabled = false;
|
|
398
|
+
removeFrameGraphTask(scene, task);
|
|
399
|
+
}
|
|
400
|
+
disposeTasks(tasks);
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Disposes tasks that are not in a frame graph.
|
|
404
|
+
*
|
|
405
|
+
* @param tasks - The tasks.
|
|
406
|
+
*/
|
|
407
|
+
function disposeTasks(tasks) {
|
|
408
|
+
for (const task of tasks) {
|
|
409
|
+
task.executionEnabled = false;
|
|
410
|
+
task.dispose();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Takes a task out of the scene's frame graph.
|
|
415
|
+
*
|
|
416
|
+
* @remarks
|
|
417
|
+
* Lite 1.34 has no public remove (`index.d.ts` 206–217 add only), and a disposed task left in the
|
|
418
|
+
* graph is recorded again by the next `frameGraph.build()` against freed targets. The task list is
|
|
419
|
+
* the private `_tasks` array every `addTask*` splices (`lib/frame-graph/frame-graph-actions.js`).
|
|
420
|
+
* If a later Lite renames it, the task stays in, disabled.
|
|
421
|
+
*
|
|
422
|
+
* @param scene - The scene.
|
|
423
|
+
* @param task - The task to remove.
|
|
424
|
+
*/
|
|
425
|
+
function removeFrameGraphTask(scene, task) {
|
|
426
|
+
const tasks = frameGraphTasks(scene);
|
|
427
|
+
const index = tasks?.indexOf(task) ?? -1;
|
|
428
|
+
if (tasks !== null && index >= 0) tasks.splice(index, 1);
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* The scene's frame-graph task list, or `null` when Lite no longer exposes it.
|
|
432
|
+
*
|
|
433
|
+
* @param scene - The scene.
|
|
434
|
+
* @returns The live array (Lite's own), or `null`.
|
|
435
|
+
*
|
|
436
|
+
* @internal
|
|
437
|
+
*/
|
|
438
|
+
function frameGraphTasks(scene) {
|
|
439
|
+
const tasks = Reflect.get(getFrameGraph(scene), "_tasks");
|
|
440
|
+
return isTaskList(tasks) ? tasks : null;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Whether a value is Lite's task array.
|
|
444
|
+
*
|
|
445
|
+
* @param value - The value read from the frame graph.
|
|
446
|
+
* @returns `true` for an array.
|
|
447
|
+
*/
|
|
448
|
+
function isTaskList(value) {
|
|
449
|
+
return Array.isArray(value);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Creates a depth pyramid the size of the depth facade's current texture.
|
|
453
|
+
*
|
|
454
|
+
* @param engine - The engine, whose current device owns the pipelines.
|
|
455
|
+
* @param depth - The depth facade.
|
|
456
|
+
* @returns The pyramid.
|
|
457
|
+
*/
|
|
458
|
+
function newPyramid(engine, depth) {
|
|
459
|
+
return createDepthPyramid(engine, {
|
|
460
|
+
width: depth.width,
|
|
461
|
+
height: depth.height,
|
|
462
|
+
reduce: "max"
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* The sampled depth facade of the depth target.
|
|
467
|
+
*
|
|
468
|
+
* @param depth - The depth target, created with `withSampledDepthTexture`.
|
|
469
|
+
* @returns The facade.
|
|
470
|
+
*/
|
|
471
|
+
function requireDepthFacade(depth) {
|
|
472
|
+
if (depth.depthTexture === null) throw new Error("Lite built the scene-inputs depth target without a sampled depth facade.");
|
|
473
|
+
return depth.depthTexture;
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* A geometry attachment the task was asked for.
|
|
477
|
+
*
|
|
478
|
+
* @param target - The accessor's value.
|
|
479
|
+
* @param what - The attachment, for the error.
|
|
480
|
+
* @returns The attachment.
|
|
481
|
+
*/
|
|
482
|
+
function requireAttachment(target, what) {
|
|
483
|
+
if (target === null) throw new Error(`Lite's geometry task built no ${what} attachment.`);
|
|
484
|
+
return target;
|
|
485
|
+
}
|
|
486
|
+
//#endregion
|
|
487
|
+
export { SCENE_INPUT_TASK_NAMES, createSceneInputsHost, frameGraphTasks };
|
|
488
|
+
|
|
489
|
+
//# sourceMappingURL=scene-inputs-CbTkrkOw.js.map
|