rayzee 7.15.1 → 7.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/rayzee.es.js +117 -83
- package/dist/rayzee.es.js.map +1 -1
- package/dist/rayzee.umd.js +4 -4
- package/dist/rayzee.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/PathTracerApp.js +59 -15
- package/src/Processor/EmissiveTriangleBuilder.js +74 -20
- package/src/Processor/SceneProcessor.js +35 -5
- package/src/Stages/PathTracer.js +14 -0
- package/src/Stages/PathTracerStage.js +36 -8
- package/src/TSL/EmissiveSampling.js +11 -2
package/README.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Rayzee Engine
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/rayzee)
|
|
4
|
-
[](https://www.npmjs.com/package/rayzee)
|
|
5
5
|
[](https://www.npmjs.com/package/rayzee)
|
|
6
6
|
[](https://www.jsdelivr.com/package/npm/rayzee)
|
|
7
7
|
|
package/dist/rayzee.es.js
CHANGED
|
@@ -6026,48 +6026,49 @@ function qs(e, t) {
|
|
|
6026
6026
|
//#region src/Processor/EmissiveTriangleBuilder.js
|
|
6027
6027
|
var Js = class {
|
|
6028
6028
|
constructor() {
|
|
6029
|
-
this.emissiveTriangles = [], this.emissiveCount = 0, this.totalEmissivePower = 0, this.emissiveIndicesArray = null, this.emissivePowerArray = null, this.cdfArray = null, this.lightBVHNodeData = null, this.lightBVHNodeCount = 0, this.emissiveBitTrailMap = null, this._totalTriangleCount = 0;
|
|
6029
|
+
this.emissiveTriangles = [], this.emissiveCount = 0, this.totalEmissivePower = 0, this.emissiveIndicesArray = null, this.emissivePowerArray = null, this.cdfArray = null, this.lightBVHNodeData = null, this.lightBVHNodeCount = 0, this.emissiveBitTrailMap = null, this._totalTriangleCount = 0, this._hiddenMeshes = /* @__PURE__ */ new Set();
|
|
6030
6030
|
}
|
|
6031
6031
|
extractEmissiveTriangles(e, t, n) {
|
|
6032
6032
|
console.log("[EmissiveTriangleBuilder] Extracting emissive triangles..."), this.emissiveTriangles = [], this.totalEmissivePower = 0, this._totalTriangleCount = n;
|
|
6033
|
-
let r = Z.FLOATS_PER_TRIANGLE, i = Z.UV_C_MAT_OFFSET + 2;
|
|
6034
|
-
for (let
|
|
6035
|
-
let n =
|
|
6036
|
-
if (!
|
|
6037
|
-
let
|
|
6033
|
+
let r = Z.FLOATS_PER_TRIANGLE, i = Z.UV_C_MAT_OFFSET + 2, a = Z.UV_C_MAT_OFFSET + 3;
|
|
6034
|
+
for (let o = 0; o < n; o++) {
|
|
6035
|
+
let n = o * r, s = Math.floor(e[n + i]), c = Math.floor(e[n + a]), l = t[s];
|
|
6036
|
+
if (!l) continue;
|
|
6037
|
+
let u = l.emissive || {
|
|
6038
6038
|
r: 0,
|
|
6039
6039
|
g: 0,
|
|
6040
6040
|
b: 0
|
|
6041
|
-
},
|
|
6042
|
-
if (
|
|
6043
|
-
let t = e[n + 0], r = e[n + 1], i = e[n + 2],
|
|
6044
|
-
|
|
6045
|
-
let
|
|
6041
|
+
}, d = l.emissiveIntensity || 0;
|
|
6042
|
+
if (d > 0 && (u.r > 0 || u.g > 0 || u.b > 0)) {
|
|
6043
|
+
let t = e[n + 0], r = e[n + 1], i = e[n + 2], a = e[n + 4], f = e[n + 5], p = e[n + 6], m = e[n + 8], h = e[n + 9], g = e[n + 10], _ = this._calculateTriangleArea(t, r, i, a, f, p, m, h, g), v = (.2126 * u.r + .7152 * u.g + .0722 * u.b) * d * _, y = (f - r) * (g - i) - (p - i) * (h - r), b = (p - i) * (m - t) - (a - t) * (g - i), x = (a - t) * (h - r) - (f - r) * (m - t), S = Math.sqrt(y * y + b * b + x * x) || 1, C = l.side === 1 ? -1 : 1;
|
|
6044
|
+
y = y / S * C, b = b / S * C, x = x / S * C;
|
|
6045
|
+
let w = l.side === 2, T = (t + a + m) / 3, E = (r + f + h) / 3, D = (i + p + g) / 3, O = Math.min(t, a, m), k = Math.min(r, f, h), A = Math.min(i, p, g), j = Math.max(t, a, m), M = Math.max(r, f, h), ee = Math.max(i, p, g);
|
|
6046
6046
|
this.emissiveTriangles.push({
|
|
6047
|
-
triangleIndex:
|
|
6048
|
-
materialIndex:
|
|
6049
|
-
|
|
6050
|
-
|
|
6047
|
+
triangleIndex: o,
|
|
6048
|
+
materialIndex: s,
|
|
6049
|
+
meshIndex: c,
|
|
6050
|
+
power: v,
|
|
6051
|
+
area: _,
|
|
6051
6052
|
emissive: {
|
|
6052
|
-
r:
|
|
6053
|
-
g:
|
|
6054
|
-
b:
|
|
6053
|
+
r: u.r,
|
|
6054
|
+
g: u.g,
|
|
6055
|
+
b: u.b
|
|
6055
6056
|
},
|
|
6056
|
-
emissiveIntensity:
|
|
6057
|
-
cx:
|
|
6058
|
-
cy:
|
|
6059
|
-
cz:
|
|
6060
|
-
bMinX:
|
|
6061
|
-
bMinY:
|
|
6062
|
-
bMinZ:
|
|
6063
|
-
bMaxX:
|
|
6064
|
-
bMaxY:
|
|
6065
|
-
bMaxZ:
|
|
6066
|
-
nx:
|
|
6067
|
-
ny:
|
|
6068
|
-
nz:
|
|
6069
|
-
twoSided:
|
|
6070
|
-
}), this.totalEmissivePower +=
|
|
6057
|
+
emissiveIntensity: d,
|
|
6058
|
+
cx: T,
|
|
6059
|
+
cy: E,
|
|
6060
|
+
cz: D,
|
|
6061
|
+
bMinX: O,
|
|
6062
|
+
bMinY: k,
|
|
6063
|
+
bMinZ: A,
|
|
6064
|
+
bMaxX: j,
|
|
6065
|
+
bMaxY: M,
|
|
6066
|
+
bMaxZ: ee,
|
|
6067
|
+
nx: y,
|
|
6068
|
+
ny: b,
|
|
6069
|
+
nz: x,
|
|
6070
|
+
twoSided: w
|
|
6071
|
+
}), this.totalEmissivePower += v;
|
|
6071
6072
|
}
|
|
6072
6073
|
}
|
|
6073
6074
|
return this.emissiveCount = this.emissiveTriangles.length, console.log(`[EmissiveTriangleBuilder] Found ${this.emissiveCount} emissive triangles (${(this.emissiveCount / n * 100).toFixed(2)}%)`), console.log(`[EmissiveTriangleBuilder] Total emissive power: ${this.totalEmissivePower.toFixed(2)}`), this._buildDataArrays(), this.emissiveCount;
|
|
@@ -6161,44 +6162,57 @@ var Js = class {
|
|
|
6161
6162
|
if (s !== this.emissiveTriangles.some((t) => t.materialIndex === e)) return this.extractEmissiveTriangles(n, r, i), !0;
|
|
6162
6163
|
if (!s) return !1;
|
|
6163
6164
|
let c = .2126 * a.r + .7152 * a.g + .0722 * a.b;
|
|
6164
|
-
this.
|
|
6165
|
-
|
|
6166
|
-
|
|
6167
|
-
|
|
6168
|
-
|
|
6169
|
-
|
|
6170
|
-
|
|
6171
|
-
|
|
6165
|
+
for (let t of this.emissiveTriangles) t.materialIndex === e && (t.power = c * o * t.area, t.emissive = {
|
|
6166
|
+
r: a.r,
|
|
6167
|
+
g: a.g,
|
|
6168
|
+
b: a.b
|
|
6169
|
+
}, t.emissiveIntensity = o);
|
|
6170
|
+
return !0;
|
|
6171
|
+
}
|
|
6172
|
+
setHiddenMeshes(e) {
|
|
6173
|
+
let t = /* @__PURE__ */ new Set();
|
|
6174
|
+
for (let e of this.emissiveTriangles) t.add(e.meshIndex);
|
|
6175
|
+
let n = /* @__PURE__ */ new Set();
|
|
6176
|
+
for (let r of e) t.has(r) && n.add(r);
|
|
6177
|
+
let r = this._hiddenMeshes, i = n.size !== r.size;
|
|
6178
|
+
if (!i) {
|
|
6179
|
+
for (let e of n) if (!r.has(e)) {
|
|
6180
|
+
i = !0;
|
|
6181
|
+
break;
|
|
6182
|
+
}
|
|
6172
6183
|
}
|
|
6173
|
-
return this.
|
|
6184
|
+
return this._hiddenMeshes = n, i;
|
|
6174
6185
|
}
|
|
6175
6186
|
buildLightBVH() {
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
|
|
6187
|
+
let e = this._hiddenMeshes.size === 0 ? this.emissiveTriangles : this.emissiveTriangles.filter((e) => !this._hiddenMeshes.has(e.meshIndex));
|
|
6188
|
+
this.emissiveCount = e.length, this.totalEmissivePower = 0;
|
|
6189
|
+
for (let t of e) this.totalEmissivePower += t.power;
|
|
6190
|
+
if (e.length === 0) return this.lightBVHNodeData = new Float32Array(16), this.lightBVHNodeData[7] = 1, this.lightBVHNodeData[14] = 1, this.lightBVHNodeData[15] = -1, this.lightBVHNodeCount = 1, this.emissiveBitTrailMap = new Float32Array(Math.max(this._totalTriangleCount, 1)).fill(-1), this.emissiveIndicesArray = new Int32Array(), this.emissivePowerArray = new Float32Array(), this._buildCDF(), this.emissiveTriangleData = new Float32Array(8), 1;
|
|
6191
|
+
let { nodeData: t, nodeCount: n, sortedPerm: r, bitTrails: i } = new Gs().build(e);
|
|
6192
|
+
this.lightBVHNodeData = t, this.lightBVHNodeCount = n, this._rebuildSortedEmissiveData(r, e), this.emissiveBitTrailMap = new Float32Array(Math.max(this._totalTriangleCount, 1)).fill(-1);
|
|
6193
|
+
for (let t = 0; t < r.length; t++) {
|
|
6194
|
+
let n = e[r[t]].triangleIndex;
|
|
6195
|
+
this.emissiveBitTrailMap[n] = i[t];
|
|
6182
6196
|
}
|
|
6183
|
-
return
|
|
6197
|
+
return n;
|
|
6184
6198
|
}
|
|
6185
|
-
_rebuildSortedEmissiveData(e) {
|
|
6186
|
-
let
|
|
6187
|
-
this.emissiveIndicesArray = new Int32Array(
|
|
6188
|
-
for (let
|
|
6189
|
-
let
|
|
6190
|
-
this.emissiveIndicesArray[
|
|
6199
|
+
_rebuildSortedEmissiveData(e, t) {
|
|
6200
|
+
let n = e.length;
|
|
6201
|
+
this.emissiveIndicesArray = new Int32Array(n), this.emissivePowerArray = new Float32Array(n);
|
|
6202
|
+
for (let r = 0; r < n; r++) {
|
|
6203
|
+
let n = e[r];
|
|
6204
|
+
this.emissiveIndicesArray[r] = t[n].triangleIndex, this.emissivePowerArray[r] = t[n].power;
|
|
6191
6205
|
}
|
|
6192
6206
|
this._buildCDF();
|
|
6193
|
-
let
|
|
6194
|
-
for (let
|
|
6195
|
-
let
|
|
6196
|
-
|
|
6207
|
+
let r = new Float32Array(n * 8);
|
|
6208
|
+
for (let i = 0; i < n; i++) {
|
|
6209
|
+
let n = t[e[i]], a = i * 8;
|
|
6210
|
+
r[a + 0] = n.triangleIndex, r[a + 1] = n.power, r[a + 2] = this.cdfArray[i], r[a + 3] = this.totalEmissivePower > 0 ? n.power / this.totalEmissivePower : 0, r[a + 4] = n.emissive.r * n.emissiveIntensity, r[a + 5] = n.emissive.g * n.emissiveIntensity, r[a + 6] = n.emissive.b * n.emissiveIntensity, r[a + 7] = n.area;
|
|
6197
6211
|
}
|
|
6198
|
-
this.emissiveTriangleData =
|
|
6212
|
+
this.emissiveTriangleData = r, console.log(`[EmissiveTriangleBuilder] Rebuilt sorted emissive data: ${n} entries`);
|
|
6199
6213
|
}
|
|
6200
6214
|
clear() {
|
|
6201
|
-
this.emissiveTriangles = [], this.emissiveCount = 0, this.totalEmissivePower = 0, this.emissiveIndicesArray = null, this.emissivePowerArray = null, this.cdfArray = null, this.lightBVHNodeData = null, this.lightBVHNodeCount = 0, this.emissiveBitTrailMap = null, this._totalTriangleCount = 0;
|
|
6215
|
+
this.emissiveTriangles = [], this.emissiveCount = 0, this.totalEmissivePower = 0, this.emissiveIndicesArray = null, this.emissivePowerArray = null, this.cdfArray = null, this.lightBVHNodeData = null, this.lightBVHNodeCount = 0, this.emissiveBitTrailMap = null, this._totalTriangleCount = 0, this._hiddenMeshes = /* @__PURE__ */ new Set();
|
|
6202
6216
|
}
|
|
6203
6217
|
}, Ys = class {
|
|
6204
6218
|
constructor(e = "Build") {
|
|
@@ -6558,7 +6572,7 @@ var Js = class {
|
|
|
6558
6572
|
for (let n of this.materials) n.map = t(n.map, e.albedo), n.emissiveMap = t(n.emissiveMap, e.emissive), n.normalMap = t(n.normalMap, e.normal), n.bumpMap = t(n.bumpMap, e.bump), n.roughnessMap = t(n.roughnessMap, e.roughness), n.metalnessMap = t(n.metalnessMap, e.metalness), n.displacementMap = t(n.displacementMap, e.displacement), n.anisotropyMap = t(n.anisotropyMap, e.anisotropy), n.transmissionMap = t(n.transmissionMap, e.transmission), n.clearcoatMap = t(n.clearcoatMap, e.clearcoat), n.clearcoatRoughnessMap = t(n.clearcoatRoughnessMap, e.clearcoatRoughness), n.sheenColorMap = t(n.sheenColorMap, e.sheenColor), n.sheenRoughnessMap = t(n.sheenRoughnessMap, e.sheenRoughness), n.iridescenceMap = t(n.iridescenceMap, e.iridescence), n.iridescenceThicknessMap = t(n.iridescenceThicknessMap, e.iridescenceThickness), n.specularIntensityMap = t(n.specularIntensityMap, e.specularIntensity), n.specularColorMap = t(n.specularColorMap, e.specularColor);
|
|
6559
6573
|
}
|
|
6560
6574
|
_buildEmissiveData() {
|
|
6561
|
-
this.emissiveTriangleCount = this.emissiveTriangleBuilder.extractEmissiveTriangles(this.triangleData, this.materials, this.triangleCount), this.emissiveTriangleData = this.emissiveTriangleBuilder.createEmissiveRawData(), this.emissiveTotalPower = this.emissiveTriangleBuilder.totalEmissivePower, this._log("Emissive triangle extraction complete", this.emissiveTriangleBuilder.getStats()), this.emissiveTriangleBuilder.buildLightBVH(), this.lightBVHNodeData = this.emissiveTriangleBuilder.lightBVHNodeData, this.lightBVHNodeCount = this.emissiveTriangleBuilder.lightBVHNodeCount, this.emissiveTriangleData = this.emissiveTriangleBuilder.emissiveTriangleData || this.emissiveTriangleData, this.emissiveBitTrailMap = this.emissiveTriangleBuilder.emissiveBitTrailMap;
|
|
6575
|
+
this.emissiveTriangleCount = this.emissiveTriangleBuilder.extractEmissiveTriangles(this.triangleData, this.materials, this.triangleCount), this.emissiveTriangleData = this.emissiveTriangleBuilder.createEmissiveRawData(), this.emissiveTotalPower = this.emissiveTriangleBuilder.totalEmissivePower, this._log("Emissive triangle extraction complete", this.emissiveTriangleBuilder.getStats()), this.emissiveTriangleBuilder.buildLightBVH(), this.lightBVHNodeData = this.emissiveTriangleBuilder.lightBVHNodeData, this.lightBVHNodeCount = this.emissiveTriangleBuilder.lightBVHNodeCount, this.emissiveTriangleData = this.emissiveTriangleBuilder.emissiveTriangleData || this.emissiveTriangleData, this.emissiveBitTrailMap = this.emissiveTriangleBuilder.emissiveBitTrailMap, this.emissiveTriangleCount = this.emissiveTriangleBuilder.emissiveCount, this.emissiveTotalPower = this.emissiveTriangleBuilder.totalEmissivePower;
|
|
6562
6576
|
}
|
|
6563
6577
|
_createSpheres() {
|
|
6564
6578
|
return [];
|
|
@@ -6713,14 +6727,20 @@ var Js = class {
|
|
|
6713
6727
|
updateMaterialEmissive(e, t, n) {
|
|
6714
6728
|
if (!this.emissiveTriangleBuilder) return null;
|
|
6715
6729
|
let r = this.materials[e];
|
|
6716
|
-
return !r || (t === "emissive" ? r.emissive = n : t === "emissiveIntensity" && (r.emissiveIntensity = n), !this.emissiveTriangleBuilder.updateMaterialEmissive(e, r, this.triangleData, this.materials, this.triangleCount)) ? null :
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
|
|
6730
|
+
return !r || (t === "emissive" ? r.emissive = n : t === "emissiveIntensity" && (r.emissiveIntensity = n), !this.emissiveTriangleBuilder.updateMaterialEmissive(e, r, this.triangleData, this.materials, this.triangleCount)) ? null : this._collectEmissivePayload();
|
|
6731
|
+
}
|
|
6732
|
+
rebuildEmissiveForVisibility(e, t = !1) {
|
|
6733
|
+
return !this.emissiveTriangleBuilder || !this.emissiveTriangleBuilder.setHiddenMeshes(e) && !t ? null : this._collectEmissivePayload();
|
|
6734
|
+
}
|
|
6735
|
+
_collectEmissivePayload() {
|
|
6736
|
+
return this.emissiveTriangleBuilder.buildLightBVH(), this.lightBVHNodeData = this.emissiveTriangleBuilder.lightBVHNodeData, this.lightBVHNodeCount = this.emissiveTriangleBuilder.lightBVHNodeCount, this.emissiveTriangleData = this.emissiveTriangleBuilder.emissiveTriangleData, this.emissiveBitTrailMap = this.emissiveTriangleBuilder.emissiveBitTrailMap, this.emissiveTriangleCount = this.emissiveTriangleBuilder.emissiveCount, this.emissiveTotalPower = this.emissiveTriangleBuilder.totalEmissivePower, {
|
|
6737
|
+
rawData: this.emissiveTriangleData,
|
|
6738
|
+
emissiveCount: this.emissiveTriangleCount,
|
|
6739
|
+
totalPower: this.emissiveTotalPower,
|
|
6720
6740
|
bitTrailMap: this.emissiveBitTrailMap,
|
|
6721
6741
|
lightBVHNodeData: this.lightBVHNodeData,
|
|
6722
6742
|
lightBVHNodeCount: this.lightBVHNodeCount
|
|
6723
|
-
}
|
|
6743
|
+
};
|
|
6724
6744
|
}
|
|
6725
6745
|
_updateMeshTrianglePositions(e, t) {
|
|
6726
6746
|
let n = Z.FLOATS_PER_TRIANGLE, r = Z.POSITION_A_OFFSET, i = Z.POSITION_B_OFFSET, a = Z.POSITION_C_OFFSET, o = Z.NORMAL_A_OFFSET, s = Z.NORMAL_B_OFFSET, c = Z.NORMAL_C_OFFSET, l = e.bvhToOriginal;
|
|
@@ -7188,7 +7208,7 @@ var cc = 4, lc = class extends $n {
|
|
|
7188
7208
|
}, this.environment = new _i(this.scene, this.uniforms), this.environment.callbacks.onReset = () => this.reset(), this.environment.callbacks.getSceneTextureNodes = () => this.shaderBuilder.getSceneTextureNodes(), this.shaderBuilder = new us(), this._initRenderingState(), this.setupBlueNoise(), this.tempVector2 = new nn(), this.lastCameraMatrix = new bt(), this.lastProjectionMatrix = new bt(), this.lastRenderMode = -1, this.renderModeChangeTimeout = null, this.renderModeChangeDelay = 50, this.pendingRenderMode = null, this.lastInteractionModeState = !1, this.cameraChanged = !1, this.updateCompletionThreshold();
|
|
7189
7209
|
}
|
|
7190
7210
|
_initDataTextures() {
|
|
7191
|
-
this.triangleStorageAttr = null, this.triangleStorageNode = null, this.triangleCount = 0, this.bvhStorageAttr = null, this.bvhStorageNode = null, this.bvhNodeCount = 0, this.directionalLightsData = null, this.pointLightsData = null, this.spotLightsData = null, this.areaLightsData = null, this.goboMaps = null, this.iesProfiles = null, this.stbnScalarTexture = null, this.stbnVec2Texture = null, this.lightStorageAttr = new o(new Float32Array(16), 4), this.lightStorageNode = Se(this.lightStorageAttr, "vec4", 1).toReadOnly(), this._lbvhDataCache = null, this._emissiveDataCache = null, this._bitTrailMapCache = null, this._instanceTable = null, this.spheres = [];
|
|
7211
|
+
this.triangleStorageAttr = null, this.triangleStorageNode = null, this.triangleCount = 0, this.bvhStorageAttr = null, this.bvhStorageNode = null, this.bvhNodeCount = 0, this.directionalLightsData = null, this.pointLightsData = null, this.spotLightsData = null, this.areaLightsData = null, this.goboMaps = null, this.iesProfiles = null, this.stbnScalarTexture = null, this.stbnVec2Texture = null, this.lightStorageAttr = new o(new Float32Array(16), 4), this.lightStorageNode = Se(this.lightStorageAttr, "vec4", 1).toReadOnly(), this._lightBufferRealloc = !1, this._lbvhDataCache = null, this._emissiveDataCache = null, this._bitTrailMapCache = null, this._instanceTable = null, this.spheres = [];
|
|
7192
7212
|
}
|
|
7193
7213
|
_defineUniformGetters() {
|
|
7194
7214
|
let e = this.uniforms;
|
|
@@ -7478,8 +7498,15 @@ var cc = 4, lc = class extends $n {
|
|
|
7478
7498
|
this.stbnScalarTexture = e, e && (Fn.value = e);
|
|
7479
7499
|
}
|
|
7480
7500
|
_rebuildLightBuffer() {
|
|
7481
|
-
let e = this._lbvhDataCache, t = this._emissiveDataCache, n = this._bitTrailMapCache, r = e ? e.length : 0, i = t ? t.length : 0, a = n ? Math.ceil(n.length / 4) * 4 : 0, s = Math.max(r + i + a, 4)
|
|
7482
|
-
|
|
7501
|
+
let e = this._lbvhDataCache, t = this._emissiveDataCache, n = this._bitTrailMapCache, r = e ? e.length : 0, i = t ? t.length : 0, a = n ? Math.ceil(n.length / 4) * 4 : 0, s = Math.max(r + i + a, 4);
|
|
7502
|
+
if (this.lightStorageAttr && s <= this.lightStorageAttr.array.length) {
|
|
7503
|
+
let a = this.lightStorageAttr.array;
|
|
7504
|
+
e && a.set(e, 0), t && a.set(t, r), n && a.set(n, r + i), this.lightStorageAttr.needsUpdate = !0;
|
|
7505
|
+
} else {
|
|
7506
|
+
let a = new Float32Array(s);
|
|
7507
|
+
e && a.set(e, 0), t && a.set(t, r), n && a.set(n, r + i), this.lightStorageAttr = new o(a, 4), this.lightStorageNode.value = this.lightStorageAttr, this.lightStorageNode.bufferCount = a.length / 4, this._lightBufferRealloc = !0;
|
|
7508
|
+
}
|
|
7509
|
+
this.emissiveVec4Offset.value = (this.lightBVHNodeCount.value || 0) * 4, this.reverseMapVec4Offset.value = (r + i) / 4;
|
|
7483
7510
|
}
|
|
7484
7511
|
setEmissiveTriangleData(e, t, n = 0, r = null) {
|
|
7485
7512
|
e && (this._emissiveDataCache = e, r && (this._bitTrailMapCache = r), this.emissiveTriangleCount.value = t, this.emissiveTotalPower.value = n, this._rebuildLightBuffer(), console.log(`PathTracer: ${t} emissive triangles, totalPower=${n.toFixed(4)} (storage buffer)`));
|
|
@@ -8896,8 +8923,8 @@ var vl = /* @__PURE__ */ G("\n fn equirectDirectionToUv( direction: vec3f, envir
|
|
|
8896
8923
|
}), cu = f(([e, t, n, r]) => {
|
|
8897
8924
|
let i = t.sub(e), a = n.sub(e), o = n.sub(t), s = F(A(i, i), F(A(a, a), A(o, o))), c = O(i, a), l = A(c, c), u = T(!1).toVar();
|
|
8898
8925
|
return p(l.greaterThan(1e-20), () => {
|
|
8899
|
-
let t = A(c, r.sub(e)), n = t.mul(t).div(l);
|
|
8900
|
-
u.assign(s.greaterThan(n));
|
|
8926
|
+
let t = A(c, r.sub(e)), n = t.mul(t).div(l), i = s.mul(s).lessThan(l.mul(64));
|
|
8927
|
+
u.assign(s.greaterThan(n).and(i));
|
|
8901
8928
|
}), u;
|
|
8902
8929
|
}), lu = wn({
|
|
8903
8930
|
direction: "vec3",
|
|
@@ -9818,7 +9845,7 @@ var Yu = class extends lc {
|
|
|
9818
9845
|
super.setupMaterial(), this.materialData?.materialCount > 0 && (this._kernelManager && this._kernelManager.dispose(), this._wavefrontReady = !1, this._buildWavefrontKernels());
|
|
9819
9846
|
}
|
|
9820
9847
|
render(e) {
|
|
9821
|
-
if (!this.isReady || !this._wavefrontReady) return;
|
|
9848
|
+
if (!this.isReady || !this._wavefrontReady || this._lightBufferRealloc && (this._kernelManager && this._kernelManager.dispose(), this._wavefrontReady = !1, this._buildWavefrontKernels(), !this._wavefrontReady)) return;
|
|
9822
9849
|
if (this.isComplete || this.frameCount >= this.completionThreshold || this._isConvergedComplete()) {
|
|
9823
9850
|
this.isComplete ||= !0;
|
|
9824
9851
|
return;
|
|
@@ -9957,6 +9984,7 @@ var Yu = class extends lc {
|
|
|
9957
9984
|
_buildWavefrontKernels() {
|
|
9958
9985
|
let e = this.shaderBuilder.getSceneTextureNodes();
|
|
9959
9986
|
if (!e) return;
|
|
9987
|
+
this._lightBufferRealloc = !1;
|
|
9960
9988
|
let t = this.storageTextures.renderWidth, n = this.storageTextures.renderHeight, r = t * n;
|
|
9961
9989
|
this._bounceEarlyExitThreshold !== -1 && (this._bounceEarlyExitThreshold = Math.max(100, Math.floor(r / 1e3))), this._packedBuffers ? this._packedBuffers.resize(r) : this._packedBuffers = new hc(r, this.renderer);
|
|
9962
9990
|
let i = hc.requiredCapacity(r) * 1;
|
|
@@ -16360,7 +16388,7 @@ var Yf = {
|
|
|
16360
16388
|
status: "Transferring data to GPU...",
|
|
16361
16389
|
progress: 86
|
|
16362
16390
|
}), await new Promise((e) => setTimeout(e, 0)), e.start("GPU data transfer"), !this._sdf.uploadToPathTracer(this.stages.pathTracer, this.lightManager, this.meshScene, t)) return !1;
|
|
16363
|
-
this.stages.pathTracer._meshRefs = this.stages.pathTracer._collectMeshRefs(this.meshScene), this.stages.pathTracer.setMeshVisibilityData(this.stages.pathTracer._meshRefs), e.end("GPU data transfer"), ir({
|
|
16391
|
+
this.stages.pathTracer._meshRefs = this.stages.pathTracer._collectMeshRefs(this.meshScene), this.stages.pathTracer.setMeshVisibilityData(this.stages.pathTracer._meshRefs), this._refreshEmissiveForVisibility(), e.end("GPU data transfer"), ir({
|
|
16364
16392
|
status: "Compiling shaders...",
|
|
16365
16393
|
progress: 90
|
|
16366
16394
|
}), await new Promise((e) => setTimeout(e, 0)), e.start("Material setup (TSL compile)"), this.stages.pathTracer.setupMaterial(), e.end("Material setup (TSL compile)"), e.start("Pipeline precompile");
|
|
@@ -16375,7 +16403,7 @@ var Yf = {
|
|
|
16375
16403
|
}), await n, this.stages.pathTracer.environment.applyCDFResults());
|
|
16376
16404
|
let r = this.getSceneMinY();
|
|
16377
16405
|
if (this.settings.set("groundProjectionLevel", r, { reset: !1 }), this.settings.set("groundCatcherHeight", r, { reset: !1 }), !this._emissiveSamplingUserSet) {
|
|
16378
|
-
let e = (this._sdf?.emissiveTriangleCount ?? 0) > 0;
|
|
16406
|
+
let e = (this._sdf?.emissiveTriangleBuilder?.emissiveTriangles?.length ?? this._sdf?.emissiveTriangleCount ?? 0) > 0;
|
|
16379
16407
|
this.settings.set("enableEmissiveTriangleSampling", e, { reset: !1 });
|
|
16380
16408
|
}
|
|
16381
16409
|
return e.start("Apply settings"), this.settings.applyAll(), this.stages.compositor.setTransparentBackground(this.settings.get("transparentBackground")), e.end("Apply settings"), e.print(), rr(), this._initAnimationAndTransforms(), this.dispatchEvent({ type: "SceneRebuild" }), !0;
|
|
@@ -16553,23 +16581,29 @@ var Yf = {
|
|
|
16553
16581
|
return Number.isFinite(e.min.y) ? e.min.y : 0;
|
|
16554
16582
|
}
|
|
16555
16583
|
setMaterialProperty(e, t, n) {
|
|
16556
|
-
|
|
16557
|
-
|
|
16558
|
-
|
|
16559
|
-
|
|
16560
|
-
|
|
16584
|
+
this.stages.pathTracer?.materialData.updateMaterialProperty(e, t, n), ["emissive", "emissiveIntensity"].includes(t) && this._sdf && this._uploadEmissivePayload(this._sdf.updateMaterialEmissive(e, t, n)), this.reset();
|
|
16585
|
+
}
|
|
16586
|
+
_uploadEmissivePayload(e) {
|
|
16587
|
+
!e || !this.stages.pathTracer || (this.stages.pathTracer.setEmissiveTriangleData(e.rawData, e.emissiveCount, e.totalPower, e.bitTrailMap), e.lightBVHNodeData && this.stages.pathTracer.setLightBVHData(e.lightBVHNodeData, e.lightBVHNodeCount));
|
|
16588
|
+
}
|
|
16589
|
+
_refreshEmissiveForVisibility() {
|
|
16590
|
+
let e = this._sdf?.instanceTable?.entries;
|
|
16591
|
+
if (!e) return;
|
|
16592
|
+
let t = /* @__PURE__ */ new Set();
|
|
16593
|
+
for (let n of e) n && n.visible === !1 && t.add(n.meshIndex);
|
|
16594
|
+
this._uploadEmissivePayload(this._sdf.rebuildEmissiveForVisibility(t));
|
|
16561
16595
|
}
|
|
16562
16596
|
setEmissiveTriangleSampling(e) {
|
|
16563
16597
|
this._emissiveSamplingUserSet = !0, this.settings.set("enableEmissiveTriangleSampling", e);
|
|
16564
16598
|
}
|
|
16565
16599
|
hasEmissiveGeometry() {
|
|
16566
|
-
return (this._sdf?.emissiveTriangleCount ?? 0) > 0;
|
|
16600
|
+
return (this._sdf?.emissiveTriangleBuilder?.emissiveTriangles?.length ?? this._sdf?.emissiveTriangleCount ?? 0) > 0;
|
|
16567
16601
|
}
|
|
16568
16602
|
setMeshVisibility(e, t) {
|
|
16569
|
-
this.stages.pathTracer?.updateMeshVisibility(e, t), this.reset();
|
|
16603
|
+
this.stages.pathTracer?.updateMeshVisibility(e, t), this._refreshEmissiveForVisibility(), this.reset();
|
|
16570
16604
|
}
|
|
16571
16605
|
updateAllMeshVisibility() {
|
|
16572
|
-
this.stages.pathTracer?.updateAllMeshVisibility(), this.reset();
|
|
16606
|
+
this.stages.pathTracer?.updateAllMeshVisibility(), this._refreshEmissiveForVisibility(), this.reset();
|
|
16573
16607
|
}
|
|
16574
16608
|
getScene() {
|
|
16575
16609
|
return this.meshScene || this.scene;
|