From 5a80551ed944ad6011b967fa55b293e76bee5b7b Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Thu, 31 Oct 2024 11:15:46 +0000 Subject: [PATCH] fix --- src/splat.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/splat.ts b/src/splat.ts index c19b9fb..a469993 100644 --- a/src/splat.ts +++ b/src/splat.ts @@ -68,18 +68,15 @@ class Splat extends Element { const splatData = splatResource.splatData; // get material options object for a shader that renders with the given number of bands - const getMaterialOptions = (bands: number) => { - return { - vertex: vertexShader, - fragment: fragmentShader, - defines: ['USE_SH1', 'USE_SH2', 'USE_SH3'].splice(0, bands) - }; + const materialOptions = { + vertex: vertexShader, + fragment: fragmentShader }; this.asset = asset; this.splatData = splatData; this.numSplats = splatData.numSplats; - this.entity = splatResource.instantiate(getMaterialOptions(0)); + this.entity = splatResource.instantiate(materialOptions); const instance = this.entity.gsplat.instance; @@ -118,9 +115,14 @@ class Splat extends Element { this.rebuildMaterial = (bands: number) => { // @ts-ignore - instance.createMaterial(getMaterialOptions(instance.splat.hasSH ? bands : 0)); + instance.createMaterial(materialOptions); const material = instance.material; + + const numBands = instance.splat.hasSH ? bands : 0; + material.setDefine('USE_SH1', numBands > 0 ? '1' : false); + material.setDefine('USE_SH2', numBands > 1 ? '1' : false); + material.setDefine('USE_SH3', numBands > 2 ? '1' : false); material.setParameter('splatState', this.stateTexture); material.setParameter('splatTransform', this.transformTexture); material.setParameter('transformPalette', this.transformPalette.texture);