@ignifx/core 0.2.1 → 0.3.1
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/dist/async-pipelines-CI5uT5iZ.js +26 -0
- package/dist/async-pipelines-CI5uT5iZ.js.map +1 -0
- package/dist/color-DrR6GFTd.js +351 -0
- package/dist/color-DrR6GFTd.js.map +1 -0
- package/dist/effect-task-CMbuO6Kb.js +205 -0
- package/dist/effect-task-CMbuO6Kb.js.map +1 -0
- package/dist/environment-C_JfuAjj.js +224 -0
- package/dist/environment-C_JfuAjj.js.map +1 -0
- package/dist/ignifx-error-R1ma_Lzv.js +544 -0
- package/dist/ignifx-error-R1ma_Lzv.js.map +1 -0
- package/dist/index.d.ts +3756 -1656
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6404 -5777
- package/dist/index.js.map +1 -1
- package/dist/instanced-mesh-instance-Cgx1H87p.js +701 -0
- package/dist/instanced-mesh-instance-Cgx1H87p.js.map +1 -0
- package/dist/material-plugin-CTaWZXEk.js +485 -0
- package/dist/material-plugin-CTaWZXEk.js.map +1 -0
- package/dist/math-utils-BcDnL-gi.js +277 -0
- package/dist/math-utils-BcDnL-gi.js.map +1 -0
- package/dist/mesh-CnK_PX46.js +811 -0
- package/dist/mesh-CnK_PX46.js.map +1 -0
- package/dist/post-effect-C42XJFmo.js +155 -0
- package/dist/post-effect-C42XJFmo.js.map +1 -0
- package/dist/post-effect-compiler-DTlkT1si.js +311 -0
- package/dist/post-effect-compiler-DTlkT1si.js.map +1 -0
- package/dist/shader-declaration-5q__jycG.js +165 -0
- package/dist/shader-declaration-5q__jycG.js.map +1 -0
- package/dist/shader-material-DssOqsvZ.js +1009 -0
- package/dist/shader-material-DssOqsvZ.js.map +1 -0
- package/dist/shader-material-Xk7Oc9UG.js +207 -0
- package/dist/shader-material-Xk7Oc9UG.js.map +1 -0
- package/dist/shader-pragma-CNAK4SIb.js +685 -0
- package/dist/shader-pragma-CNAK4SIb.js.map +1 -0
- package/dist/surface-shader-C2HtysNN.js +1397 -0
- package/dist/surface-shader-C2HtysNN.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { enableAsyncShaderPipelineCompilation } from "@babylonjs/lite";
|
|
2
|
+
//#region src/lite/gpu/async-pipelines.ts
|
|
3
|
+
/**
|
|
4
|
+
* The `rendering.features.asyncPipelines` opt-in, in a module of its own.
|
|
5
|
+
*
|
|
6
|
+
* Babylon Lite's async-pipeline hook reaches its shader-material renderable, which is also what the
|
|
7
|
+
* custom-WGSL adapter needs. Importing it from `../render-features.ts` would make that code shared
|
|
8
|
+
* between the entry graph and the shader chunk, and a bundler resolves "shared" by hoisting it into
|
|
9
|
+
* the entry — so a game that enables neither would pay for both (`CONSTITUTION.md` §2.5). The
|
|
10
|
+
* feature is off by default and applied from an `await`ed path, so the extra chunk is fetched only
|
|
11
|
+
* by a game that asked for it.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Turns on Babylon Lite's asynchronous shader-pipeline compilation for one engine.
|
|
15
|
+
*
|
|
16
|
+
* @param engine - The engine whose pipelines compile off the critical path.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
function enableAsyncPipelines(engine) {
|
|
21
|
+
enableAsyncShaderPipelineCompilation(engine);
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { enableAsyncPipelines };
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=async-pipelines-CI5uT5iZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"async-pipelines-CI5uT5iZ.js","names":[],"sources":["../src/lite/gpu/async-pipelines.ts"],"sourcesContent":["import { enableAsyncShaderPipelineCompilation } from \"@babylonjs/lite\";\nimport type { EngineContext } from \"@babylonjs/lite\";\n\n/**\n * The `rendering.features.asyncPipelines` opt-in, in a module of its own.\n *\n * Babylon Lite's async-pipeline hook reaches its shader-material renderable, which is also what the\n * custom-WGSL adapter needs. Importing it from `../render-features.ts` would make that code shared\n * between the entry graph and the shader chunk, and a bundler resolves \"shared\" by hoisting it into\n * the entry — so a game that enables neither would pay for both (`CONSTITUTION.md` §2.5). The\n * feature is off by default and applied from an `await`ed path, so the extra chunk is fetched only\n * by a game that asked for it.\n */\n\n/**\n * Turns on Babylon Lite's asynchronous shader-pipeline compilation for one engine.\n *\n * @param engine - The engine whose pipelines compile off the critical path.\n *\n * @internal\n */\nexport function enableAsyncPipelines(engine: EngineContext): void {\n enableAsyncShaderPipelineCompilation(engine);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,qBAAqB,QAA6B;CAChE,qCAAqC,MAAM;AAC7C"}
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { n as EPSILON, o as clamp01, u as lerp } from "./math-utils-BcDnL-gi.js";
|
|
2
|
+
//#region src/math/color.ts
|
|
3
|
+
/**
|
|
4
|
+
* Matches `#rrggbb`, `#rrggbbaa`, and the same two without the leading `#`.
|
|
5
|
+
*/
|
|
6
|
+
const HEX_PATTERN = /^#?(?:[\da-f]{6}|[\da-f]{8})$/iu;
|
|
7
|
+
/**
|
|
8
|
+
* Formats a 0-255 channel as two lowercase hex digits.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The channel value, already rounded into 0-255.
|
|
11
|
+
* @returns Two hex digits.
|
|
12
|
+
*/
|
|
13
|
+
function hexByte(value) {
|
|
14
|
+
return value.toString(16).padStart(2, "0");
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* An RGBA colour whose components are **linear** and normally in 0-1 (values above 1 are allowed
|
|
18
|
+
* and mean HDR intensity). Lighting maths only works in linear space, which is why this is the
|
|
19
|
+
* space ignifx stores; scene files and hex strings are sRGB, and
|
|
20
|
+
* {@link Color.fromHex}/{@link Color.fromSrgb} are the doors between the two
|
|
21
|
+
* (`docs/architecture/06-serialization-and-scene-format.md` section 3).
|
|
22
|
+
*
|
|
23
|
+
* Every method says which space it works in. The rule of thumb: if it takes or returns a hex string
|
|
24
|
+
* or has `Srgb` in its name, it is sRGB; everything else is linear.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* const tint = Color.fromHex("#ff8800") ?? new Color(1, 1, 1, 1); // parsed as sRGB, stored linear
|
|
29
|
+
* tint.scaleRgb(2); // twice as bright, same alpha
|
|
30
|
+
* tint.toHex(); // back to sRGB: "#ffbe00"
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
*/
|
|
35
|
+
var Color = class Color {
|
|
36
|
+
/** The linear red component. */
|
|
37
|
+
r;
|
|
38
|
+
/** The linear green component. */
|
|
39
|
+
g;
|
|
40
|
+
/** The linear blue component. */
|
|
41
|
+
b;
|
|
42
|
+
/** The alpha component in 0-1. Alpha is always linear, never gamma encoded. */
|
|
43
|
+
a;
|
|
44
|
+
/**
|
|
45
|
+
* Creates a colour from linear components.
|
|
46
|
+
*
|
|
47
|
+
* @param r - The linear red component. Defaults to 0.
|
|
48
|
+
* @param g - The linear green component. Defaults to 0.
|
|
49
|
+
* @param b - The linear blue component. Defaults to 0.
|
|
50
|
+
* @param a - The alpha component. Defaults to 1 (opaque).
|
|
51
|
+
*/
|
|
52
|
+
constructor(r = 0, g = 0, b = 0, a = 1) {
|
|
53
|
+
this.r = r;
|
|
54
|
+
this.g = g;
|
|
55
|
+
this.b = b;
|
|
56
|
+
this.a = a;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Assigns every component at once, in linear space.
|
|
60
|
+
*
|
|
61
|
+
* @param r - The new linear red component.
|
|
62
|
+
* @param g - The new linear green component.
|
|
63
|
+
* @param b - The new linear blue component.
|
|
64
|
+
* @param a - The new alpha component.
|
|
65
|
+
* @returns This colour.
|
|
66
|
+
*/
|
|
67
|
+
set(r, g, b, a) {
|
|
68
|
+
this.r = r;
|
|
69
|
+
this.g = g;
|
|
70
|
+
this.b = b;
|
|
71
|
+
this.a = a;
|
|
72
|
+
return this;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Copies every component from another colour.
|
|
76
|
+
*
|
|
77
|
+
* @param c - The colour to read.
|
|
78
|
+
* @returns This colour.
|
|
79
|
+
*/
|
|
80
|
+
copyFrom(c) {
|
|
81
|
+
this.r = c.r;
|
|
82
|
+
this.g = c.g;
|
|
83
|
+
this.b = c.b;
|
|
84
|
+
this.a = c.a;
|
|
85
|
+
return this;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Copies this colour into a new one.
|
|
89
|
+
*
|
|
90
|
+
* @returns A new colour. **Allocates.**
|
|
91
|
+
*/
|
|
92
|
+
clone() {
|
|
93
|
+
return new Color(this.r, this.g, this.b, this.a);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Multiplies this colour by another, component by component including alpha — the usual way a
|
|
97
|
+
* tint is applied.
|
|
98
|
+
*
|
|
99
|
+
* @param c - The colour to multiply by.
|
|
100
|
+
* @returns This colour.
|
|
101
|
+
*/
|
|
102
|
+
multiply(c) {
|
|
103
|
+
this.r *= c.r;
|
|
104
|
+
this.g *= c.g;
|
|
105
|
+
this.b *= c.b;
|
|
106
|
+
this.a *= c.a;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Scales the linear RGB components, leaving alpha alone. This is what "brighter" means: alpha is
|
|
111
|
+
* coverage, not colour.
|
|
112
|
+
*
|
|
113
|
+
* @param factor - The intensity factor.
|
|
114
|
+
* @returns This colour.
|
|
115
|
+
*/
|
|
116
|
+
scaleRgb(factor) {
|
|
117
|
+
this.r *= factor;
|
|
118
|
+
this.g *= factor;
|
|
119
|
+
this.b *= factor;
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Moves this colour towards a target, in linear space (which is where blending belongs; lerping
|
|
124
|
+
* sRGB values darkens midpoints).
|
|
125
|
+
*
|
|
126
|
+
* @param target - The colour reached at `t === 1`.
|
|
127
|
+
* @param t - The interpolant; not clamped.
|
|
128
|
+
* @returns This colour.
|
|
129
|
+
*/
|
|
130
|
+
lerp(target, t) {
|
|
131
|
+
return Color.lerpToRef(this, target, t, this);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Compares this colour with another, component by component, with a tolerance.
|
|
135
|
+
*
|
|
136
|
+
* @param c - The colour to compare against.
|
|
137
|
+
* @param epsilon - The largest per-component difference still considered equal.
|
|
138
|
+
* @returns `true` when every component matches within `epsilon`.
|
|
139
|
+
*/
|
|
140
|
+
equalsWithEpsilon(c, epsilon = EPSILON) {
|
|
141
|
+
return Color.equalsWithEpsilon(this, c, epsilon);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Writes the **linear** components into a `Float32Array`, the form a shader wants. The output
|
|
145
|
+
* comes first to mirror Babylon Lite's `toArray` helpers.
|
|
146
|
+
*
|
|
147
|
+
* @param out - The array to write into.
|
|
148
|
+
* @param offset - The index of the red component. Defaults to 0.
|
|
149
|
+
* @returns `out`.
|
|
150
|
+
*/
|
|
151
|
+
toArray(out, offset = 0) {
|
|
152
|
+
out[offset] = this.r;
|
|
153
|
+
out[offset + 1] = this.g;
|
|
154
|
+
out[offset + 2] = this.b;
|
|
155
|
+
out[offset + 3] = this.a;
|
|
156
|
+
return out;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Writes this colour's **sRGB-encoded** components into `out`, for display, pickers and files.
|
|
160
|
+
* Components are clamped into 0-1 by the encoding curve.
|
|
161
|
+
*
|
|
162
|
+
* @param out - The colour to write; may be this colour. Its fields hold sRGB values afterwards,
|
|
163
|
+
* not linear ones.
|
|
164
|
+
* @returns `out`.
|
|
165
|
+
*/
|
|
166
|
+
toSrgbToRef(out) {
|
|
167
|
+
return out.set(Color.linearToSrgb(this.r), Color.linearToSrgb(this.g), Color.linearToSrgb(this.b), this.a);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Encodes this colour as an sRGB hex string.
|
|
171
|
+
*
|
|
172
|
+
* @returns `#rrggbb` for an opaque colour, `#rrggbbaa` when alpha is below 1. **Allocates a
|
|
173
|
+
* string.**
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* new Color(1, 1, 1, 1).toHex(); // "#ffffff"
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
toHex() {
|
|
181
|
+
const r = hexByte(Math.round(Color.linearToSrgb(this.r) * 255));
|
|
182
|
+
const g = hexByte(Math.round(Color.linearToSrgb(this.g) * 255));
|
|
183
|
+
const b = hexByte(Math.round(Color.linearToSrgb(this.b) * 255));
|
|
184
|
+
const alpha = clamp01(this.a);
|
|
185
|
+
if (alpha >= 1) return `#${r}${g}${b}`;
|
|
186
|
+
return `#${r}${g}${b}${hexByte(Math.round(alpha * 255))}`;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Opaque white.
|
|
190
|
+
*
|
|
191
|
+
* @returns A new linear `(1, 1, 1, 1)`. **Allocates.**
|
|
192
|
+
*/
|
|
193
|
+
static white() {
|
|
194
|
+
return new Color(1, 1, 1, 1);
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Opaque black.
|
|
198
|
+
*
|
|
199
|
+
* @returns A new linear `(0, 0, 0, 1)`. **Allocates.**
|
|
200
|
+
*/
|
|
201
|
+
static black() {
|
|
202
|
+
return new Color(0, 0, 0, 1);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Fully transparent black.
|
|
206
|
+
*
|
|
207
|
+
* @returns A new linear `(0, 0, 0, 0)`. **Allocates.**
|
|
208
|
+
*/
|
|
209
|
+
static transparent() {
|
|
210
|
+
return new Color(0, 0, 0, 0);
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Copies any colour-shaped value into a `Color`.
|
|
214
|
+
*
|
|
215
|
+
* @param c - The linear colour to copy.
|
|
216
|
+
* @returns A new colour. **Allocates.**
|
|
217
|
+
*/
|
|
218
|
+
static from(c) {
|
|
219
|
+
return new Color(c.r, c.g, c.b, c.a);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Converts one **sRGB** channel to linear, using the IEC 61966-2-1 curve Babylon Lite uses
|
|
223
|
+
* (`lib/math/color.js`).
|
|
224
|
+
*
|
|
225
|
+
* @param channel - The sRGB channel value; clamped into 0-1.
|
|
226
|
+
* @returns The linear value.
|
|
227
|
+
*/
|
|
228
|
+
static srgbToLinear(channel) {
|
|
229
|
+
const c = clamp01(channel);
|
|
230
|
+
return c <= .04045 ? c / 12.92 : Math.pow((c + .055) / 1.055, 2.4);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Converts one **linear** channel to sRGB, the inverse of {@link Color.srgbToLinear}.
|
|
234
|
+
*
|
|
235
|
+
* @param channel - The linear channel value; clamped into 0-1, so HDR intensity is lost.
|
|
236
|
+
* @returns The sRGB value.
|
|
237
|
+
*/
|
|
238
|
+
static linearToSrgb(channel) {
|
|
239
|
+
const c = clamp01(channel);
|
|
240
|
+
return c <= .0031308 ? c * 12.92 : 1.055 * Math.pow(c, 1 / 2.4) - .055;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Builds a colour from **sRGB** components, converting RGB to linear and taking alpha as-is.
|
|
244
|
+
*
|
|
245
|
+
* @param r - The sRGB red component, 0-1.
|
|
246
|
+
* @param g - The sRGB green component, 0-1.
|
|
247
|
+
* @param b - The sRGB blue component, 0-1.
|
|
248
|
+
* @param a - The alpha component, 0-1. Defaults to 1.
|
|
249
|
+
* @returns A new colour holding linear components. **Allocates.**
|
|
250
|
+
*/
|
|
251
|
+
static fromSrgb(r, g, b, a = 1) {
|
|
252
|
+
return Color.fromSrgbToRef(r, g, b, a, new Color());
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Writes a colour built from **sRGB** components into `out`.
|
|
256
|
+
*
|
|
257
|
+
* @param r - The sRGB red component, 0-1.
|
|
258
|
+
* @param g - The sRGB green component, 0-1.
|
|
259
|
+
* @param b - The sRGB blue component, 0-1.
|
|
260
|
+
* @param a - The alpha component, 0-1.
|
|
261
|
+
* @param out - The colour to write; holds linear components afterwards.
|
|
262
|
+
* @returns `out`.
|
|
263
|
+
*/
|
|
264
|
+
static fromSrgbToRef(r, g, b, a, out) {
|
|
265
|
+
return out.set(Color.srgbToLinear(r), Color.srgbToLinear(g), Color.srgbToLinear(b), a);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Parses an **sRGB** hex string into a linear colour.
|
|
269
|
+
*
|
|
270
|
+
* @param hex - `#rrggbb` or `#rrggbbaa`, with or without the leading `#`, in either case.
|
|
271
|
+
* @returns A new colour, or `null` when the string is not a hex colour. Colours arrive from files
|
|
272
|
+
* and user input, so a bad one is expected absence rather than API misuse (coding standards
|
|
273
|
+
* section 5.5): the caller decides whether to substitute a default or raise a load error.
|
|
274
|
+
* **Allocates.**
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* ```ts
|
|
278
|
+
* const tint = Color.fromHex("#ff8800aa") ?? Color.white();
|
|
279
|
+
* ```
|
|
280
|
+
*/
|
|
281
|
+
static fromHex(hex) {
|
|
282
|
+
const out = new Color();
|
|
283
|
+
return Color.fromHexToRef(hex, out) ? out : null;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Parses an **sRGB** hex string into `out` as linear components.
|
|
287
|
+
*
|
|
288
|
+
* @param hex - `#rrggbb` or `#rrggbbaa`, with or without the leading `#`, in either case.
|
|
289
|
+
* @param out - The colour to write; left untouched when parsing fails.
|
|
290
|
+
* @returns `true` when `hex` was a valid hex colour.
|
|
291
|
+
*/
|
|
292
|
+
static fromHexToRef(hex, out) {
|
|
293
|
+
if (!HEX_PATTERN.test(hex)) return false;
|
|
294
|
+
const body = hex.startsWith("#") ? hex.slice(1) : hex;
|
|
295
|
+
const r = Number.parseInt(body.slice(0, 2), 16) / 255;
|
|
296
|
+
const g = Number.parseInt(body.slice(2, 4), 16) / 255;
|
|
297
|
+
const b = Number.parseInt(body.slice(4, 6), 16) / 255;
|
|
298
|
+
const a = body.length === 8 ? Number.parseInt(body.slice(6, 8), 16) / 255 : 1;
|
|
299
|
+
Color.fromSrgbToRef(r, g, b, a, out);
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Writes the component-wise product `a * b` into `out`, in linear space.
|
|
304
|
+
*
|
|
305
|
+
* @param a - The first colour.
|
|
306
|
+
* @param b - The second colour.
|
|
307
|
+
* @param out - The colour to write; may alias `a` or `b`.
|
|
308
|
+
* @returns `out`.
|
|
309
|
+
*/
|
|
310
|
+
static multiplyToRef(a, b, out) {
|
|
311
|
+
return out.set(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Writes `c` with its RGB scaled and its alpha untouched into `out`.
|
|
315
|
+
*
|
|
316
|
+
* @param c - The colour to scale.
|
|
317
|
+
* @param factor - The intensity factor.
|
|
318
|
+
* @param out - The colour to write; may alias `c`.
|
|
319
|
+
* @returns `out`.
|
|
320
|
+
*/
|
|
321
|
+
static scaleRgbToRef(c, factor, out) {
|
|
322
|
+
return out.set(c.r * factor, c.g * factor, c.b * factor, c.a);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Writes the linear-space interpolation of `a` and `b` into `out`.
|
|
326
|
+
*
|
|
327
|
+
* @param a - The colour written at `t === 0`.
|
|
328
|
+
* @param b - The colour written at `t === 1`.
|
|
329
|
+
* @param t - The interpolant; not clamped.
|
|
330
|
+
* @param out - The colour to write; may alias `a` or `b`.
|
|
331
|
+
* @returns `out`.
|
|
332
|
+
*/
|
|
333
|
+
static lerpToRef(a, b, t, out) {
|
|
334
|
+
return out.set(lerp(a.r, b.r, t), lerp(a.g, b.g, t), lerp(a.b, b.b, t), lerp(a.a, b.a, t));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Compares two colours component by component, with a tolerance.
|
|
338
|
+
*
|
|
339
|
+
* @param a - The first colour.
|
|
340
|
+
* @param b - The second colour.
|
|
341
|
+
* @param epsilon - The largest per-component difference still considered equal.
|
|
342
|
+
* @returns `true` when every component matches within `epsilon`.
|
|
343
|
+
*/
|
|
344
|
+
static equalsWithEpsilon(a, b, epsilon = EPSILON) {
|
|
345
|
+
return Math.abs(a.r - b.r) <= epsilon && Math.abs(a.g - b.g) <= epsilon && Math.abs(a.b - b.b) <= epsilon && Math.abs(a.a - b.a) <= epsilon;
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
//#endregion
|
|
349
|
+
export { Color as t };
|
|
350
|
+
|
|
351
|
+
//# sourceMappingURL=color-DrR6GFTd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-DrR6GFTd.js","names":[],"sources":["../src/math/color.ts"],"sourcesContent":["import { clamp01, EPSILON, lerp } from \"./math-utils.js\";\nimport type { ColorLike } from \"./types.js\";\n\n/**\n * Matches `#rrggbb`, `#rrggbbaa`, and the same two without the leading `#`.\n */\nconst HEX_PATTERN = /^#?(?:[\\da-f]{6}|[\\da-f]{8})$/iu;\n\n/**\n * Formats a 0-255 channel as two lowercase hex digits.\n *\n * @param value - The channel value, already rounded into 0-255.\n * @returns Two hex digits.\n */\nfunction hexByte(value: number): string {\n return value.toString(16).padStart(2, \"0\");\n}\n\n/**\n * An RGBA colour whose components are **linear** and normally in 0-1 (values above 1 are allowed\n * and mean HDR intensity). Lighting maths only works in linear space, which is why this is the\n * space ignifx stores; scene files and hex strings are sRGB, and\n * {@link Color.fromHex}/{@link Color.fromSrgb} are the doors between the two\n * (`docs/architecture/06-serialization-and-scene-format.md` section 3).\n *\n * Every method says which space it works in. The rule of thumb: if it takes or returns a hex string\n * or has `Srgb` in its name, it is sRGB; everything else is linear.\n *\n * @example\n * ```ts\n * const tint = Color.fromHex(\"#ff8800\") ?? new Color(1, 1, 1, 1); // parsed as sRGB, stored linear\n * tint.scaleRgb(2); // twice as bright, same alpha\n * tint.toHex(); // back to sRGB: \"#ffbe00\"\n * ```\n *\n * @public\n */\nexport class Color {\n /** The linear red component. */\n r: number;\n /** The linear green component. */\n g: number;\n /** The linear blue component. */\n b: number;\n /** The alpha component in 0-1. Alpha is always linear, never gamma encoded. */\n a: number;\n\n /**\n * Creates a colour from linear components.\n *\n * @param r - The linear red component. Defaults to 0.\n * @param g - The linear green component. Defaults to 0.\n * @param b - The linear blue component. Defaults to 0.\n * @param a - The alpha component. Defaults to 1 (opaque).\n */\n constructor(r: number = 0, g: number = 0, b: number = 0, a: number = 1) {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n }\n\n /**\n * Assigns every component at once, in linear space.\n *\n * @param r - The new linear red component.\n * @param g - The new linear green component.\n * @param b - The new linear blue component.\n * @param a - The new alpha component.\n * @returns This colour.\n */\n set(r: number, g: number, b: number, a: number): this {\n this.r = r;\n this.g = g;\n this.b = b;\n this.a = a;\n return this;\n }\n\n /**\n * Copies every component from another colour.\n *\n * @param c - The colour to read.\n * @returns This colour.\n */\n copyFrom(c: ColorLike): this {\n this.r = c.r;\n this.g = c.g;\n this.b = c.b;\n this.a = c.a;\n return this;\n }\n\n /**\n * Copies this colour into a new one.\n *\n * @returns A new colour. **Allocates.**\n */\n clone(): Color {\n return new Color(this.r, this.g, this.b, this.a);\n }\n\n /**\n * Multiplies this colour by another, component by component including alpha — the usual way a\n * tint is applied.\n *\n * @param c - The colour to multiply by.\n * @returns This colour.\n */\n multiply(c: ColorLike): this {\n this.r *= c.r;\n this.g *= c.g;\n this.b *= c.b;\n this.a *= c.a;\n return this;\n }\n\n /**\n * Scales the linear RGB components, leaving alpha alone. This is what \"brighter\" means: alpha is\n * coverage, not colour.\n *\n * @param factor - The intensity factor.\n * @returns This colour.\n */\n scaleRgb(factor: number): this {\n this.r *= factor;\n this.g *= factor;\n this.b *= factor;\n return this;\n }\n\n /**\n * Moves this colour towards a target, in linear space (which is where blending belongs; lerping\n * sRGB values darkens midpoints).\n *\n * @param target - The colour reached at `t === 1`.\n * @param t - The interpolant; not clamped.\n * @returns This colour.\n */\n lerp(target: ColorLike, t: number): this {\n return Color.lerpToRef(this, target, t, this);\n }\n\n /**\n * Compares this colour with another, component by component, with a tolerance.\n *\n * @param c - The colour to compare against.\n * @param epsilon - The largest per-component difference still considered equal.\n * @returns `true` when every component matches within `epsilon`.\n */\n equalsWithEpsilon(c: ColorLike, epsilon: number = EPSILON): boolean {\n return Color.equalsWithEpsilon(this, c, epsilon);\n }\n\n /**\n * Writes the **linear** components into a `Float32Array`, the form a shader wants. The output\n * comes first to mirror Babylon Lite's `toArray` helpers.\n *\n * @param out - The array to write into.\n * @param offset - The index of the red component. Defaults to 0.\n * @returns `out`.\n */\n toArray(out: Float32Array, offset: number = 0): Float32Array {\n out[offset] = this.r;\n out[offset + 1] = this.g;\n out[offset + 2] = this.b;\n out[offset + 3] = this.a;\n return out;\n }\n\n /**\n * Writes this colour's **sRGB-encoded** components into `out`, for display, pickers and files.\n * Components are clamped into 0-1 by the encoding curve.\n *\n * @param out - The colour to write; may be this colour. Its fields hold sRGB values afterwards,\n * not linear ones.\n * @returns `out`.\n */\n toSrgbToRef<TOut extends Color>(out: TOut): TOut {\n return out.set(Color.linearToSrgb(this.r), Color.linearToSrgb(this.g), Color.linearToSrgb(this.b), this.a);\n }\n\n /**\n * Encodes this colour as an sRGB hex string.\n *\n * @returns `#rrggbb` for an opaque colour, `#rrggbbaa` when alpha is below 1. **Allocates a\n * string.**\n *\n * @example\n * ```ts\n * new Color(1, 1, 1, 1).toHex(); // \"#ffffff\"\n * ```\n */\n toHex(): string {\n const r = hexByte(Math.round(Color.linearToSrgb(this.r) * 255));\n const g = hexByte(Math.round(Color.linearToSrgb(this.g) * 255));\n const b = hexByte(Math.round(Color.linearToSrgb(this.b) * 255));\n const alpha = clamp01(this.a);\n if (alpha >= 1) {\n return `#${r}${g}${b}`;\n }\n return `#${r}${g}${b}${hexByte(Math.round(alpha * 255))}`;\n }\n\n /**\n * Opaque white.\n *\n * @returns A new linear `(1, 1, 1, 1)`. **Allocates.**\n */\n static white(): Color {\n return new Color(1, 1, 1, 1);\n }\n\n /**\n * Opaque black.\n *\n * @returns A new linear `(0, 0, 0, 1)`. **Allocates.**\n */\n static black(): Color {\n return new Color(0, 0, 0, 1);\n }\n\n /**\n * Fully transparent black.\n *\n * @returns A new linear `(0, 0, 0, 0)`. **Allocates.**\n */\n static transparent(): Color {\n return new Color(0, 0, 0, 0);\n }\n\n /**\n * Copies any colour-shaped value into a `Color`.\n *\n * @param c - The linear colour to copy.\n * @returns A new colour. **Allocates.**\n */\n static from(c: ColorLike): Color {\n return new Color(c.r, c.g, c.b, c.a);\n }\n\n /**\n * Converts one **sRGB** channel to linear, using the IEC 61966-2-1 curve Babylon Lite uses\n * (`lib/math/color.js`).\n *\n * @param channel - The sRGB channel value; clamped into 0-1.\n * @returns The linear value.\n */\n static srgbToLinear(channel: number): number {\n const c = clamp01(channel);\n return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);\n }\n\n /**\n * Converts one **linear** channel to sRGB, the inverse of {@link Color.srgbToLinear}.\n *\n * @param channel - The linear channel value; clamped into 0-1, so HDR intensity is lost.\n * @returns The sRGB value.\n */\n static linearToSrgb(channel: number): number {\n const c = clamp01(channel);\n return c <= 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;\n }\n\n /**\n * Builds a colour from **sRGB** components, converting RGB to linear and taking alpha as-is.\n *\n * @param r - The sRGB red component, 0-1.\n * @param g - The sRGB green component, 0-1.\n * @param b - The sRGB blue component, 0-1.\n * @param a - The alpha component, 0-1. Defaults to 1.\n * @returns A new colour holding linear components. **Allocates.**\n */\n static fromSrgb(r: number, g: number, b: number, a: number = 1): Color {\n return Color.fromSrgbToRef(r, g, b, a, new Color());\n }\n\n /**\n * Writes a colour built from **sRGB** components into `out`.\n *\n * @param r - The sRGB red component, 0-1.\n * @param g - The sRGB green component, 0-1.\n * @param b - The sRGB blue component, 0-1.\n * @param a - The alpha component, 0-1.\n * @param out - The colour to write; holds linear components afterwards.\n * @returns `out`.\n */\n static fromSrgbToRef<TOut extends Color>(r: number, g: number, b: number, a: number, out: TOut): TOut {\n return out.set(Color.srgbToLinear(r), Color.srgbToLinear(g), Color.srgbToLinear(b), a);\n }\n\n /**\n * Parses an **sRGB** hex string into a linear colour.\n *\n * @param hex - `#rrggbb` or `#rrggbbaa`, with or without the leading `#`, in either case.\n * @returns A new colour, or `null` when the string is not a hex colour. Colours arrive from files\n * and user input, so a bad one is expected absence rather than API misuse (coding standards\n * section 5.5): the caller decides whether to substitute a default or raise a load error.\n * **Allocates.**\n *\n * @example\n * ```ts\n * const tint = Color.fromHex(\"#ff8800aa\") ?? Color.white();\n * ```\n */\n static fromHex(hex: string): Color | null {\n const out = new Color();\n return Color.fromHexToRef(hex, out) ? out : null;\n }\n\n /**\n * Parses an **sRGB** hex string into `out` as linear components.\n *\n * @param hex - `#rrggbb` or `#rrggbbaa`, with or without the leading `#`, in either case.\n * @param out - The colour to write; left untouched when parsing fails.\n * @returns `true` when `hex` was a valid hex colour.\n */\n static fromHexToRef(hex: string, out: Color): boolean {\n if (!HEX_PATTERN.test(hex)) {\n return false;\n }\n const body = hex.startsWith(\"#\") ? hex.slice(1) : hex;\n const r = Number.parseInt(body.slice(0, 2), 16) / 255;\n const g = Number.parseInt(body.slice(2, 4), 16) / 255;\n const b = Number.parseInt(body.slice(4, 6), 16) / 255;\n const a = body.length === 8 ? Number.parseInt(body.slice(6, 8), 16) / 255 : 1;\n Color.fromSrgbToRef(r, g, b, a, out);\n return true;\n }\n\n /**\n * Writes the component-wise product `a * b` into `out`, in linear space.\n *\n * @param a - The first colour.\n * @param b - The second colour.\n * @param out - The colour to write; may alias `a` or `b`.\n * @returns `out`.\n */\n static multiplyToRef<TOut extends Color>(a: ColorLike, b: ColorLike, out: TOut): TOut {\n return out.set(a.r * b.r, a.g * b.g, a.b * b.b, a.a * b.a);\n }\n\n /**\n * Writes `c` with its RGB scaled and its alpha untouched into `out`.\n *\n * @param c - The colour to scale.\n * @param factor - The intensity factor.\n * @param out - The colour to write; may alias `c`.\n * @returns `out`.\n */\n static scaleRgbToRef<TOut extends Color>(c: ColorLike, factor: number, out: TOut): TOut {\n return out.set(c.r * factor, c.g * factor, c.b * factor, c.a);\n }\n\n /**\n * Writes the linear-space interpolation of `a` and `b` into `out`.\n *\n * @param a - The colour written at `t === 0`.\n * @param b - The colour written at `t === 1`.\n * @param t - The interpolant; not clamped.\n * @param out - The colour to write; may alias `a` or `b`.\n * @returns `out`.\n */\n static lerpToRef<TOut extends Color>(a: ColorLike, b: ColorLike, t: number, out: TOut): TOut {\n return out.set(lerp(a.r, b.r, t), lerp(a.g, b.g, t), lerp(a.b, b.b, t), lerp(a.a, b.a, t));\n }\n\n /**\n * Compares two colours component by component, with a tolerance.\n *\n * @param a - The first colour.\n * @param b - The second colour.\n * @param epsilon - The largest per-component difference still considered equal.\n * @returns `true` when every component matches within `epsilon`.\n */\n static equalsWithEpsilon(a: ColorLike, b: ColorLike, epsilon: number = EPSILON): boolean {\n return (\n Math.abs(a.r - b.r) <= epsilon &&\n Math.abs(a.g - b.g) <= epsilon &&\n Math.abs(a.b - b.b) <= epsilon &&\n Math.abs(a.a - b.a) <= epsilon\n );\n }\n}\n"],"mappings":";;;;;AAMA,MAAM,cAAc;;;;;;;AAQpB,SAAS,QAAQ,OAAuB;CACtC,OAAO,MAAM,SAAS,EAAE,CAAC,CAAC,SAAS,GAAG,GAAG;AAC3C;;;;;;;;;;;;;;;;;;;;AAqBA,IAAa,QAAb,MAAa,MAAM;;CAEjB;;CAEA;;CAEA;;CAEA;;;;;;;;;CAUA,YAAY,IAAY,GAAG,IAAY,GAAG,IAAY,GAAG,IAAY,GAAG;EACtE,KAAK,IAAI;EACT,KAAK,IAAI;EACT,KAA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K,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;CAC3F;;;;;;;;;CAUA,OAAO,kBAAkB,GAAc,GAAc,UAAkB,SAAkB;EACvF,OACE,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,WACvB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,WACvB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK,WACvB,KAAK,IAAI,EAAE,IAAI,EAAE,CAAC,KAAK;CAE3B;AACF"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { createCopyToTextureTask, createEffectRenderTask, createEffectWrapper, createRenderTargetTexture, disposeEffectWrapper, setEffectTexture, setEffectUniforms } from "@babylonjs/lite";
|
|
2
|
+
//#region src/lite/gpu/effect-task.ts
|
|
3
|
+
/**
|
|
4
|
+
* Creates one fullscreen effect: its shader module, bind-group layout, uniform buffer, and texture
|
|
5
|
+
* slots.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* The binding layout is fixed and shared with the generated WGSL: `0` the uniform block, `1` and `2`
|
|
9
|
+
* the chain's current colour and its sampler, then a texture/sampler pair per declared texture.
|
|
10
|
+
* Nothing is compiled here — Lite builds the pipeline lazily, on the first `record()`.
|
|
11
|
+
*
|
|
12
|
+
* @param engine - The engine that owns the GPU resources.
|
|
13
|
+
* @param options - The shader, the uniform size, and the declared textures.
|
|
14
|
+
* @returns The effect wrapper. Bind its textures before recording a task for it.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
function createCustomEffect(engine, options) {
|
|
19
|
+
const bindings = [
|
|
20
|
+
{
|
|
21
|
+
name: "shaderUniforms",
|
|
22
|
+
binding: 0,
|
|
23
|
+
kind: "uniform",
|
|
24
|
+
uniformByteLength: options.uniformByteLength
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: "inputTexture",
|
|
28
|
+
binding: 1,
|
|
29
|
+
kind: "texture"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "inputTextureSampler",
|
|
33
|
+
binding: 2,
|
|
34
|
+
kind: "sampler",
|
|
35
|
+
textureBinding: 1
|
|
36
|
+
}
|
|
37
|
+
];
|
|
38
|
+
for (let index = 0; index < options.declaredTextures.length; index += 1) {
|
|
39
|
+
const declared = options.declaredTextures[index];
|
|
40
|
+
const binding = 3 + index * 2;
|
|
41
|
+
const layout = {
|
|
42
|
+
name: `texture${String(index)}`,
|
|
43
|
+
binding,
|
|
44
|
+
kind: "texture"
|
|
45
|
+
};
|
|
46
|
+
if (declared?.array === true) bindings.push({
|
|
47
|
+
...layout,
|
|
48
|
+
viewDimension: "2d-array"
|
|
49
|
+
});
|
|
50
|
+
else bindings.push(layout);
|
|
51
|
+
bindings.push({
|
|
52
|
+
name: `sampler${String(index)}`,
|
|
53
|
+
binding: binding + 1,
|
|
54
|
+
kind: "sampler",
|
|
55
|
+
textureBinding: binding
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return createEffectWrapper(engine, {
|
|
59
|
+
name: options.name,
|
|
60
|
+
fragmentWGSL: options.fragmentWGSL,
|
|
61
|
+
bindings
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Binds a texture to one of an effect's texture slots.
|
|
66
|
+
*
|
|
67
|
+
* @remarks
|
|
68
|
+
* Also marks the wrapper's bind group dirty, which is the only thing that does, so this is what has
|
|
69
|
+
* to be called after a link is rebuilt or a declared texture is swapped.
|
|
70
|
+
*
|
|
71
|
+
* @param effect - The effect wrapper.
|
|
72
|
+
* @param binding - The binding index.
|
|
73
|
+
* @param texture - The texture.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
function bindCustomEffectTexture(effect, binding, texture) {
|
|
78
|
+
setEffectTexture(effect, binding, texture);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Uploads an effect's uniform bytes.
|
|
82
|
+
*
|
|
83
|
+
* @remarks
|
|
84
|
+
* A plain `queue.writeBuffer`, so it is safe to call every frame and costs nothing on a frame where
|
|
85
|
+
* the bytes did not change — which is why the caller compares first.
|
|
86
|
+
*
|
|
87
|
+
* @param effect - The effect wrapper.
|
|
88
|
+
* @param data - The bytes; no longer than the declared `uniformByteLength`.
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
function writeCustomEffectUniforms(effect, data) {
|
|
93
|
+
setEffectUniforms(effect, data);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Records one fullscreen effect as a frame-graph task writing `target`.
|
|
97
|
+
*
|
|
98
|
+
* @remarks
|
|
99
|
+
* The task clears its target and draws a fullscreen triangle, so the whole target is overwritten and
|
|
100
|
+
* the clear costs nothing. Append it with `appendPostProcessTask` from `./post-process.ts`.
|
|
101
|
+
*
|
|
102
|
+
* @param engine - The engine.
|
|
103
|
+
* @param scene - The scene whose frame graph will hold it.
|
|
104
|
+
* @param name - A debug label.
|
|
105
|
+
* @param effect - The effect wrapper, with every texture already bound.
|
|
106
|
+
* @param target - The colour target it writes; the surface swapchain for the last effect.
|
|
107
|
+
* @returns The task.
|
|
108
|
+
*
|
|
109
|
+
* @internal
|
|
110
|
+
*/
|
|
111
|
+
function createCustomEffectTask(engine, scene, name, effect, target) {
|
|
112
|
+
return createEffectRenderTask({
|
|
113
|
+
name,
|
|
114
|
+
effect,
|
|
115
|
+
target,
|
|
116
|
+
clear: true
|
|
117
|
+
}, engine, scene);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Frees an effect wrapper's GPU resources.
|
|
121
|
+
*
|
|
122
|
+
* @param effect - The effect wrapper.
|
|
123
|
+
*
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
function disposeCustomEffect(effect) {
|
|
127
|
+
disposeEffectWrapper(effect);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Creates one ping-pong link of an effect chain: a colour target that is also a sampled texture.
|
|
131
|
+
*
|
|
132
|
+
* @remarks
|
|
133
|
+
* Eager and fixed size, which Lite requires of a sampled render target (error 571) and which the
|
|
134
|
+
* chain needs anyway, because an effect wrapper caches the texture view in its bind group. A resize
|
|
135
|
+
* therefore rebuilds the chain rather than reallocating the link.
|
|
136
|
+
*
|
|
137
|
+
* @param engine - The engine that owns the texture.
|
|
138
|
+
* @param format - The colour format; the surface's, so a built-in pass can write it.
|
|
139
|
+
* @param width - The width in backing-store pixels.
|
|
140
|
+
* @param height - The height in backing-store pixels.
|
|
141
|
+
* @param label - A debug label.
|
|
142
|
+
* @returns The link.
|
|
143
|
+
*
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
function createEffectChainLink(engine, format, width, height, label) {
|
|
147
|
+
const created = createRenderTargetTexture(engine, {
|
|
148
|
+
lbl: label,
|
|
149
|
+
format,
|
|
150
|
+
samples: 1,
|
|
151
|
+
size: {
|
|
152
|
+
width: Math.max(1, width),
|
|
153
|
+
height: Math.max(1, height)
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
return {
|
|
157
|
+
target: created.rt,
|
|
158
|
+
texture: created.texture
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Frees a chain link's GPU texture.
|
|
163
|
+
*
|
|
164
|
+
* @remarks
|
|
165
|
+
* `disposeRenderTarget` refuses to free an eager target, which is what keeps
|
|
166
|
+
* `EffectRenderTask.dispose` from destroying a shared link, so the texture has to be destroyed here
|
|
167
|
+
* instead.
|
|
168
|
+
*
|
|
169
|
+
* @param link - The link.
|
|
170
|
+
*
|
|
171
|
+
* @internal
|
|
172
|
+
*/
|
|
173
|
+
function disposeEffectChainLink(link) {
|
|
174
|
+
link.texture.texture.destroy();
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Records a task that copies one colour target into another.
|
|
178
|
+
*
|
|
179
|
+
* @remarks
|
|
180
|
+
* The chain uses it once, and only when its **first** effect is a custom one: the scene colour the
|
|
181
|
+
* render path drew into is a canvas-sized, non-eager `RenderTarget` with no `Texture2D`, so it
|
|
182
|
+
* cannot be sampled by an effect wrapper. One copy into a link makes it samplable. A chain that
|
|
183
|
+
* starts with bloom or SMAA needs no copy, because those write a link directly.
|
|
184
|
+
*
|
|
185
|
+
* @param engine - The engine.
|
|
186
|
+
* @param scene - The scene whose frame graph will hold it.
|
|
187
|
+
* @param name - A debug label.
|
|
188
|
+
* @param source - The target to read.
|
|
189
|
+
* @param target - The target to write; externally owned, so the task does not rebuild or free it.
|
|
190
|
+
* @returns The task.
|
|
191
|
+
*
|
|
192
|
+
* @internal
|
|
193
|
+
*/
|
|
194
|
+
function createChainCopyTask(engine, scene, name, source, target) {
|
|
195
|
+
return createCopyToTextureTask({
|
|
196
|
+
name,
|
|
197
|
+
sourceTexture: source,
|
|
198
|
+
targetTexture: target,
|
|
199
|
+
ownsTargetTexture: false
|
|
200
|
+
}, engine, scene);
|
|
201
|
+
}
|
|
202
|
+
//#endregion
|
|
203
|
+
export { bindCustomEffectTexture, createChainCopyTask, createCustomEffect, createCustomEffectTask, createEffectChainLink, disposeCustomEffect, disposeEffectChainLink, writeCustomEffectUniforms };
|
|
204
|
+
|
|
205
|
+
//# sourceMappingURL=effect-task-CMbuO6Kb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"effect-task-CMbuO6Kb.js","names":[],"sources":["../src/lite/gpu/effect-task.ts"],"sourcesContent":["import {\n createCopyToTextureTask,\n createEffectRenderTask,\n createEffectWrapper,\n createRenderTargetTexture,\n disposeEffectWrapper,\n setEffectTexture,\n setEffectUniforms,\n} from \"@babylonjs/lite\";\nimport type {\n EffectBindingLayout,\n EffectWrapper,\n EngineContext,\n RenderTarget,\n SceneContext,\n Task,\n Texture2D,\n} from \"@babylonjs/lite\";\n\n/**\n * The Babylon Lite half of custom post effects (`docs/plan/2026-09-terrain-particles-shaders.md`\n * §3.3).\n *\n * Everything here is `@internal` and every entry point needs a device.\n *\n * Lite's only public custom-pass path is `createEffectWrapper` + `createEffectRenderTask`\n * (`index.d.ts` 2461, 2452) — the generic `PostProcessTaskConfig` is not exported. The task writes a\n * `RenderTarget` while the wrapper **samples a `Texture2D`**, and a `createRenderTarget` target\n * exposes no `Texture2D`, so a chain that mixes built-ins with custom effects needs links that are\n * both: {@link createEffectChainLink} is `createRenderTargetTexture` (2998), which hands back\n * `{ rt, texture }`.\n *\n * Those links are **eager**, which the chain depends on twice over: an eager target is never\n * reallocated and `disposeRenderTarget` refuses to free one (`lib/engine/render-target.js` 20, 48),\n * so a wrapper's cached bind group cannot end up holding a destroyed view, and an effect that writes\n * the equally eager swapchain can be disposed without destroying it. The price is that a link is\n * fixed size (Lite error 571), so a canvas resize rebuilds the chain.\n *\n * Two more Lite rules: `getEffectPipeline` hard-codes the entry-point names `effectFullscreenVertex`\n * and `effectFragment` and prepends its own vertex module — which declares `EffectVertexOutput` — to\n * the fragment source (`lib/effect/effect-renderer.js` 258-260, 274); and a `sampler` binding with\n * no `textureBinding` falls back to the wrapper's first texture slot (line 342), so\n * {@link createCustomEffect} sets `textureBinding` on every sampler.\n */\n\n/**\n * A Babylon Lite fullscreen effect, re-exported under an ignifx name.\n *\n * @remarks\n * Unstable; excluded from the stability guarantees of `CONSTITUTION.md` Article IV.\n *\n * @internal\n */\nexport type LiteEffect = EffectWrapper;\n\n/**\n * A colour target that is also a sampled texture: what a chain of custom effects ping-pongs through.\n *\n * @internal\n */\nexport interface EffectChainLink {\n /** The render target a task writes. */\n readonly target: RenderTarget;\n /** The sampled texture the next effect reads. */\n readonly texture: Texture2D;\n}\n\n/**\n * What {@link createCustomEffect} needs.\n *\n * @internal\n */\nexport interface CustomEffectOptions {\n /** A debug label for the GPU resources. */\n readonly name: string;\n /** The whole fragment module, including its `effectFragment` entry point. */\n readonly fragmentWGSL: string;\n /** How large the effect's single uniform buffer is, in bytes. */\n readonly uniformByteLength: number;\n /** Whether each declared texture beyond the chain input is a `2d-array` view. */\n readonly declaredTextures: readonly { readonly array: boolean }[];\n}\n\n/**\n * Creates one fullscreen effect: its shader module, bind-group layout, uniform buffer, and texture\n * slots.\n *\n * @remarks\n * The binding layout is fixed and shared with the generated WGSL: `0` the uniform block, `1` and `2`\n * the chain's current colour and its sampler, then a texture/sampler pair per declared texture.\n * Nothing is compiled here — Lite builds the pipeline lazily, on the first `record()`.\n *\n * @param engine - The engine that owns the GPU resources.\n * @param options - The shader, the uniform size, and the declared textures.\n * @returns The effect wrapper. Bind its textures before recording a task for it.\n *\n * @internal\n */\nexport function createCustomEffect(engine: EngineContext, options: CustomEffectOptions): EffectWrapper {\n const bindings: EffectBindingLayout[] = [\n { name: \"shaderUniforms\", binding: 0, kind: \"uniform\", uniformByteLength: options.uniformByteLength },\n { name: \"inputTexture\", binding: 1, kind: \"texture\" },\n { name: \"inputTextureSampler\", binding: 2, kind: \"sampler\", textureBinding: 1 },\n ];\n for (let index = 0; index < options.declaredTextures.length; index += 1) {\n const declared = options.declaredTextures[index];\n const binding = 3 + index * 2;\n const layout: EffectBindingLayout = { name: `texture${String(index)}`, binding, kind: \"texture\" };\n if (declared?.array === true) {\n // The bind-group layout reads `viewDimension` straight off this field\n // (`bindingLayoutEntry`, `lib/effect/effect-renderer.js` 302).\n bindings.push({ ...layout, viewDimension: \"2d-array\" });\n } else {\n bindings.push(layout);\n }\n bindings.push({ name: `sampler${String(index)}`, binding: binding + 1, kind: \"sampler\", textureBinding: binding });\n }\n return createEffectWrapper(engine, { name: options.name, fragmentWGSL: options.fragmentWGSL, bindings });\n}\n\n/**\n * Binds a texture to one of an effect's texture slots.\n *\n * @remarks\n * Also marks the wrapper's bind group dirty, which is the only thing that does, so this is what has\n * to be called after a link is rebuilt or a declared texture is swapped.\n *\n * @param effect - The effect wrapper.\n * @param binding - The binding index.\n * @param texture - The texture.\n *\n * @internal\n */\nexport function bindCustomEffectTexture(effect: EffectWrapper, binding: number, texture: Texture2D): void {\n setEffectTexture(effect, binding, texture);\n}\n\n/**\n * Uploads an effect's uniform bytes.\n *\n * @remarks\n * A plain `queue.writeBuffer`, so it is safe to call every frame and costs nothing on a frame where\n * the bytes did not change — which is why the caller compares first.\n *\n * @param effect - The effect wrapper.\n * @param data - The bytes; no longer than the declared `uniformByteLength`.\n *\n * @internal\n */\nexport function writeCustomEffectUniforms(effect: EffectWrapper, data: Float32Array): void {\n setEffectUniforms(effect, data);\n}\n\n/**\n * Records one fullscreen effect as a frame-graph task writing `target`.\n *\n * @remarks\n * The task clears its target and draws a fullscreen triangle, so the whole target is overwritten and\n * the clear costs nothing. Append it with `appendPostProcessTask` from `./post-process.ts`.\n *\n * @param engine - The engine.\n * @param scene - The scene whose frame graph will hold it.\n * @param name - A debug label.\n * @param effect - The effect wrapper, with every texture already bound.\n * @param target - The colour target it writes; the surface swapchain for the last effect.\n * @returns The task.\n *\n * @internal\n */\nexport function createCustomEffectTask(\n engine: EngineContext,\n scene: SceneContext,\n name: string,\n effect: EffectWrapper,\n target: RenderTarget,\n): Task {\n return createEffectRenderTask({ name, effect, target, clear: true }, engine, scene);\n}\n\n/**\n * Frees an effect wrapper's GPU resources.\n *\n * @param effect - The effect wrapper.\n *\n * @internal\n */\nexport function disposeCustomEffect(effect: EffectWrapper): void {\n disposeEffectWrapper(effect);\n}\n\n/**\n * Creates one ping-pong link of an effect chain: a colour target that is also a sampled texture.\n *\n * @remarks\n * Eager and fixed size, which Lite requires of a sampled render target (error 571) and which the\n * chain needs anyway, because an effect wrapper caches the texture view in its bind group. A resize\n * therefore rebuilds the chain rather than reallocating the link.\n *\n * @param engine - The engine that owns the texture.\n * @param format - The colour format; the surface's, so a built-in pass can write it.\n * @param width - The width in backing-store pixels.\n * @param height - The height in backing-store pixels.\n * @param label - A debug label.\n * @returns The link.\n *\n * @internal\n */\nexport function createEffectChainLink(\n engine: EngineContext,\n format: GPUTextureFormat,\n width: number,\n height: number,\n label: string,\n): EffectChainLink {\n const created = createRenderTargetTexture(engine, {\n lbl: label,\n format,\n samples: 1,\n size: { width: Math.max(1, width), height: Math.max(1, height) },\n });\n return { target: created.rt, texture: created.texture };\n}\n\n/**\n * Frees a chain link's GPU texture.\n *\n * @remarks\n * `disposeRenderTarget` refuses to free an eager target, which is what keeps\n * `EffectRenderTask.dispose` from destroying a shared link, so the texture has to be destroyed here\n * instead.\n *\n * @param link - The link.\n *\n * @internal\n */\nexport function disposeEffectChainLink(link: EffectChainLink): void {\n link.texture.texture.destroy();\n}\n\n/**\n * Records a task that copies one colour target into another.\n *\n * @remarks\n * The chain uses it once, and only when its **first** effect is a custom one: the scene colour the\n * render path drew into is a canvas-sized, non-eager `RenderTarget` with no `Texture2D`, so it\n * cannot be sampled by an effect wrapper. One copy into a link makes it samplable. A chain that\n * starts with bloom or SMAA needs no copy, because those write a link directly.\n *\n * @param engine - The engine.\n * @param scene - The scene whose frame graph will hold it.\n * @param name - A debug label.\n * @param source - The target to read.\n * @param target - The target to write; externally owned, so the task does not rebuild or free it.\n * @returns The task.\n *\n * @internal\n */\nexport function createChainCopyTask(\n engine: EngineContext,\n scene: SceneContext,\n name: string,\n source: RenderTarget,\n target: RenderTarget,\n): Task {\n return createCopyToTextureTask(\n { name, sourceTexture: source, targetTexture: target, ownsTargetTexture: false },\n engine,\n scene,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAkGA,SAAgB,mBAAmB,QAAuB,SAA6C;CACrG,MAAM,WAAkC;EACtC;GAAE,MAAM;GAAkB,SAAS;GAAG,MAAM;GAAW,mBAAmB,QAAQ;EAAkB;EACpG;GAAE,MAAM;GAAgB,SAAS;GAAG,MAAM;EAAU;EACpD;GAAE,MAAM;GAAuB,SAAS;GAAG,MAAM;GAAW,gBAAgB;EAAE;CAChF;CACA,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,iBAAiB,QAAQ,SAAS,GAAG;EACvE,MAAM,WAAW,QAAQ,iBAAiB;EAC1C,MAAM,UAAU,IAAI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