Custom/extended splat encoding ranges, Premultiplied alpha for hyper-saturated colors (#134)

* Externalized SparkRenderer.maxPixelRadius and .minAlpha settings. Added to documentation. Added to examples/editor under Debug folder, moved sort32 there.

* Added SplatEncoding concept, applied individually to SparkRenderer (rgbMin/Max, lnScaleMinMax), SplatMesh (additionally sh1Min/Max, sh2, sh3). Updated examples/editor to control settings via gui. Updated all related code to pipe along settings where needed.
Added SparkRenderer.premultipliedAlpha to control blend mode and enable hyper-saturated color contributions by default.

* Fix SplatLoader not passing along encoding. Complete renaming to splat encoding.
This commit is contained in:
Andreas Sundquist
2025-07-23 10:04:24 -07:00
committed by GitHub
parent f4b4522c56
commit f60c2b0cf9
19 changed files with 568 additions and 149 deletions
+9 -4
View File
@@ -1,3 +1,4 @@
import type { SplatEncoding } from "./PackedSplats";
import {
computeMaxSplats,
encodeSh1Rgb,
@@ -352,7 +353,10 @@ export function decodeKsplat(
}
}
export function unpackKsplat(fileBytes: Uint8Array): {
export function unpackKsplat(
fileBytes: Uint8Array,
splatEncoding: SplatEncoding,
): {
packedArray: Uint32Array;
numSplats: number;
extra: Record<string, unknown>;
@@ -593,6 +597,7 @@ export function unpackKsplat(fileBytes: Uint8Array): {
r,
g,
b,
splatEncoding,
);
if (sphericalHarmonicsDegree >= 1) {
@@ -603,7 +608,7 @@ export function unpackKsplat(fileBytes: Uint8Array): {
for (const [i, key] of sh1Index.entries()) {
sh1[i] = getSh(splatOffset, key);
}
encodeSh1Rgb(extra.sh1 as Uint32Array, i, sh1);
encodeSh1Rgb(extra.sh1 as Uint32Array, i, sh1, splatEncoding);
}
if (sh2) {
if (!extra.sh2) {
@@ -612,7 +617,7 @@ export function unpackKsplat(fileBytes: Uint8Array): {
for (const [i, key] of sh2Index.entries()) {
sh2[i] = getSh(splatOffset, key);
}
encodeSh2Rgb(extra.sh2 as Uint32Array, i, sh2);
encodeSh2Rgb(extra.sh2 as Uint32Array, i, sh2, splatEncoding);
}
if (sh3) {
if (!extra.sh3) {
@@ -621,7 +626,7 @@ export function unpackKsplat(fileBytes: Uint8Array): {
for (const [i, key] of sh3Index.entries()) {
sh3[i] = getSh(splatOffset, key);
}
encodeSh3Rgb(extra.sh3 as Uint32Array, i, sh3);
encodeSh3Rgb(extra.sh3 as Uint32Array, i, sh3, splatEncoding);
}
}
}