1- import { SEMANTIC_POSITION , SEMANTIC_ATTR13 , CULLFACE_NONE , PIXELFORMAT_RGBA16U } from '../../platform/graphics/constants.js' ;
1+ import { SEMANTIC_POSITION , CULLFACE_NONE , PIXELFORMAT_RGBA16U } from '../../platform/graphics/constants.js' ;
22import {
33 BLEND_NONE , BLEND_PREMULTIPLIED , BLEND_ADDITIVE , GSPLAT_FORWARD , GSPLAT_SHADOW ,
44 SHADOWCAMERA_NAME
55} from '../constants.js' ;
66import { ShaderMaterial } from '../materials/shader-material.js' ;
77import { GSplatResourceBase } from '../gsplat/gsplat-resource-base.js' ;
88import { MeshInstance } from '../mesh-instance.js' ;
9- import { math } from '../../core/math/math.js' ;
109
1110/**
12- * @import { VertexBuffer } from '../../platform/graphics/vertex-buffer.js'
1311 * @import { StorageBuffer } from '../../platform/graphics/storage-buffer.js'
1412 * @import { Layer } from '../layer.js'
1513 * @import { GraphNode } from '../graph-node.js'
@@ -29,12 +27,6 @@ class GSplatRenderer {
2927 /** @type {MeshInstance } */
3028 meshInstance ;
3129
32- /** @type {VertexBuffer|null } */
33- instanceIndices = null ;
34-
35- /** @type {number } */
36- instanceIndicesCount = 0 ;
37-
3830 /** @type {Layer } */
3931 layer ;
4032
@@ -84,11 +76,12 @@ class GSplatRenderer {
8476 vertexWGSL : '#include "gsplatVS"' ,
8577 fragmentWGSL : '#include "gsplatPS"' ,
8678 attributes : {
87- vertex_position : SEMANTIC_POSITION ,
88- vertex_id_attrib : SEMANTIC_ATTR13
79+ vertex_position : SEMANTIC_POSITION
8980 }
9081 } ) ;
9182
83+ this . _material . setDefine ( '{GSPLAT_INSTANCE_SIZE}' , GSplatResourceBase . instanceSize ) ;
84+
9285 this . configureMaterial ( ) ;
9386
9487 // Capture internal define names to protect them from being cleared
@@ -97,6 +90,7 @@ class GSplatRenderer {
9790 } ) ;
9891
9992 // Also protect defines that may be added dynamically
93+ this . _internalDefines . add ( '{GSPLAT_INSTANCE_SIZE}' ) ;
10094 this . _internalDefines . add ( 'GSPLAT_UNIFIED_ID' ) ;
10195 this . _internalDefines . add ( 'PICK_CUSTOM_ID' ) ;
10296 this . _internalDefines . add ( 'GSPLAT_INDIRECT_DRAW' ) ;
@@ -248,6 +242,12 @@ class GSplatRenderer {
248242 updateIndirect ( textureSize ) {
249243 this . _material . setParameter ( 'splatTextureSize' , textureSize ) ;
250244 this . meshInstance . visible = true ;
245+
246+ // Ensure instancingCount is non-zero so the forward/shadow renderers don't
247+ // skip this draw call. The actual instance count is GPU-driven via indirect args.
248+ if ( this . meshInstance . instancingCount <= 0 ) {
249+ this . meshInstance . instancingCount = 1 ;
250+ }
251251 }
252252
253253 /**
@@ -420,34 +420,12 @@ class GSplatRenderer {
420420 }
421421 }
422422
423- setMaxNumSplats ( numSplats ) {
424-
425- // round up to the nearest multiple of instanceSize (same as createInstanceIndices does internally)
426- const roundedNumSplats = math . roundUp ( numSplats , GSplatResourceBase . instanceSize ) ;
427-
428- if ( this . instanceIndicesCount < roundedNumSplats ) {
429- this . instanceIndicesCount = roundedNumSplats ;
430-
431- // destroy old instance indices
432- this . instanceIndices ?. destroy ( ) ;
433-
434- // create new instance indices
435- this . instanceIndices = GSplatResourceBase . createInstanceIndices ( this . device , numSplats ) ;
436- this . meshInstance . setInstancing ( this . instanceIndices , true ) ;
437-
438- // update texture size uniform
439- this . _material . setParameter ( 'splatTextureSize' , this . workBuffer . textureSize ) ;
440- }
441- }
442-
443423 createMeshInstance ( ) {
444424
445425 const mesh = GSplatResourceBase . createMesh ( this . device ) ;
446- const textureSize = this . workBuffer . textureSize ;
447- const instanceIndices = GSplatResourceBase . createInstanceIndices ( this . device , textureSize * textureSize ) ;
448426 const meshInstance = new MeshInstance ( mesh , this . _material ) ;
449427 meshInstance . node = this . node ;
450- meshInstance . setInstancing ( instanceIndices , true ) ;
428+ meshInstance . setInstancing ( true , true ) ;
451429
452430 // only start rendering the splat after we've received the splat order data
453431 meshInstance . instancingCount = 0 ;
0 commit comments