Add sh1, sh2 support to sogs (#109)

* Add sh1, sh2 support to sogs

* Fix lint issues

---------

Co-authored-by: Diego Marcos Segura <diego.marcos@gmail.com>
This commit is contained in:
lucasoptml
2025-07-11 13:30:57 -05:00
committed by GitHub
parent 8d0267d7ff
commit 0c3bb74e1a
+19 -6
View File
@@ -97,9 +97,14 @@ export async function unpackPcSogs(
} }
if (json.shN) { if (json.shN) {
extra.sh1 = new Uint32Array(numSplats * 2); const useSH3 = json.shN.shape[1] >= 48 - 3;
extra.sh2 = new Uint32Array(numSplats * 4); const useSH2 = json.shN.shape[1] >= 27 - 3;
extra.sh3 = new Uint32Array(numSplats * 4); const useSH1 = json.shN.shape[1] >= 12 - 3;
if (useSH1) extra.sh1 = new Uint32Array(numSplats * 2);
if (useSH2) extra.sh2 = new Uint32Array(numSplats * 4);
if (useSH3) extra.sh3 = new Uint32Array(numSplats * 4);
const sh1 = new Float32Array(9); const sh1 = new Float32Array(9);
const sh2 = new Float32Array(15); const sh2 = new Float32Array(15);
const sh3 = new Float32Array(21); const sh3 = new Float32Array(21);
@@ -116,6 +121,7 @@ export async function unpackPcSogs(
const offset = row * centroids.width + col; const offset = row * centroids.width + col;
for (let d = 0; d < 3; ++d) { for (let d = 0; d < 3; ++d) {
if (useSH1) {
for (let k = 0; k < 3; ++k) { for (let k = 0; k < 3; ++k) {
sh1[k * 3 + d] = sh1[k * 3 + d] =
json.shN.mins + json.shN.mins +
@@ -123,6 +129,9 @@ export async function unpackPcSogs(
centroids.rgba[(offset + k) * 4 + d]) / centroids.rgba[(offset + k) * 4 + d]) /
255; 255;
} }
}
if (useSH2) {
for (let k = 0; k < 5; ++k) { for (let k = 0; k < 5; ++k) {
sh2[k * 3 + d] = sh2[k * 3 + d] =
json.shN.mins + json.shN.mins +
@@ -130,6 +139,9 @@ export async function unpackPcSogs(
centroids.rgba[(offset + 3 + k) * 4 + d]) / centroids.rgba[(offset + 3 + k) * 4 + d]) /
255; 255;
} }
}
if (useSH3) {
for (let k = 0; k < 7; ++k) { for (let k = 0; k < 7; ++k) {
sh3[k * 3 + d] = sh3[k * 3 + d] =
json.shN.mins + json.shN.mins +
@@ -138,10 +150,11 @@ export async function unpackPcSogs(
255; 255;
} }
} }
}
encodeSh1Rgb(extra.sh1 as Uint32Array, i, sh1); if (useSH1) encodeSh1Rgb(extra.sh1 as Uint32Array, i, sh1);
encodeSh2Rgb(extra.sh2 as Uint32Array, i, sh2); if (useSH2) encodeSh2Rgb(extra.sh2 as Uint32Array, i, sh2);
encodeSh3Rgb(extra.sh3 as Uint32Array, i, sh3); if (useSH3) encodeSh3Rgb(extra.sh3 as Uint32Array, i, sh3);
} }
} }