Skip to content

Commit 40b1982

Browse files
authored
Fix SOG SH decompression (playcanvas#8271)
1 parent f38da47 commit 40b1982

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

src/framework/parsers/sog-bundle.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ class SogBundleParser {
268268
data.sh0 = textures[meta.sh0.files[0]].resource;
269269
data.sh_centroids = textures[meta.shN?.files[0]]?.resource;
270270
data.sh_labels = textures[meta.shN?.files[1]]?.resource;
271+
data.shBands = GSplatSogsData.calcBands(data.sh_centroids?.width);
271272

272273
if (!decompress) {
273274
// no need to prepare gpu data if decompressing

src/framework/parsers/sogs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class SogsParser {
196196
data.sh0 = textures.sh0[0].resource;
197197
data.sh_centroids = textures.shN?.[0]?.resource;
198198
data.sh_labels = textures.shN?.[1]?.resource;
199+
data.shBands = GSplatSogsData.calcBands(data.sh_centroids?.width);
199200

200201
const decompress = asset.data?.decompress;
201202
const minimalMemory = asset.options?.minimalMemory ?? false;

src/scene/gsplat/gsplat-sogs-data.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,11 @@ class GSplatSogsData {
217217
destroyed = false;
218218

219219
/**
220-
* Cached number of spherical harmonics bands.
220+
* Number of spherical harmonics bands.
221221
*
222222
* @type {number}
223-
* @private
224223
*/
225-
_shBands = 0;
224+
shBands = 0;
226225

227226
_destroyGpuResources() {
228227
this.means_l?.destroy();
@@ -237,6 +236,13 @@ class GSplatSogsData {
237236
this.packedShN?.destroy();
238237
}
239238

239+
// calculate the number of bands given the centroids texture width
240+
static calcBands(centroidsWidth) {
241+
// sh palette has 64 sh entries per row: 192 = 1 band (64*3), 512 = 2 bands (64*8), 960 = 3 bands (64*15)
242+
const shBandsWidths = { 192: 1, 512: 2, 960: 3 };
243+
return shBandsWidths[centroidsWidth] ?? 0;
244+
}
245+
240246
destroy() {
241247
// Remove devicerestored listener if it was registered
242248
this.deviceRestoredEvent?.off();
@@ -293,10 +299,6 @@ class GSplatSogsData {
293299
return true;
294300
}
295301

296-
get shBands() {
297-
return this._shBands;
298-
}
299-
300302
async decompress() {
301303
const members = [
302304
'x', 'y', 'z',
@@ -543,11 +545,6 @@ class GSplatSogsData {
543545

544546
if (this.destroyed || !device || device._destroyed) return;
545547

546-
// Cache shBands from sh_centroids texture width before source textures may be destroyed
547-
// sh palette has 64 sh entries per row: 192 = 1 band (64*3), 512 = 2 bands (64*8), 960 = 3 bands (64*15)
548-
const shBandsWidths = { 192: 1, 512: 2, 960: 3 };
549-
this._shBands = shBandsWidths[this.sh_centroids?.width] ?? 0;
550-
551548
// Include URL in texture name for debugging
552549
const urlSuffix = this.url ? `_${this.url}` : '';
553550

0 commit comments

Comments
 (0)