@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
package/dist/lighting/index.d.ts
CHANGED
|
@@ -20,4 +20,12 @@ export { ClusteredLightGrid, CLUSTERED_POINT_LIGHT_LAYOUT, MAX_CLUSTERED_POINT_L
|
|
|
20
20
|
export type { ClusteredLightGridProps, ClusteredLightGridEncodeOptions, ClusteredLightGridBindings, ClusteredLightGridUniforms, ClusteredLightGridShaderPassUniforms } from "./clustered-light-grid.js";
|
|
21
21
|
export { AmbientOcclusionPass } from "./ambient-occlusion-pass.js";
|
|
22
22
|
export type { AmbientOcclusionMode, AmbientOcclusionPassProps, AmbientOcclusionRenderOptions } from "./ambient-occlusion-pass.js";
|
|
23
|
+
export { createPBRLightmapModel } from "./pbr-model.js";
|
|
24
|
+
export type { CreatePBRLightmapModelOptions } from "./pbr-model.js";
|
|
25
|
+
export { LightmapBaker, LightmapBakeResult } from "./lightmap-baker.js";
|
|
26
|
+
export type { LightmapBakerProps, LightmapBakeOptions, LightmapBakeView, LightmapTextures } from "./lightmap-baker.js";
|
|
27
|
+
export { readLightmapData, createLightmapFromData, encodeLightmapData, decodeLightmapData } from "./lightmap-data.js";
|
|
28
|
+
export type { LightmapData } from "./lightmap-data.js";
|
|
29
|
+
export { sampleLightmapEnvironment } from "./lightmap-environment.js";
|
|
30
|
+
export type { LightmapEnvironment, LightmapEnvironmentSample } from "./lightmap-environment.js";
|
|
23
31
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lighting/index.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,EAC/B,sBAAsB,EACvB,qCAAkC;AACnC,YAAY,EACV,6BAA6B,EAC7B,8BAA8B,EAC/B,qCAAkC;AACnC,OAAO,EAAC,0BAA0B,EAAC,0BAAuB;AAE1D,O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;AAElF,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AACxD,YAAY,EAAC,sBAAsB,EAAE,0BAA0B,EAAC,iCAA8B;AAE9F,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,EAC1B,0BAA0B,EAC1B,8BAA8B,EAC/B,kCAA+B;AAChC,YAAY,EACV,uBAAuB,EACvB,+BAA+B,EAC/B,0BAA0B,EAC1B,0BAA0B,EAC1B,oCAAoC,EACrC,kCAA+B;AAChC,OAAO,EAAC,oBAAoB,EAAC,oCAAiC;AAC9D,YAAY,EACV,oBAAoB,EACpB,yBAAyB,EACzB,6BAA6B,EAC9B,oCAAiC;AAElC,OAAO,EAAC,sBAAsB,EAAC,uBAAoB;AACnD,YAAY,EAAC,6BAA6B,EAAC,uBAAoB;AAC/D,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,4BAAyB;AACnE,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,gBAAgB,EACjB,4BAAyB;AAC1B,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EACnB,2BAAwB;AACzB,YAAY,EAAC,YAAY,EAAC,2BAAwB;AAClD,OAAO,EAAC,yBAAyB,EAAC,kCAA+B;AACjE,YAAY,EAAC,mBAAmB,EAAE,yBAAyB,EAAC,kCAA+B"}
|
package/dist/lighting/index.js
CHANGED
|
@@ -13,4 +13,8 @@ export { createContactShadowCompositeShaderPass } from "./contact-shadow-composi
|
|
|
13
13
|
export { ContactShadowPass } from "./contact-shadow-pass.js";
|
|
14
14
|
export { ClusteredLightGrid, CLUSTERED_POINT_LIGHT_LAYOUT, MAX_CLUSTERED_POINT_LIGHTS, DEFAULT_CLUSTER_DIMENSIONS, DEFAULT_MAX_LIGHTS_PER_CLUSTER } from "./clustered-light-grid.js";
|
|
15
15
|
export { AmbientOcclusionPass } from "./ambient-occlusion-pass.js";
|
|
16
|
+
export { createPBRLightmapModel } from "./pbr-model.js";
|
|
17
|
+
export { LightmapBaker, LightmapBakeResult } from "./lightmap-baker.js";
|
|
18
|
+
export { readLightmapData, createLightmapFromData, encodeLightmapData, decodeLightmapData } from "./lightmap-data.js";
|
|
19
|
+
export { sampleLightmapEnvironment } from "./lightmap-environment.js";
|
|
16
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lighting/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,EAC/B,sBAAsB,EACvB,qCAAkC;AAKnC,OAAO,EAAC,0BAA0B,EAAC,0BAAuB;AAE1D,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EAC1B,0BAAuB;AAExB,OAAO,EAAC,yBAAyB,EAAE,yBAAyB,EAAC,6BAA0B;AAGvF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACtB,uBAAoB;AAGrB,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAClB,iCAA8B;AAY/B,OAAO,EAAC,uBAAuB,EAAC,4BAAyB;AAGzD,OAAO,EAAC,cAAc,EAAC,8BAA2B;AAOlD,OAAO,EAAC,sCAAsC,EAAC,sCAAmC;AAElF,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AAGxD,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,EAC1B,0BAA0B,EAC1B,8BAA8B,EAC/B,kCAA+B;AAQhC,OAAO,EAAC,oBAAoB,EAAC,oCAAiC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/lighting/index.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EACL,4BAA4B,EAC5B,+BAA+B,EAC/B,sBAAsB,EACvB,qCAAkC;AAKnC,OAAO,EAAC,0BAA0B,EAAC,0BAAuB;AAE1D,OAAO,EACL,iBAAiB,EACjB,wBAAwB,EACxB,yBAAyB,EAC1B,0BAAuB;AAExB,OAAO,EAAC,yBAAyB,EAAE,yBAAyB,EAAC,6BAA0B;AAGvF,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACpB,eAAe,EACf,qBAAqB,EACtB,uBAAoB;AAGrB,OAAO,EACL,iBAAiB,EACjB,0BAA0B,EAC1B,mBAAmB,EACnB,yBAAyB,EACzB,iBAAiB,EAClB,iCAA8B;AAY/B,OAAO,EAAC,uBAAuB,EAAC,4BAAyB;AAGzD,OAAO,EAAC,cAAc,EAAC,8BAA2B;AAOlD,OAAO,EAAC,sCAAsC,EAAC,sCAAmC;AAElF,OAAO,EAAC,iBAAiB,EAAC,iCAA8B;AAGxD,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,EAC1B,0BAA0B,EAC1B,8BAA8B,EAC/B,kCAA+B;AAQhC,OAAO,EAAC,oBAAoB,EAAC,oCAAiC;AAO9D,OAAO,EAAC,sBAAsB,EAAC,uBAAoB;AAEnD,OAAO,EAAC,aAAa,EAAE,kBAAkB,EAAC,4BAAyB;AAOnE,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EACnB,2BAAwB;AAEzB,OAAO,EAAC,yBAAyB,EAAC,kCAA+B"}
|
|
@@ -0,0 +1,238 @@
|
|
|
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_baker_exports = {};
|
|
19
|
+
__export(lightmap_baker_exports, {
|
|
20
|
+
LightmapBakeResult: () => LightmapBakeResult,
|
|
21
|
+
LightmapBaker: () => LightmapBaker
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(lightmap_baker_exports);
|
|
24
|
+
var import_core = require("@luma.gl/core");
|
|
25
|
+
var import_shaders = require("@luma.gl/shaders");
|
|
26
|
+
var import_clip_space = require("../models/clip-space.cjs");
|
|
27
|
+
class LightmapBakeResult {
|
|
28
|
+
textures;
|
|
29
|
+
destroyed = false;
|
|
30
|
+
constructor(texture) {
|
|
31
|
+
this.textures = { lightmapTexture: texture };
|
|
32
|
+
}
|
|
33
|
+
destroy() {
|
|
34
|
+
if (!this.destroyed) {
|
|
35
|
+
this.destroyed = true;
|
|
36
|
+
this.textures.lightmapTexture.destroy();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
class LightmapBaker {
|
|
41
|
+
device;
|
|
42
|
+
format;
|
|
43
|
+
targets = [];
|
|
44
|
+
filters = /* @__PURE__ */ new Map();
|
|
45
|
+
activeIndex = 1;
|
|
46
|
+
previewIndex = 3;
|
|
47
|
+
destroyed = false;
|
|
48
|
+
needsClear = true;
|
|
49
|
+
samples = 0;
|
|
50
|
+
constructor(device, props) {
|
|
51
|
+
this.device = device;
|
|
52
|
+
this.format = props.format ?? "rgba16float";
|
|
53
|
+
const capabilities = device.getTextureFormatCapabilities(this.format);
|
|
54
|
+
(0, import_core.assert)((this.format === "rgba16float" || this.format === "rgba32float") && capabilities.render && capabilities.filter);
|
|
55
|
+
(0, import_core.assert)(device.getTextureFormatCapabilities("rgba32float").render);
|
|
56
|
+
this.resize(props);
|
|
57
|
+
}
|
|
58
|
+
get width() {
|
|
59
|
+
return this.targets[0].texture.width;
|
|
60
|
+
}
|
|
61
|
+
get height() {
|
|
62
|
+
return this.targets[0].texture.height;
|
|
63
|
+
}
|
|
64
|
+
get sampleCount() {
|
|
65
|
+
return this.samples;
|
|
66
|
+
}
|
|
67
|
+
/** Borrowed current preview. Reacquire after every update or resize. */
|
|
68
|
+
get textures() {
|
|
69
|
+
(0, import_core.assert)(!this.destroyed);
|
|
70
|
+
return { lightmapTexture: this.targets[this.previewIndex].texture };
|
|
71
|
+
}
|
|
72
|
+
reset() {
|
|
73
|
+
(0, import_core.assert)(!this.destroyed);
|
|
74
|
+
this.samples = 0;
|
|
75
|
+
this.needsClear = true;
|
|
76
|
+
}
|
|
77
|
+
resize(props) {
|
|
78
|
+
(0, import_core.assert)(!this.destroyed);
|
|
79
|
+
(0, import_core.assert)(Number.isInteger(props.width) && props.width > 0 && Number.isInteger(props.height) && props.height > 0);
|
|
80
|
+
if (this.targets.length && props.width === this.width && props.height === this.height)
|
|
81
|
+
return;
|
|
82
|
+
const targets = [];
|
|
83
|
+
try {
|
|
84
|
+
for (let index = 0; index < 5; index++)
|
|
85
|
+
targets.push(this.createTarget(props.width, props.height, index === 1 || index === 2 ? "rgba32float" : this.format));
|
|
86
|
+
} catch (error) {
|
|
87
|
+
for (const target of targets)
|
|
88
|
+
this.destroyTarget(target);
|
|
89
|
+
throw error;
|
|
90
|
+
}
|
|
91
|
+
for (const target of this.targets)
|
|
92
|
+
this.destroyTarget(target);
|
|
93
|
+
this.targets = targets;
|
|
94
|
+
this.activeIndex = 1;
|
|
95
|
+
this.previewIndex = 3;
|
|
96
|
+
this.reset();
|
|
97
|
+
}
|
|
98
|
+
/** Record one update per submission. Failed draw callbacks leave accumulation/sample count unchanged. */
|
|
99
|
+
update(options) {
|
|
100
|
+
var _a;
|
|
101
|
+
(0, import_core.assert)(!this.destroyed);
|
|
102
|
+
const steps = options.dilationSteps ?? 0;
|
|
103
|
+
(0, import_core.assert)(Number.isInteger(steps) && steps >= 0 && steps <= 16);
|
|
104
|
+
const chartTexture = options.chartTexture;
|
|
105
|
+
if (steps) {
|
|
106
|
+
(0, import_core.assert)(chartTexture && !chartTexture.destroyed && chartTexture.device === this.device && chartTexture.width === this.width && chartTexture.height === this.height && chartTexture.dimension === "2d");
|
|
107
|
+
}
|
|
108
|
+
if (this.needsClear) {
|
|
109
|
+
for (const target2 of this.targets) {
|
|
110
|
+
const pass = this.device.beginRenderPass({
|
|
111
|
+
framebuffer: target2.framebuffer,
|
|
112
|
+
clearColor: [0, 0, 0, 0]
|
|
113
|
+
});
|
|
114
|
+
pass.end();
|
|
115
|
+
}
|
|
116
|
+
this.needsClear = false;
|
|
117
|
+
}
|
|
118
|
+
const target = this.targets[0];
|
|
119
|
+
const view = {
|
|
120
|
+
width: this.width,
|
|
121
|
+
height: this.height,
|
|
122
|
+
sampleIndex: this.samples,
|
|
123
|
+
framebuffer: target.framebuffer
|
|
124
|
+
};
|
|
125
|
+
(_a = options.prepareSample) == null ? void 0 : _a.call(options, view);
|
|
126
|
+
const renderPass = this.device.beginRenderPass({
|
|
127
|
+
framebuffer: target.framebuffer,
|
|
128
|
+
clearColor: [0, 0, 0, 0]
|
|
129
|
+
});
|
|
130
|
+
try {
|
|
131
|
+
renderPass.setParameters({ viewport: [0, 0, this.width, this.height] });
|
|
132
|
+
options.drawSample({ ...view, renderPass });
|
|
133
|
+
} finally {
|
|
134
|
+
renderPass.end();
|
|
135
|
+
}
|
|
136
|
+
const nextIndex = this.activeIndex === 1 ? 2 : 1;
|
|
137
|
+
this.filter(0, 0, this.targets[this.activeIndex].texture, this.targets[0].texture, this.targets[nextIndex], 1 / (this.samples + 1));
|
|
138
|
+
this.activeIndex = nextIndex;
|
|
139
|
+
this.samples++;
|
|
140
|
+
this.filter(17, 2, this.targets[nextIndex].texture, this.targets[nextIndex].texture, this.targets[3], 1);
|
|
141
|
+
this.previewIndex = 3;
|
|
142
|
+
for (let step = 0; step < steps; step++) {
|
|
143
|
+
const destinationIndex = step % 2 === 0 ? 4 : 3;
|
|
144
|
+
this.filter(step + 1, 1, chartTexture, this.targets[this.previewIndex].texture, this.targets[destinationIndex], 1);
|
|
145
|
+
this.previewIndex = destinationIndex;
|
|
146
|
+
}
|
|
147
|
+
return this.textures;
|
|
148
|
+
}
|
|
149
|
+
/** Records a copy into independent storage. Submit before releasing referenced resources. */
|
|
150
|
+
createResult() {
|
|
151
|
+
(0, import_core.assert)(!this.destroyed && this.samples > 0);
|
|
152
|
+
const target = this.createTarget(this.width, this.height);
|
|
153
|
+
try {
|
|
154
|
+
this.device.commandEncoder.copyTextureToTexture({
|
|
155
|
+
sourceTexture: this.textures.lightmapTexture,
|
|
156
|
+
destinationTexture: target.texture,
|
|
157
|
+
width: this.width,
|
|
158
|
+
height: this.height
|
|
159
|
+
});
|
|
160
|
+
return new LightmapBakeResult(target.texture);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
target.texture.destroy();
|
|
163
|
+
throw error;
|
|
164
|
+
} finally {
|
|
165
|
+
target.framebuffer.destroy();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
destroy() {
|
|
169
|
+
if (this.destroyed)
|
|
170
|
+
return;
|
|
171
|
+
this.destroyed = true;
|
|
172
|
+
for (const filter of this.filters.values())
|
|
173
|
+
filter.destroy();
|
|
174
|
+
for (const target of this.targets)
|
|
175
|
+
this.destroyTarget(target);
|
|
176
|
+
}
|
|
177
|
+
createTarget(width, height, format = this.format) {
|
|
178
|
+
const texture = this.device.createTexture({
|
|
179
|
+
width,
|
|
180
|
+
height,
|
|
181
|
+
format,
|
|
182
|
+
usage: import_core.Texture.RENDER_ATTACHMENT | import_core.Texture.SAMPLE | import_core.Texture.COPY_SRC | import_core.Texture.COPY_DST,
|
|
183
|
+
sampler: format === "rgba32float" ? { minFilter: "nearest", magFilter: "nearest" } : { minFilter: "linear", magFilter: "linear" }
|
|
184
|
+
});
|
|
185
|
+
try {
|
|
186
|
+
return {
|
|
187
|
+
texture,
|
|
188
|
+
format,
|
|
189
|
+
framebuffer: this.device.createFramebuffer({ width, height, colorAttachments: [texture] })
|
|
190
|
+
};
|
|
191
|
+
} catch (error) {
|
|
192
|
+
texture.destroy();
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
destroyTarget(target) {
|
|
197
|
+
target.framebuffer.destroy();
|
|
198
|
+
target.texture.destroy();
|
|
199
|
+
}
|
|
200
|
+
filter(index, mode, previous, current, target, weight) {
|
|
201
|
+
let model = this.filters.get(index);
|
|
202
|
+
if (!model) {
|
|
203
|
+
model = new import_clip_space.ClipSpace(this.device, {
|
|
204
|
+
modules: [import_shaders.lightmapFilter],
|
|
205
|
+
shaderLayout: {
|
|
206
|
+
attributes: [],
|
|
207
|
+
bindings: ["currentTexture", "previousTexture", "chartTexture"].map((name, index2) => ({
|
|
208
|
+
name,
|
|
209
|
+
type: "texture",
|
|
210
|
+
group: 0,
|
|
211
|
+
location: index2 + 101,
|
|
212
|
+
sampleType: "unfilterable-float"
|
|
213
|
+
}))
|
|
214
|
+
},
|
|
215
|
+
source: "@fragment fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {return lightmapFilter_getColor(vec2i(inputs.Position.xy));}",
|
|
216
|
+
fs: "#version 300 es\nout vec4 fragmentColor;\nvoid main() {fragmentColor = lightmapFilter_getColor(ivec2(gl_FragCoord.xy));}",
|
|
217
|
+
colorAttachmentFormats: [target.format],
|
|
218
|
+
parameters: { depthWriteEnabled: false }
|
|
219
|
+
});
|
|
220
|
+
this.filters.set(index, model);
|
|
221
|
+
}
|
|
222
|
+
model.setBindings({ currentTexture: current, previousTexture: previous, chartTexture: previous });
|
|
223
|
+
model.shaderInputs.setProps({ lightmapFilter: { weight, mode } });
|
|
224
|
+
model.predraw(this.device.commandEncoder);
|
|
225
|
+
const pass = this.device.beginRenderPass({ framebuffer: target.framebuffer });
|
|
226
|
+
try {
|
|
227
|
+
pass.setParameters({ viewport: [0, 0, this.width, this.height] });
|
|
228
|
+
model.draw(pass);
|
|
229
|
+
} finally {
|
|
230
|
+
pass.end();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
235
|
+
0 && (module.exports = {
|
|
236
|
+
LightmapBakeResult,
|
|
237
|
+
LightmapBaker
|
|
238
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Texture, type Device, type Framebuffer, type RenderPass, type TextureFormatColor } from '@luma.gl/core';
|
|
2
|
+
export type LightmapBakerProps = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
format?: TextureFormatColor;
|
|
6
|
+
};
|
|
7
|
+
export type LightmapTextures = {
|
|
8
|
+
lightmapTexture: Texture;
|
|
9
|
+
};
|
|
10
|
+
export type LightmapBakeView = {
|
|
11
|
+
width: number;
|
|
12
|
+
height: number;
|
|
13
|
+
sampleIndex: number;
|
|
14
|
+
framebuffer: Framebuffer;
|
|
15
|
+
renderPass: RenderPass;
|
|
16
|
+
};
|
|
17
|
+
export type LightmapBakeOptions = {
|
|
18
|
+
/** Upload model uniforms and prepare shadow maps before the atlas pass starts. */
|
|
19
|
+
prepareSample?: (view: Omit<LightmapBakeView, 'renderPass'>) => void;
|
|
20
|
+
/** Draw caller-selected UV-space models. Alpha must contain positive chart IDs. */
|
|
21
|
+
drawSample: (view: LightmapBakeView) => void;
|
|
22
|
+
/** Borrowed same-size linear texture: red contains the permitted chart ID for each gutter texel. */
|
|
23
|
+
chartTexture?: Texture;
|
|
24
|
+
/** Number of one-texel dilation steps, from zero to sixteen. Requires chartTexture. */
|
|
25
|
+
dilationSteps?: number;
|
|
26
|
+
};
|
|
27
|
+
/** Owns an independent linear irradiance texture, including alpha chart coverage. */
|
|
28
|
+
export declare class LightmapBakeResult {
|
|
29
|
+
readonly textures: LightmapTextures;
|
|
30
|
+
private destroyed;
|
|
31
|
+
constructor(texture: Texture);
|
|
32
|
+
destroy(): void;
|
|
33
|
+
}
|
|
34
|
+
/** Records UV-space samples and arithmetic-mean accumulation without traversal or submission. */
|
|
35
|
+
export declare class LightmapBaker {
|
|
36
|
+
readonly device: Device;
|
|
37
|
+
readonly format: TextureFormatColor;
|
|
38
|
+
private targets;
|
|
39
|
+
private filters;
|
|
40
|
+
private activeIndex;
|
|
41
|
+
private previewIndex;
|
|
42
|
+
private destroyed;
|
|
43
|
+
private needsClear;
|
|
44
|
+
private samples;
|
|
45
|
+
constructor(device: Device, props: LightmapBakerProps);
|
|
46
|
+
get width(): number;
|
|
47
|
+
get height(): number;
|
|
48
|
+
get sampleCount(): number;
|
|
49
|
+
/** Borrowed current preview. Reacquire after every update or resize. */
|
|
50
|
+
get textures(): LightmapTextures;
|
|
51
|
+
reset(): void;
|
|
52
|
+
resize(props: Pick<LightmapBakerProps, 'width' | 'height'>): void;
|
|
53
|
+
/** Record one update per submission. Failed draw callbacks leave accumulation/sample count unchanged. */
|
|
54
|
+
update(options: LightmapBakeOptions): LightmapTextures;
|
|
55
|
+
/** Records a copy into independent storage. Submit before releasing referenced resources. */
|
|
56
|
+
createResult(): LightmapBakeResult;
|
|
57
|
+
destroy(): void;
|
|
58
|
+
private createTarget;
|
|
59
|
+
private destroyTarget;
|
|
60
|
+
private filter;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=lightmap-baker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightmap-baker.d.ts","sourceRoot":"","sources":["../../src/lighting/lightmap-baker.ts"],"names":[],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;IAC/C,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,YAAY,CAAK;IACzB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,UAAU,CAAQ;IAC1B,OAAO,CAAC,OAAO,CAAK;gBAER,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB;IAcrD,IAAI,KAAK,IAAI,MAAM,CAElB;IACD,IAAI,MAAM,IAAI,MAAM,CAEnB;IACD,IAAI,WAAW,IAAI,MAAM,CAExB;IACD,wEAAwE;IACxE,IAAI,QAAQ,IAAI,gBAAgB,CAG/B;IAED,KAAK,IAAI,IAAI;IAKb,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,kBAAkB,EAAE,OAAO,GAAG,QAAQ,CAAC,GAAG,IAAI;IA8BjE,yGAAyG;IACzG,MAAM,CAAC,OAAO,EAAE,mBAAmB,GAAG,gBAAgB;IA+EtD,6FAA6F;IAC7F,YAAY,IAAI,kBAAkB;IAmBlC,OAAO,IAAI,IAAI;IAMf,OAAO,CAAC,YAAY;IA0BpB,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,MAAM;CA0Cf"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
3
|
+
import { assert, Texture } from '@luma.gl/core';
|
|
4
|
+
import { lightmapFilter } from '@luma.gl/shaders';
|
|
5
|
+
import { ClipSpace } from "../models/clip-space.js";
|
|
6
|
+
/** Owns an independent linear irradiance texture, including alpha chart coverage. */
|
|
7
|
+
export class LightmapBakeResult {
|
|
8
|
+
textures;
|
|
9
|
+
destroyed = false;
|
|
10
|
+
constructor(texture) {
|
|
11
|
+
this.textures = { lightmapTexture: texture };
|
|
12
|
+
}
|
|
13
|
+
destroy() {
|
|
14
|
+
if (!this.destroyed) {
|
|
15
|
+
this.destroyed = true;
|
|
16
|
+
this.textures.lightmapTexture.destroy();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** Records UV-space samples and arithmetic-mean accumulation without traversal or submission. */
|
|
21
|
+
export class LightmapBaker {
|
|
22
|
+
device;
|
|
23
|
+
format;
|
|
24
|
+
targets = [];
|
|
25
|
+
filters = new Map();
|
|
26
|
+
activeIndex = 1;
|
|
27
|
+
previewIndex = 3;
|
|
28
|
+
destroyed = false;
|
|
29
|
+
needsClear = true;
|
|
30
|
+
samples = 0;
|
|
31
|
+
constructor(device, props) {
|
|
32
|
+
this.device = device;
|
|
33
|
+
this.format = props.format ?? 'rgba16float';
|
|
34
|
+
const capabilities = device.getTextureFormatCapabilities(this.format);
|
|
35
|
+
// Require explicit linear floating-point storage; never silently clip irradiance.
|
|
36
|
+
assert((this.format === 'rgba16float' || this.format === 'rgba32float') &&
|
|
37
|
+
capabilities.render &&
|
|
38
|
+
capabilities.filter);
|
|
39
|
+
// Accumulation uses unfiltered float32 history so small late samples survive rounding.
|
|
40
|
+
assert(device.getTextureFormatCapabilities('rgba32float').render);
|
|
41
|
+
this.resize(props);
|
|
42
|
+
}
|
|
43
|
+
get width() {
|
|
44
|
+
return this.targets[0].texture.width;
|
|
45
|
+
}
|
|
46
|
+
get height() {
|
|
47
|
+
return this.targets[0].texture.height;
|
|
48
|
+
}
|
|
49
|
+
get sampleCount() {
|
|
50
|
+
return this.samples;
|
|
51
|
+
}
|
|
52
|
+
/** Borrowed current preview. Reacquire after every update or resize. */
|
|
53
|
+
get textures() {
|
|
54
|
+
assert(!this.destroyed);
|
|
55
|
+
return { lightmapTexture: this.targets[this.previewIndex].texture };
|
|
56
|
+
}
|
|
57
|
+
reset() {
|
|
58
|
+
assert(!this.destroyed);
|
|
59
|
+
this.samples = 0;
|
|
60
|
+
this.needsClear = true;
|
|
61
|
+
}
|
|
62
|
+
resize(props) {
|
|
63
|
+
assert(!this.destroyed);
|
|
64
|
+
assert(Number.isInteger(props.width) &&
|
|
65
|
+
props.width > 0 &&
|
|
66
|
+
Number.isInteger(props.height) &&
|
|
67
|
+
props.height > 0);
|
|
68
|
+
if (this.targets.length && props.width === this.width && props.height === this.height)
|
|
69
|
+
return;
|
|
70
|
+
const targets = [];
|
|
71
|
+
try {
|
|
72
|
+
for (let index = 0; index < 5; index++)
|
|
73
|
+
targets.push(this.createTarget(props.width, props.height, index === 1 || index === 2 ? 'rgba32float' : this.format));
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
for (const target of targets)
|
|
77
|
+
this.destroyTarget(target);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
for (const target of this.targets)
|
|
81
|
+
this.destroyTarget(target);
|
|
82
|
+
this.targets = targets;
|
|
83
|
+
this.activeIndex = 1;
|
|
84
|
+
this.previewIndex = 3;
|
|
85
|
+
this.reset();
|
|
86
|
+
}
|
|
87
|
+
/** Record one update per submission. Failed draw callbacks leave accumulation/sample count unchanged. */
|
|
88
|
+
update(options) {
|
|
89
|
+
assert(!this.destroyed);
|
|
90
|
+
const steps = options.dilationSteps ?? 0;
|
|
91
|
+
assert(Number.isInteger(steps) && steps >= 0 && steps <= 16);
|
|
92
|
+
const chartTexture = options.chartTexture;
|
|
93
|
+
if (steps) {
|
|
94
|
+
// Chart ownership is explicit, preventing dilation between adjacent islands.
|
|
95
|
+
assert(chartTexture &&
|
|
96
|
+
!chartTexture.destroyed &&
|
|
97
|
+
chartTexture.device === this.device &&
|
|
98
|
+
chartTexture.width === this.width &&
|
|
99
|
+
chartTexture.height === this.height &&
|
|
100
|
+
chartTexture.dimension === '2d');
|
|
101
|
+
}
|
|
102
|
+
if (this.needsClear) {
|
|
103
|
+
for (const target of this.targets) {
|
|
104
|
+
const pass = this.device.beginRenderPass({
|
|
105
|
+
framebuffer: target.framebuffer,
|
|
106
|
+
clearColor: [0, 0, 0, 0]
|
|
107
|
+
});
|
|
108
|
+
pass.end();
|
|
109
|
+
}
|
|
110
|
+
this.needsClear = false;
|
|
111
|
+
}
|
|
112
|
+
const target = this.targets[0];
|
|
113
|
+
const view = {
|
|
114
|
+
width: this.width,
|
|
115
|
+
height: this.height,
|
|
116
|
+
sampleIndex: this.samples,
|
|
117
|
+
framebuffer: target.framebuffer
|
|
118
|
+
};
|
|
119
|
+
options.prepareSample?.(view);
|
|
120
|
+
const renderPass = this.device.beginRenderPass({
|
|
121
|
+
framebuffer: target.framebuffer,
|
|
122
|
+
clearColor: [0, 0, 0, 0]
|
|
123
|
+
});
|
|
124
|
+
try {
|
|
125
|
+
renderPass.setParameters({ viewport: [0, 0, this.width, this.height] });
|
|
126
|
+
options.drawSample({ ...view, renderPass });
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
renderPass.end();
|
|
130
|
+
}
|
|
131
|
+
const nextIndex = this.activeIndex === 1 ? 2 : 1;
|
|
132
|
+
this.filter(0, 0, this.targets[this.activeIndex].texture, this.targets[0].texture, this.targets[nextIndex], 1 / (this.samples + 1));
|
|
133
|
+
this.activeIndex = nextIndex;
|
|
134
|
+
this.samples++;
|
|
135
|
+
this.filter(17, 2, this.targets[nextIndex].texture, this.targets[nextIndex].texture, this.targets[3], 1);
|
|
136
|
+
this.previewIndex = 3;
|
|
137
|
+
for (let step = 0; step < steps; step++) {
|
|
138
|
+
const destinationIndex = step % 2 === 0 ? 4 : 3;
|
|
139
|
+
this.filter(step + 1, 1, chartTexture, this.targets[this.previewIndex].texture, this.targets[destinationIndex], 1);
|
|
140
|
+
this.previewIndex = destinationIndex;
|
|
141
|
+
}
|
|
142
|
+
return this.textures;
|
|
143
|
+
}
|
|
144
|
+
/** Records a copy into independent storage. Submit before releasing referenced resources. */
|
|
145
|
+
createResult() {
|
|
146
|
+
assert(!this.destroyed && this.samples > 0);
|
|
147
|
+
const target = this.createTarget(this.width, this.height);
|
|
148
|
+
try {
|
|
149
|
+
this.device.commandEncoder.copyTextureToTexture({
|
|
150
|
+
sourceTexture: this.textures.lightmapTexture,
|
|
151
|
+
destinationTexture: target.texture,
|
|
152
|
+
width: this.width,
|
|
153
|
+
height: this.height
|
|
154
|
+
});
|
|
155
|
+
return new LightmapBakeResult(target.texture);
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
target.texture.destroy();
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
finally {
|
|
162
|
+
target.framebuffer.destroy();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
destroy() {
|
|
166
|
+
if (this.destroyed)
|
|
167
|
+
return;
|
|
168
|
+
this.destroyed = true;
|
|
169
|
+
for (const filter of this.filters.values())
|
|
170
|
+
filter.destroy();
|
|
171
|
+
for (const target of this.targets)
|
|
172
|
+
this.destroyTarget(target);
|
|
173
|
+
}
|
|
174
|
+
createTarget(width, height, format = this.format) {
|
|
175
|
+
const texture = this.device.createTexture({
|
|
176
|
+
width,
|
|
177
|
+
height,
|
|
178
|
+
format,
|
|
179
|
+
usage: Texture.RENDER_ATTACHMENT | Texture.SAMPLE | Texture.COPY_SRC | Texture.COPY_DST,
|
|
180
|
+
sampler: format === 'rgba32float'
|
|
181
|
+
? { minFilter: 'nearest', magFilter: 'nearest' }
|
|
182
|
+
: { minFilter: 'linear', magFilter: 'linear' }
|
|
183
|
+
});
|
|
184
|
+
try {
|
|
185
|
+
return {
|
|
186
|
+
texture,
|
|
187
|
+
format,
|
|
188
|
+
framebuffer: this.device.createFramebuffer({ width, height, colorAttachments: [texture] })
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
texture.destroy();
|
|
193
|
+
throw error;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
destroyTarget(target) {
|
|
197
|
+
target.framebuffer.destroy();
|
|
198
|
+
target.texture.destroy();
|
|
199
|
+
}
|
|
200
|
+
filter(index, mode, previous, current, target, weight) {
|
|
201
|
+
let model = this.filters.get(index);
|
|
202
|
+
if (!model) {
|
|
203
|
+
model = new ClipSpace(this.device, {
|
|
204
|
+
modules: [lightmapFilter],
|
|
205
|
+
shaderLayout: {
|
|
206
|
+
attributes: [],
|
|
207
|
+
bindings: ['currentTexture', 'previousTexture', 'chartTexture'].map((name, index) => ({
|
|
208
|
+
name,
|
|
209
|
+
type: 'texture',
|
|
210
|
+
group: 0,
|
|
211
|
+
location: index + 101,
|
|
212
|
+
sampleType: 'unfilterable-float'
|
|
213
|
+
}))
|
|
214
|
+
},
|
|
215
|
+
source: '@fragment fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {return lightmapFilter_getColor(vec2i(inputs.Position.xy));}',
|
|
216
|
+
fs: '#version 300 es\nout vec4 fragmentColor;\nvoid main() {fragmentColor = lightmapFilter_getColor(ivec2(gl_FragCoord.xy));}',
|
|
217
|
+
colorAttachmentFormats: [target.format],
|
|
218
|
+
parameters: { depthWriteEnabled: false }
|
|
219
|
+
});
|
|
220
|
+
this.filters.set(index, model);
|
|
221
|
+
}
|
|
222
|
+
model.setBindings({ currentTexture: current, previousTexture: previous, chartTexture: previous });
|
|
223
|
+
model.shaderInputs.setProps({ lightmapFilter: { weight, mode } });
|
|
224
|
+
// Uniform preparation must precede the render pass.
|
|
225
|
+
model.predraw(this.device.commandEncoder);
|
|
226
|
+
const pass = this.device.beginRenderPass({ framebuffer: target.framebuffer });
|
|
227
|
+
try {
|
|
228
|
+
pass.setParameters({ viewport: [0, 0, this.width, this.height] });
|
|
229
|
+
model.draw(pass);
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
pass.end();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=lightmap-baker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lightmap-baker.js","sourceRoot":"","sources":["../../src/lighting/lightmap-baker.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,4DAA4D;AAE5D,OAAO,EACL,MAAM,EACN,OAAO,EAKR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,cAAc,EAAC,MAAM,kBA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