Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/scene/gsplat/gsplat-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { Mat4 } from '../../core/math/mat4.js';
import { Vec3 } from '../../core/math/vec3.js';
import { CULLFACE_NONE, SEMANTIC_ATTR13, SEMANTIC_POSITION, PIXELFORMAT_R32U } from '../../platform/graphics/constants.js';
import { MeshInstance } from '../mesh-instance.js';
import { GSplatResolveSH } from './gsplat-resolve-sh.js';
import { GSplatSorter } from './gsplat-sorter.js';
import { GSplatSogsData } from './gsplat-sogs-data.js';
import { ShaderMaterial } from '../materials/shader-material.js';
import { BLEND_NONE, BLEND_PREMULTIPLIED } from '../constants.js';

Expand Down Expand Up @@ -34,13 +36,16 @@ class GSplatInstance {

options = {};

/** @type {GSplatSorter | null} */
/** @type {GSplatSorter|null} */
sorter = null;

lastCameraPosition = new Vec3();

lastCameraDirection = new Vec3();

/** @type {GSplatResolveSH|null} */
resolveSH = null;

/**
* List of cameras this instance is visible for. Updated every frame by the renderer.
*
Expand Down Expand Up @@ -111,9 +116,17 @@ class GSplatInstance {
// update splat count on the material
this.material.setParameter('numSplats', count);
});

// configure sogs sh resolve
const { gsplatData } = resource;
if (gsplatData instanceof GSplatSogsData && gsplatData.shBands > 0 && !gsplatData.fullSH) {
this.resolveSH = new GSplatResolveSH(resource.device, this);
this.material.setDefine('SH_BANDS', '0');
}
}

destroy() {
this.resolveSH?.destroy();
this.material?.destroy();
this.meshInstance?.destroy();
this.sorter?.destroy();
Expand Down Expand Up @@ -212,6 +225,9 @@ class GSplatInstance {
const camera = this.cameras[0];
this.sort(camera._node);

// resolve spherical harmonics
this.resolveSH?.render(camera._node, this.meshInstance.node.getWorldTransform());

// we get new list of cameras each frame
this.cameras.length = 0;
}
Expand Down
Loading