Skip to content

Commit

Permalink
Default to rendering with SH (#174)
Browse files Browse the repository at this point in the history
* default to sh3

* update package version
  • Loading branch information
slimbuck authored Aug 22, 2024
1 parent d399017 commit 336f8a9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supersplat",
"version": "1.2.0",
"version": "1.2.1",
"author": "PlayCanvas<[email protected]>",
"homepage": "https://playcanvas.com/supersplat/editor",
"description": "3D Gaussian Splat Editor",
Expand Down
2 changes: 1 addition & 1 deletion src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ const registerEditorEvents = (events: Events, editHistory: EditHistory, scene: S

// view spherical harmonic bands

let viewBands = 0;
let viewBands = 3;

const setViewBands = (value: number) => {
if (value !== viewBands) {
Expand Down
38 changes: 22 additions & 16 deletions src/splat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,11 @@ class Splat extends Element {
// create the state texture
this.stateTexture = createTexture('splatState', PIXELFORMAT_L8);

let sh1to3: Texture;
let sh4to7: Texture;
let sh8to11: Texture;
let sh12to15: Texture;

// expect all SH or none
if (hasSH) {
// apply load-time transform to SH coefficients
Expand Down Expand Up @@ -377,10 +382,10 @@ class Splat extends Element {
}

// create the spherical harmonic textures
const sh1to3 = createTexture('splatSH_1to3', PIXELFORMAT_RGBA32U);
const sh4to7 = createTexture('splatSH_4to7', PIXELFORMAT_RGBA32U);
const sh8to11 = createTexture('splatSH_8to11', PIXELFORMAT_RGBA32U);
const sh12to15 = createTexture('splatSH_12to15', PIXELFORMAT_RGBA32U);
sh1to3 = createTexture('splatSH_1to3', PIXELFORMAT_RGBA32U);
sh4to7 = createTexture('splatSH_4to7', PIXELFORMAT_RGBA32U);
sh8to11 = createTexture('splatSH_8to11', PIXELFORMAT_RGBA32U);
sh12to15 = createTexture('splatSH_12to15', PIXELFORMAT_RGBA32U);

const sh1to3Data = sh1to3.lock();
const sh4to7Data = sh4to7.lock();
Expand Down Expand Up @@ -442,24 +447,29 @@ class Splat extends Element {
sh4to7.unlock();
sh8to11.unlock();
sh12to15.unlock();

instance.material.setParameter(`splatSH_1to3`, sh1to3);
instance.material.setParameter(`splatSH_4to7`, sh4to7);
instance.material.setParameter(`splatSH_8to11`, sh8to11);
instance.material.setParameter(`splatSH_12to15`, sh12to15);
}

this.rebuildMaterial = (bands: number) => {
const instance = this.entity.gsplat.instance;
instance.createMaterial(getMaterialOptions(hasSH ? bands : 0));

const material = instance.material;
material.setParameter('splatState', this.stateTexture);

if (hasSH) {
this.entity.gsplat.instance.createMaterial(getMaterialOptions(bands));
material.setParameter(`splatSH_1to3`, sh1to3);
material.setParameter(`splatSH_4to7`, sh4to7);
material.setParameter(`splatSH_8to11`, sh8to11);
material.setParameter(`splatSH_12to15`, sh12to15);
}

material.update();
};

this.localBoundStorage = instance.splat.aabb;
this.worldBoundStorage = instance.meshInstance._aabb;

instance.meshInstance._updateAabb = false;
instance.material.setParameter('splatState', this.stateTexture);

// when sort changes, re-render the scene
instance.sorter.on('updated', () => {
Expand Down Expand Up @@ -562,11 +572,7 @@ class Splat extends Element {
this.scene.boundDirty = true;

this.scene.events.on('view.bands', this.rebuildMaterial, this);

const bands = this.scene.events.invoke('view.bands');
if (bands !== 0) {
this.rebuildMaterial(bands);
}
this.rebuildMaterial(this.scene.events.invoke('view.bands'));
}

remove() {
Expand Down
2 changes: 1 addition & 1 deletion src/ui/view-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ViewPanel extends Container {
min: 0,
max: 3,
precision: 0,
value: 0
value: 3
});

shBandsRow.append(shBandsLabel);
Expand Down

0 comments on commit 336f8a9

Please sign in to comment.