@luma.gl/engine 10.0.0-alpha.11 → 10.0.0-alpha.12
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/dist.dev.js +132 -126
- package/dist/dist.min.js +57 -57
- package/dist/lighting/index.cjs +22 -2
- package/dist/lighting/index.cjs.map +3 -3
- package/dist/lighting/index.d.ts +8 -0
- package/dist/lighting/index.d.ts.map +1 -1
- package/dist/lighting/index.js +4 -0
- package/dist/lighting/index.js.map +1 -1
- package/dist/lighting/lightmap-baker.cjs +238 -0
- package/dist/lighting/lightmap-baker.d.ts +62 -0
- package/dist/lighting/lightmap-baker.d.ts.map +1 -0
- package/dist/lighting/lightmap-baker.js +236 -0
- package/dist/lighting/lightmap-baker.js.map +1 -0
- package/dist/lighting/lightmap-data.cjs +117 -0
- package/dist/lighting/lightmap-data.d.ts +20 -0
- package/dist/lighting/lightmap-data.d.ts.map +1 -0
- package/dist/lighting/lightmap-data.js +110 -0
- package/dist/lighting/lightmap-data.js.map +1 -0
- package/dist/lighting/lightmap-environment.cjs +61 -0
- package/dist/lighting/lightmap-environment.d.ts +18 -0
- package/dist/lighting/lightmap-environment.d.ts.map +1 -0
- package/dist/lighting/lightmap-environment.js +46 -0
- package/dist/lighting/lightmap-environment.js.map +1 -0
- package/dist/lighting/pbr-model.cjs +70 -0
- package/dist/lighting/pbr-model.d.ts +5 -1
- package/dist/lighting/pbr-model.d.ts.map +1 -1
- package/dist/lighting/pbr-model.js +71 -1
- package/dist/lighting/pbr-model.js.map +1 -1
- package/dist/lighting/shadow-map-renderer.cjs +7 -3
- package/dist/lighting/shadow-map-renderer.d.ts +1 -1
- package/dist/lighting/shadow-map-renderer.d.ts.map +1 -1
- package/dist/lighting/shadow-map-renderer.js +8 -3
- package/dist/lighting/shadow-map-renderer.js.map +1 -1
- package/package.json +8 -8
- package/src/lighting/index.ts +19 -0
- package/src/lighting/lightmap-baker.ts +306 -0
- package/src/lighting/lightmap-data.ts +138 -0
- package/src/lighting/lightmap-environment.ts +70 -0
- package/src/lighting/pbr-model.ts +78 -1
- package/src/lighting/shadow-map-renderer.ts +12 -3
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var lightmap_data_exports = {};
|
|
19
|
+
__export(lightmap_data_exports, {
|
|
20
|
+
createLightmapFromData: () => createLightmapFromData,
|
|
21
|
+
decodeLightmapData: () => decodeLightmapData,
|
|
22
|
+
encodeLightmapData: () => encodeLightmapData,
|
|
23
|
+
readLightmapData: () => readLightmapData
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(lightmap_data_exports);
|
|
26
|
+
var import_core = require("@luma.gl/core");
|
|
27
|
+
var import_shaders = require("@luma.gl/shaders");
|
|
28
|
+
var import_lightmap_baker = require("./lightmap-baker.cjs");
|
|
29
|
+
async function readLightmapData(texture, uvSet = 1) {
|
|
30
|
+
(0, import_core.assert)(!texture.destroyed && texture.dimension === "2d" && texture.samples === 1 && (uvSet === 0 || uvSet === 1) && (texture.format === "rgba16float" || texture.format === "rgba32float"));
|
|
31
|
+
const bytesPerPixel = texture.format === "rgba16float" ? 8 : 16;
|
|
32
|
+
const rowBytes = texture.computeMemoryLayout().bytesPerRow;
|
|
33
|
+
const buffer = texture.device.createBuffer({
|
|
34
|
+
byteLength: rowBytes * texture.height,
|
|
35
|
+
usage: import_core.Buffer.COPY_DST | import_core.Buffer.MAP_READ
|
|
36
|
+
});
|
|
37
|
+
try {
|
|
38
|
+
texture.device.submit();
|
|
39
|
+
texture.readBuffer({ x: 0, y: 0, width: texture.width, height: texture.height }, buffer);
|
|
40
|
+
texture.device.submit();
|
|
41
|
+
const bytes = await buffer.readAsync();
|
|
42
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
43
|
+
const data = new Float32Array(texture.width * texture.height * 4);
|
|
44
|
+
for (let row = 0; row < texture.height; row++) {
|
|
45
|
+
for (let component = 0; component < texture.width * 4; component++) {
|
|
46
|
+
const offset = row * rowBytes + component * bytesPerPixel / 4;
|
|
47
|
+
if (bytesPerPixel === 16)
|
|
48
|
+
data[row * texture.width * 4 + component] = view.getFloat32(offset, true);
|
|
49
|
+
else {
|
|
50
|
+
data[row * texture.width * 4 + component] = (0, import_shaders.fromHalfFloat)(view.getUint16(offset, true));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
version: 1,
|
|
56
|
+
width: texture.width,
|
|
57
|
+
height: texture.height,
|
|
58
|
+
encoding: "linear-irradiance",
|
|
59
|
+
uvSet,
|
|
60
|
+
data
|
|
61
|
+
};
|
|
62
|
+
} finally {
|
|
63
|
+
buffer.destroy();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function createLightmapFromData(device, lightmap, format = "rgba16float") {
|
|
67
|
+
(0, import_core.assert)(lightmap.version === 1 && lightmap.encoding === "linear-irradiance");
|
|
68
|
+
(0, import_core.assert)(Number.isInteger(lightmap.width) && lightmap.width > 0 && lightmap.width <= 4294967295 && Number.isInteger(lightmap.height) && lightmap.height > 0 && lightmap.height <= 4294967295);
|
|
69
|
+
(0, import_core.assert)(lightmap.data.length === lightmap.width * lightmap.height * 4);
|
|
70
|
+
(0, import_core.assert)(lightmap.uvSet === 0 || lightmap.uvSet === 1);
|
|
71
|
+
(0, import_core.assert)(device.getTextureFormatCapabilities(format).filter);
|
|
72
|
+
for (const value of lightmap.data)
|
|
73
|
+
(0, import_core.assert)(Number.isFinite(value) && (format !== "rgba16float" || Math.abs(value) <= 65504));
|
|
74
|
+
const data = format === "rgba16float" ? Uint16Array.from(lightmap.data, import_shaders.toHalfFloat) : lightmap.data;
|
|
75
|
+
return new import_lightmap_baker.LightmapBakeResult(device.createTexture({
|
|
76
|
+
width: lightmap.width,
|
|
77
|
+
height: lightmap.height,
|
|
78
|
+
format,
|
|
79
|
+
data,
|
|
80
|
+
sampler: format === "rgba16float" ? { minFilter: "linear", magFilter: "linear" } : { minFilter: "nearest", magFilter: "nearest" },
|
|
81
|
+
usage: import_core.Texture.SAMPLE | import_core.Texture.COPY_DST | import_core.Texture.COPY_SRC
|
|
82
|
+
}));
|
|
83
|
+
}
|
|
84
|
+
function encodeLightmapData(lightmap) {
|
|
85
|
+
(0, import_core.assert)(lightmap.version === 1 && lightmap.encoding === "linear-irradiance");
|
|
86
|
+
(0, import_core.assert)(Number.isInteger(lightmap.width) && lightmap.width > 0 && lightmap.width <= 4294967295 && Number.isInteger(lightmap.height) && lightmap.height > 0 && lightmap.height <= 4294967295);
|
|
87
|
+
(0, import_core.assert)(lightmap.uvSet === 0 || lightmap.uvSet === 1);
|
|
88
|
+
(0, import_core.assert)(lightmap.data.length === lightmap.width * lightmap.height * 4);
|
|
89
|
+
const buffer = new ArrayBuffer(16 + lightmap.data.length * 4);
|
|
90
|
+
const view = new DataView(buffer);
|
|
91
|
+
view.setUint32(0, 827084108, true);
|
|
92
|
+
view.setUint32(4, lightmap.width, true);
|
|
93
|
+
view.setUint32(8, lightmap.height, true);
|
|
94
|
+
view.setUint32(12, lightmap.uvSet, true);
|
|
95
|
+
lightmap.data.forEach((value, index) => view.setFloat32(16 + index * 4, value, true));
|
|
96
|
+
return buffer;
|
|
97
|
+
}
|
|
98
|
+
function decodeLightmapData(buffer) {
|
|
99
|
+
(0, import_core.assert)(buffer.byteLength >= 16);
|
|
100
|
+
const view = new DataView(buffer);
|
|
101
|
+
(0, import_core.assert)(view.getUint32(0, true) === 827084108);
|
|
102
|
+
const width = view.getUint32(4, true), height = view.getUint32(8, true), uvSet = view.getUint32(12, true);
|
|
103
|
+
(0, import_core.assert)(width > 0 && height > 0 && (uvSet === 0 || uvSet === 1));
|
|
104
|
+
const length = width * height * 4;
|
|
105
|
+
(0, import_core.assert)(Number.isSafeInteger(length) && buffer.byteLength === 16 + length * 4);
|
|
106
|
+
const data = new Float32Array(length);
|
|
107
|
+
for (let index = 0; index < length; index++)
|
|
108
|
+
data[index] = view.getFloat32(16 + index * 4, true);
|
|
109
|
+
return { version: 1, width, height, encoding: "linear-irradiance", uvSet, data };
|
|
110
|
+
}
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
createLightmapFromData,
|
|
114
|
+
decodeLightmapData,
|
|
115
|
+
encodeLightmapData,
|
|
116
|
+
readLightmapData
|
|
117
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Texture, type Device } from '@luma.gl/core';
|
|
2
|
+
import { LightmapBakeResult } from "./lightmap-baker.js";
|
|
3
|
+
/** Portable linear irradiance E, with chart coverage in alpha. Rows follow texture upload order. */
|
|
4
|
+
export type LightmapData = {
|
|
5
|
+
version: 1;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
encoding: 'linear-irradiance';
|
|
9
|
+
uvSet: 0 | 1;
|
|
10
|
+
data: Float32Array;
|
|
11
|
+
};
|
|
12
|
+
/** Explicit asynchronous readback. Submits pending work, including result copies. */
|
|
13
|
+
export declare function readLightmapData(texture: Texture, uvSet?: 0 | 1): Promise<LightmapData>;
|
|
14
|
+
/** Uploads an independent owned texture. Input CPU data remains caller-owned. */
|
|
15
|
+
export declare function createLightmapFromData(device: Device, lightmap: LightmapData, format?: 'rgba16float' | 'rgba32float'): LightmapBakeResult;
|
|
16
|
+
/** Encodes LML1: four little-endian uint32 header words followed by linear float32 RGBA. */
|
|
17
|
+
export declare function encodeLightmapData(lightmap: LightmapData): ArrayBuffer;
|
|
18
|
+
/** Decodes an independently owned CPU copy; no image decoding, fetching or GPU allocation. */
|
|
19
|
+
export declare function decodeLightmapData(buffer: ArrayBuffer): LightmapData;
|
|
20
|
+
//# sourceMappingURL=lightmap-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightmap-data.d.ts","sourceRoot":"","sources":["../../src/lighting/lightmap-data.ts"],"names":[],"mappings":"AAGA,OAAO,EAAiB,OAAO,EAAE,KAAK,MAAM,EAAC,MAAM,eAAe,CAAC;AAEnE,OAAO,EAAC,kBAAkB,EAAC,4BAAyB;AAEpD,oGAAoG;AACpG,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,CAAC,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,mBAAmB,CAAC;IAC9B,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IACb,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,qFAAqF;AACrF,wBAAsB,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,GAAE,CAAC,GAAG,CAAK,GAAG,OAAO,CAAC,YAAY,CAAC,CA0ChG;AAED,iFAAiF;AACjF,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,YAAY,EACtB,MAAM,GAAE,aAAa,GAAG,aAA6B,GACpD,kBAAkB,CA+BpB;AAED,4FAA4F;AAC5F,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,YAAY,GAAG,WAAW,CAoBtE;AAED,8FAA8F;AAC9F,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CAapE"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
3
|
+
import { assert, Buffer, Texture } from '@luma.gl/core';
|
|
4
|
+
import { fromHalfFloat, toHalfFloat } from '@luma.gl/shaders';
|
|
5
|
+
import { LightmapBakeResult } from "./lightmap-baker.js";
|
|
6
|
+
/** Explicit asynchronous readback. Submits pending work, including result copies. */
|
|
7
|
+
export async function readLightmapData(texture, uvSet = 1) {
|
|
8
|
+
assert(!texture.destroyed &&
|
|
9
|
+
texture.dimension === '2d' &&
|
|
10
|
+
texture.samples === 1 &&
|
|
11
|
+
(uvSet === 0 || uvSet === 1) &&
|
|
12
|
+
(texture.format === 'rgba16float' || texture.format === 'rgba32float'));
|
|
13
|
+
const bytesPerPixel = texture.format === 'rgba16float' ? 8 : 16;
|
|
14
|
+
const rowBytes = texture.computeMemoryLayout().bytesPerRow;
|
|
15
|
+
const buffer = texture.device.createBuffer({
|
|
16
|
+
byteLength: rowBytes * texture.height,
|
|
17
|
+
usage: Buffer.COPY_DST | Buffer.MAP_READ
|
|
18
|
+
});
|
|
19
|
+
try {
|
|
20
|
+
texture.device.submit();
|
|
21
|
+
texture.readBuffer({ x: 0, y: 0, width: texture.width, height: texture.height }, buffer);
|
|
22
|
+
texture.device.submit();
|
|
23
|
+
const bytes = await buffer.readAsync();
|
|
24
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
25
|
+
const data = new Float32Array(texture.width * texture.height * 4);
|
|
26
|
+
for (let row = 0; row < texture.height; row++) {
|
|
27
|
+
for (let component = 0; component < texture.width * 4; component++) {
|
|
28
|
+
const offset = row * rowBytes + (component * bytesPerPixel) / 4;
|
|
29
|
+
if (bytesPerPixel === 16)
|
|
30
|
+
data[row * texture.width * 4 + component] = view.getFloat32(offset, true);
|
|
31
|
+
else {
|
|
32
|
+
data[row * texture.width * 4 + component] = fromHalfFloat(view.getUint16(offset, true));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
version: 1,
|
|
38
|
+
width: texture.width,
|
|
39
|
+
height: texture.height,
|
|
40
|
+
encoding: 'linear-irradiance',
|
|
41
|
+
uvSet,
|
|
42
|
+
data
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
finally {
|
|
46
|
+
buffer.destroy();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/** Uploads an independent owned texture. Input CPU data remains caller-owned. */
|
|
50
|
+
export function createLightmapFromData(device, lightmap, format = 'rgba16float') {
|
|
51
|
+
assert(lightmap.version === 1 && lightmap.encoding === 'linear-irradiance');
|
|
52
|
+
assert(Number.isInteger(lightmap.width) &&
|
|
53
|
+
lightmap.width > 0 &&
|
|
54
|
+
lightmap.width <= 0xffffffff &&
|
|
55
|
+
Number.isInteger(lightmap.height) &&
|
|
56
|
+
lightmap.height > 0 &&
|
|
57
|
+
lightmap.height <= 0xffffffff);
|
|
58
|
+
assert(lightmap.data.length === lightmap.width * lightmap.height * 4);
|
|
59
|
+
assert(lightmap.uvSet === 0 || lightmap.uvSet === 1);
|
|
60
|
+
assert(device.getTextureFormatCapabilities(format).filter);
|
|
61
|
+
// Half-float uploads round explicitly but must not silently saturate HDR values.
|
|
62
|
+
for (const value of lightmap.data)
|
|
63
|
+
assert(Number.isFinite(value) && (format !== 'rgba16float' || Math.abs(value) <= 65504));
|
|
64
|
+
const data = format === 'rgba16float' ? Uint16Array.from(lightmap.data, toHalfFloat) : lightmap.data;
|
|
65
|
+
return new LightmapBakeResult(device.createTexture({
|
|
66
|
+
width: lightmap.width,
|
|
67
|
+
height: lightmap.height,
|
|
68
|
+
format,
|
|
69
|
+
data,
|
|
70
|
+
sampler: format === 'rgba16float'
|
|
71
|
+
? { minFilter: 'linear', magFilter: 'linear' }
|
|
72
|
+
: { minFilter: 'nearest', magFilter: 'nearest' },
|
|
73
|
+
usage: Texture.SAMPLE | Texture.COPY_DST | Texture.COPY_SRC
|
|
74
|
+
}));
|
|
75
|
+
}
|
|
76
|
+
/** Encodes LML1: four little-endian uint32 header words followed by linear float32 RGBA. */
|
|
77
|
+
export function encodeLightmapData(lightmap) {
|
|
78
|
+
assert(lightmap.version === 1 && lightmap.encoding === 'linear-irradiance');
|
|
79
|
+
assert(Number.isInteger(lightmap.width) &&
|
|
80
|
+
lightmap.width > 0 &&
|
|
81
|
+
lightmap.width <= 0xffffffff &&
|
|
82
|
+
Number.isInteger(lightmap.height) &&
|
|
83
|
+
lightmap.height > 0 &&
|
|
84
|
+
lightmap.height <= 0xffffffff);
|
|
85
|
+
assert(lightmap.uvSet === 0 || lightmap.uvSet === 1);
|
|
86
|
+
assert(lightmap.data.length === lightmap.width * lightmap.height * 4);
|
|
87
|
+
const buffer = new ArrayBuffer(16 + lightmap.data.length * 4);
|
|
88
|
+
const view = new DataView(buffer);
|
|
89
|
+
view.setUint32(0, 0x314c4d4c, true);
|
|
90
|
+
view.setUint32(4, lightmap.width, true);
|
|
91
|
+
view.setUint32(8, lightmap.height, true);
|
|
92
|
+
view.setUint32(12, lightmap.uvSet, true);
|
|
93
|
+
lightmap.data.forEach((value, index) => view.setFloat32(16 + index * 4, value, true));
|
|
94
|
+
return buffer;
|
|
95
|
+
}
|
|
96
|
+
/** Decodes an independently owned CPU copy; no image decoding, fetching or GPU allocation. */
|
|
97
|
+
export function decodeLightmapData(buffer) {
|
|
98
|
+
assert(buffer.byteLength >= 16);
|
|
99
|
+
const view = new DataView(buffer);
|
|
100
|
+
assert(view.getUint32(0, true) === 0x314c4d4c);
|
|
101
|
+
const width = view.getUint32(4, true), height = view.getUint32(8, true), uvSet = view.getUint32(12, true);
|
|
102
|
+
assert(width > 0 && height > 0 && (uvSet === 0 || uvSet === 1));
|
|
103
|
+
const length = width * height * 4;
|
|
104
|
+
assert(Number.isSafeInteger(length) && buffer.byteLength === 16 + length * 4);
|
|
105
|
+
const data = new Float32Array(length);
|
|
106
|
+
for (let index = 0; index < length; index++)
|
|
107
|
+
data[index] = view.getFloat32(16 + index * 4, true);
|
|
108
|
+
return { version: 1, width, height, encoding: 'linear-irradiance', uvSet, data };
|
|
109
|
+
}
|
|
110
|
+
//# sourceMappingURL=lightmap-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightmap-data.js","sourceRoot":"","sources":["../../src/lighting/lightmap-data.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAc,MAAM,eAAe,CAAC;AACnE,OAAO,EAAC,aAAa,EAAE,WAAW,EAAC,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAC,kBAAkB,EAAC,4BAAyB;AAYpD,qFAAqF;AACrF,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAgB,EAAE,QAAe,CAAC;IACvE,MAAM,CACJ,CAAC,OAAO,CAAC,SAAS;QAChB,OAAO,CAAC,SAAS,KAAK,IAAI;QAC1B,OAAO,CAAC,OAAO,KAAK,CAAC;QACrB,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC;QAC5B,CAAC,OAAO,CAAC,MAAM,KAAK,aAAa,IAAI,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,CACzE,CAAC;IACF,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,KAAK,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAChE,MAAM,QAAQ,GAAG,OAAO,CAAC,mBAAmB,EAAE,CAAC,WAAW,CAAC;IAC3D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;QACzC,UAAU,EA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M,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,EACnC,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,IAAI,CAAC,EAChC,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC,KAAK,GAAG,CAAC,IAAI,MAAM,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC;IAChE,MAAM,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC;IAClC,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,KAAK,EAAE,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9E,MAAM,IAAI,GAAG,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC;IACtC,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE;QAAE,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,UAAU,CAAC,EAAE,GAAG,KAAK,GAAG,CAAC,EAAE,IAAI,CAAC,CAAC;IACjG,OAAO,EAAC,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,KAAK,EAAE,IAAI,EAAC,CAAC;AACjF,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var lightmap_environment_exports = {};
|
|
19
|
+
__export(lightmap_environment_exports, {
|
|
20
|
+
sampleLightmapEnvironment: () => sampleLightmapEnvironment
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(lightmap_environment_exports);
|
|
23
|
+
var import_core = require("@luma.gl/core");
|
|
24
|
+
function sampleLightmapEnvironment(environment, sampleIndex, sampleCount) {
|
|
25
|
+
(0, import_core.assert)(Number.isInteger(environment.width) && environment.width > 0 && Number.isInteger(environment.height) && environment.height > 0);
|
|
26
|
+
(0, import_core.assert)(environment.data.length === environment.width * environment.height * 3);
|
|
27
|
+
(0, import_core.assert)(Number.isInteger(sampleCount) && sampleCount > 0 && Number.isInteger(sampleIndex) && sampleIndex >= 0 && sampleIndex < sampleCount);
|
|
28
|
+
let reversed = 0;
|
|
29
|
+
let fraction = 0.5;
|
|
30
|
+
for (let remaining = sampleIndex; remaining > 0; remaining = Math.floor(remaining / 2)) {
|
|
31
|
+
reversed += remaining % 2 * fraction;
|
|
32
|
+
fraction *= 0.5;
|
|
33
|
+
}
|
|
34
|
+
const vertical = 1 - 2 * (sampleIndex + 0.5) / sampleCount;
|
|
35
|
+
const longitude = 2 * Math.PI * reversed;
|
|
36
|
+
const radius = Math.sqrt(Math.max(0, 1 - vertical * vertical));
|
|
37
|
+
const directionToLight = [
|
|
38
|
+
radius * Math.cos(longitude),
|
|
39
|
+
vertical,
|
|
40
|
+
radius * Math.sin(longitude)
|
|
41
|
+
];
|
|
42
|
+
const column = Math.min(environment.width - 1, Math.floor(reversed * environment.width));
|
|
43
|
+
const row = Math.min(environment.height - 1, Math.floor(Math.acos(vertical) / Math.PI * environment.height));
|
|
44
|
+
const offset = (row * environment.width + column) * 3;
|
|
45
|
+
return {
|
|
46
|
+
directionToLight,
|
|
47
|
+
light: {
|
|
48
|
+
type: "directional",
|
|
49
|
+
direction: [-directionToLight[0], -directionToLight[1], -directionToLight[2]],
|
|
50
|
+
color: [
|
|
51
|
+
environment.data[offset] * 4 * Math.PI,
|
|
52
|
+
environment.data[offset + 1] * 4 * Math.PI,
|
|
53
|
+
environment.data[offset + 2] * 4 * Math.PI
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
sampleLightmapEnvironment
|
|
61
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Linear RGB equirectangular radiance. Row zero is the north pole; longitude zero points +X. */
|
|
2
|
+
export type LightmapEnvironment = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
data: Float32Array;
|
|
6
|
+
};
|
|
7
|
+
export type LightmapEnvironmentSample = {
|
|
8
|
+
/** Direction from the surface toward the sampled environment, usable by shadow preparation. */
|
|
9
|
+
directionToLight: [number, number, number];
|
|
10
|
+
light: {
|
|
11
|
+
type: 'directional';
|
|
12
|
+
direction: [number, number, number];
|
|
13
|
+
color: [number, number, number];
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
/** Uniform solid-angle quadrature for a fixed sample budget. Use lighting.useByteColors=false. */
|
|
17
|
+
export declare function sampleLightmapEnvironment(environment: LightmapEnvironment, sampleIndex: number, sampleCount: number): LightmapEnvironmentSample;
|
|
18
|
+
//# sourceMappingURL=lightmap-environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightmap-environment.d.ts","sourceRoot":"","sources":["../../src/lighting/lightmap-environment.ts"],"names":[],"mappings":"AAKA,iGAAiG;AACjG,MAAM,MAAM,mBAAmB,GAAG;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,YAAY,CAAA;CAAC,CAAC;AACtF,MAAM,MAAM,yBAAyB,GAAG;IACtC,+FAA+F;IAC/F,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3C,KAAK,EAAE;QACL,IAAI,EAAE,aAAa,CAAC;QACpB,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QACpC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;KACjC,CAAC;CACH,CAAC;AAEF,kGAAkG;AAClG,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,mBAAmB,EAChC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,yBAAyB,CA+C3B"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
3
|
+
import { assert } from '@luma.gl/core';
|
|
4
|
+
/** Uniform solid-angle quadrature for a fixed sample budget. Use lighting.useByteColors=false. */
|
|
5
|
+
export function sampleLightmapEnvironment(environment, sampleIndex, sampleCount) {
|
|
6
|
+
assert(Number.isInteger(environment.width) &&
|
|
7
|
+
environment.width > 0 &&
|
|
8
|
+
Number.isInteger(environment.height) &&
|
|
9
|
+
environment.height > 0);
|
|
10
|
+
assert(environment.data.length === environment.width * environment.height * 3);
|
|
11
|
+
assert(Number.isInteger(sampleCount) &&
|
|
12
|
+
sampleCount > 0 &&
|
|
13
|
+
Number.isInteger(sampleIndex) &&
|
|
14
|
+
sampleIndex >= 0 &&
|
|
15
|
+
sampleIndex < sampleCount);
|
|
16
|
+
let reversed = 0;
|
|
17
|
+
let fraction = 0.5;
|
|
18
|
+
for (let remaining = sampleIndex; remaining > 0; remaining = Math.floor(remaining / 2)) {
|
|
19
|
+
reversed += (remaining % 2) * fraction;
|
|
20
|
+
fraction *= 0.5;
|
|
21
|
+
}
|
|
22
|
+
const vertical = 1 - (2 * (sampleIndex + 0.5)) / sampleCount;
|
|
23
|
+
const longitude = 2 * Math.PI * reversed;
|
|
24
|
+
const radius = Math.sqrt(Math.max(0, 1 - vertical * vertical));
|
|
25
|
+
const directionToLight = [
|
|
26
|
+
radius * Math.cos(longitude),
|
|
27
|
+
vertical,
|
|
28
|
+
radius * Math.sin(longitude)
|
|
29
|
+
];
|
|
30
|
+
const column = Math.min(environment.width - 1, Math.floor(reversed * environment.width));
|
|
31
|
+
const row = Math.min(environment.height - 1, Math.floor((Math.acos(vertical) / Math.PI) * environment.height));
|
|
32
|
+
const offset = (row * environment.width + column) * 3;
|
|
33
|
+
return {
|
|
34
|
+
directionToLight,
|
|
35
|
+
light: {
|
|
36
|
+
type: 'directional',
|
|
37
|
+
direction: [-directionToLight[0], -directionToLight[1], -directionToLight[2]],
|
|
38
|
+
color: [
|
|
39
|
+
environment.data[offset] * 4 * Math.PI,
|
|
40
|
+
environment.data[offset + 1] * 4 * Math.PI,
|
|
41
|
+
environment.data[offset + 2] * 4 * Math.PI
|
|
42
|
+
]
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=lightmap-environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightmap-environment.js","sourceRoot":"","sources":["../../src/lighting/lightmap-environment.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EAAC,MAAM,EAAC,MAAM,eAAe,CAAC;AAcrC,kGAAkG;AAClG,MAAM,UAAU,yBAAyB,CACvC,WAAgC,EAChC,WAAmB,EACnB,WAAmB;IAEnB,MAAM,CAC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=> PBR_MODEL_WGSL_SHADER,
|
|
21
|
+
createPBRLightmapModel: () => createPBRLightmapModel,
|
|
21
22
|
createPBRModel: () => createPBRModel,
|
|
22
23
|
createPBRShadowModel: () => createPBRShadowModel,
|
|
23
24
|
createPBRSurfaceModel: () => createPBRSurfaceModel,
|
|
@@ -26,6 +27,7 @@ __export(pbr_model_exports, {
|
|
|
26
27
|
getPBRTextureDefines: () => getPBRTextureDefines
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(pbr_model_exports);
|
|
30
|
+
var import_core = require("@luma.gl/core");
|
|
29
31
|
var import_model = require("../model/model.cjs");
|
|
30
32
|
var import_shaders = require("@luma.gl/shaders");
|
|
31
33
|
function getPBRModelWGSL(hooks = {}) {
|
|
@@ -150,6 +152,10 @@ ${hooks.instanceTransform ?? ""} position = instanceMatrix * position;
|
|
|
150
152
|
tangent = vec4f(normalize((pbrProjection.modelMatrix * vec4f(tangent.xyz, 0.0)).xyz), tangent.w * sign(determinant(mat3x3f(pbrProjection.modelMatrix[0].xyz, pbrProjection.modelMatrix[1].xyz, pbrProjection.modelMatrix[2].xyz))));
|
|
151
153
|
#endif
|
|
152
154
|
outputs.position = pbrProjection.modelViewProjectionMatrix * position;
|
|
155
|
+
#ifdef PBR_LIGHTMAP_PASS
|
|
156
|
+
let atlasUV = (lightmapBake.uvTransform * vec3f(select(textureCoordinates, secondTextureCoordinates, lightmapBake.uvSet == 1), 1.0)).xy;
|
|
157
|
+
outputs.position = vec4f(atlasUV.x * 2.0 - 1.0, 1.0 - atlasUV.y * 2.0, 0.0, 1.0);
|
|
158
|
+
#endif
|
|
153
159
|
${hooks.vertexOutput ?? ""}
|
|
154
160
|
outputs.pbrPosition = worldPosition.xyz / worldPosition.w;
|
|
155
161
|
outputs.pbrUV0 = textureCoordinates;
|
|
@@ -182,6 +188,24 @@ ${hooks.fragmentReturnType ?? `#ifndef PBR_SHADOW_PASS
|
|
|
182
188
|
fragmentInputs.pbr_vTBN = mat3x3f(tangent, bitangent, inputs.pbrNormal);
|
|
183
189
|
#endif
|
|
184
190
|
${hooks.fragmentBody ?? `
|
|
191
|
+
#ifdef PBR_LIGHTMAP_PASS
|
|
192
|
+
pbr_discardMaskedFragment(inputs.pbrColor);
|
|
193
|
+
var directionalVisibility = 1.0;
|
|
194
|
+
var pointVisibility = vec4f(1.0);
|
|
195
|
+
var spotVisibility = vec4f(1.0);
|
|
196
|
+
let normal = normalize(inputs.pbrNormal);
|
|
197
|
+
#ifdef PBR_RECEIVE_SHADOWS
|
|
198
|
+
if (pbrShadow.enabled != 0) {
|
|
199
|
+
let viewDepth = -(pbrShadow.viewMatrix * vec4f(inputs.pbrPosition, 1.0)).z;
|
|
200
|
+
directionalVisibility = shadow_getDirectionalFactor(inputs.pbrPosition, normal, viewDepth);
|
|
201
|
+
for (var index = 0; index < 4; index++) {
|
|
202
|
+
pointVisibility[index] = shadow_getPointFactor(index, inputs.pbrPosition, normal);
|
|
203
|
+
spotVisibility[index] = shadow_getSpotFactor(index, inputs.pbrPosition, normal);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
#endif
|
|
207
|
+
return vec4f(lightmap_getIrradiance(inputs.pbrPosition, normal, directionalVisibility, pointVisibility, spotVisibility), lightmapBake.chartId);
|
|
208
|
+
#else
|
|
185
209
|
#ifdef PBR_SHADOW_PASS
|
|
186
210
|
pbr_discardMaskedFragment(inputs.pbrColor);
|
|
187
211
|
#else
|
|
@@ -220,6 +244,7 @@ ${hooks.fragmentBody ?? `
|
|
|
220
244
|
#endif
|
|
221
245
|
#endif
|
|
222
246
|
#endif
|
|
247
|
+
#endif
|
|
223
248
|
`}
|
|
224
249
|
}
|
|
225
250
|
`
|
|
@@ -317,6 +342,10 @@ void main(void) {
|
|
|
317
342
|
secondTextureCoordinates
|
|
318
343
|
);
|
|
319
344
|
gl_Position = pbrProjection.modelViewProjectionMatrix * position;
|
|
345
|
+
#ifdef PBR_LIGHTMAP_PASS
|
|
346
|
+
vec2 atlasUV = (lightmapBake.uvTransform * vec3(lightmapBake.uvSet == 1 ? secondTextureCoordinates : textureCoordinates, 1.0)).xy;
|
|
347
|
+
gl_Position = vec4(atlasUV * 2.0 - 1.0, 0.0, 1.0);
|
|
348
|
+
#endif
|
|
320
349
|
#ifdef PBR_SHADOW_PASS
|
|
321
350
|
// ShadowMapRenderer light projections use [0, 1] depth on both backends.
|
|
322
351
|
gl_Position.z = gl_Position.z * 2.0 - gl_Position.w;
|
|
@@ -333,6 +362,28 @@ out vec4 fragmentColor;
|
|
|
333
362
|
#endif
|
|
334
363
|
|
|
335
364
|
void main(void) {
|
|
365
|
+
#ifdef PBR_LIGHTMAP_PASS
|
|
366
|
+
pbr_discardMaskedFragment(sceneVertexColor);
|
|
367
|
+
#ifdef HAS_TANGENTS
|
|
368
|
+
vec3 normal = normalize(pbr_vTBN[2]);
|
|
369
|
+
#else
|
|
370
|
+
vec3 normal = normalize(pbr_vNormal);
|
|
371
|
+
#endif
|
|
372
|
+
float directionalVisibility = 1.0;
|
|
373
|
+
vec4 pointVisibility = vec4(1.0);
|
|
374
|
+
vec4 spotVisibility = vec4(1.0);
|
|
375
|
+
#ifdef PBR_RECEIVE_SHADOWS
|
|
376
|
+
if (pbrShadow.enabled != 0) {
|
|
377
|
+
float viewDepth = -(pbrShadow.viewMatrix * vec4(pbr_vPosition, 1.0)).z;
|
|
378
|
+
directionalVisibility = shadow_getDirectionalFactor(pbr_vPosition, normal, viewDepth);
|
|
379
|
+
for (int index = 0; index < 4; index++) {
|
|
380
|
+
pointVisibility[index] = shadow_getPointFactor(index, pbr_vPosition, normal);
|
|
381
|
+
spotVisibility[index] = shadow_getSpotFactor(index, pbr_vPosition, normal);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
#endif
|
|
385
|
+
fragmentColor = vec4(lightmap_getIrradiance(pbr_vPosition, normal, directionalVisibility, pointVisibility, spotVisibility), lightmapBake.chartId);
|
|
386
|
+
#else
|
|
336
387
|
#ifdef PBR_SHADOW_PASS
|
|
337
388
|
pbr_discardMaskedFragment(sceneVertexColor);
|
|
338
389
|
#else
|
|
@@ -383,6 +434,7 @@ void main(void) {
|
|
|
383
434
|
#endif
|
|
384
435
|
#endif
|
|
385
436
|
#endif
|
|
437
|
+
#endif
|
|
386
438
|
}
|
|
387
439
|
`
|
|
388
440
|
);
|
|
@@ -497,9 +549,27 @@ function getPBRTextureDefines(bindings) {
|
|
|
497
549
|
HAS_MULTISCATTERCOLORMAP: Boolean(bindings["pbr_multiscatterColorSampler"])
|
|
498
550
|
};
|
|
499
551
|
}
|
|
552
|
+
function createPBRLightmapModel(device, options) {
|
|
553
|
+
const features = { ...getPBRGeometryDefines(options.geometry), ...options.defines };
|
|
554
|
+
(0, import_core.assert)(features["HAS_NORMALS"] && (features["HAS_UV"] || features["HAS_UV_1"]));
|
|
555
|
+
return createPBRModel(device, {
|
|
556
|
+
colorAttachmentFormats: ["rgba16float"],
|
|
557
|
+
...options,
|
|
558
|
+
modules: [import_shaders.lightmapBake, ...options.modules || []],
|
|
559
|
+
receiveContactShadows: false,
|
|
560
|
+
receiveAmbientOcclusion: false,
|
|
561
|
+
defines: { ...options.defines, HAS_LIGHTMAP: false, USE_IBL: false, PBR_LIGHTMAP_PASS: true },
|
|
562
|
+
parameters: {
|
|
563
|
+
...options.parameters,
|
|
564
|
+
depthWriteEnabled: false,
|
|
565
|
+
cullMode: "none"
|
|
566
|
+
}
|
|
567
|
+
});
|
|
568
|
+
}
|
|
500
569
|
// Annotate the CommonJS export names for ESM import in node:
|
|
501
570
|
0 && (module.exports = {
|
|
502
571
|
PBR_MODEL_WGSL_SHADER,
|
|
572
|
+
createPBRLightmapModel,
|
|
503
573
|
createPBRModel,
|
|
504
574
|
createPBRShadowModel,
|
|
505
575
|
createPBRSurfaceModel,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Device } from '@luma.gl/core';
|
|
2
2
|
import type { Material } from "../material/material.js";
|
|
3
3
|
import { Model, type ModelProps } from "../model/model.js";
|
|
4
4
|
/** Optional WGSL extensions for adapters building specialized mesh passes. */
|
|
@@ -38,4 +38,8 @@ export declare function createPBRSurfaceModel(device: Device, options: CreatePBR
|
|
|
38
38
|
export declare function getPBRGeometryDefines(geometry: ModelProps['geometry']): Record<string, boolean>;
|
|
39
39
|
/** Returns feature-specialized shader defines for texture bindings present on one PBR material. */
|
|
40
40
|
export declare function getPBRTextureDefines(bindings: Record<string, unknown>): Record<string, boolean>;
|
|
41
|
+
/** Options for a UV-space diffuse irradiance model. Supply normals and nonoverlapping atlas UVs. */
|
|
42
|
+
export type CreatePBRLightmapModelOptions = CreatePBRModelOptions;
|
|
43
|
+
/** Creates a borrowed-material bake model; output is linear irradiance E with chart ID in alpha. */
|
|
44
|
+
export declare function createPBRLightmapModel(device: Device, options: CreatePBRLightmapModelOptions): Model;
|
|
41
45
|
//# sourceMappingURL=pbr-model.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pbr-model.d.ts","sourceRoot":"","sources":["../../src/lighting/pbr-model.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"pbr-model.d.ts","sourceRoot":"","sources":["../../src/lighting/pbr-model.ts"],"names":[],"mappings":"AAGA,OAAO,EAAS,KAAK,MAAM,EAAC,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAC,QAAQ,EAAC,gCAA6B;AACnD,OAAO,EAAC,KAAK,EAAE,KAAK,UAAU,EAAC,0BAAuB;AAYtD,8EAA8E;AAC9E,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,C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