@@ -23,6 +23,14 @@ export class Phase5Draw {
2323 usage : GPUBufferUsage . STORAGE | GPUBufferUsage . COPY_DST | GPUBufferUsage . COPY_SRC ,
2424 } ) ;
2525
26+ // ISO threshold uniform buffer (1 f32 = 4 bytes)
27+ this . isoThresholdBuffer = device . createBuffer ( {
28+ size : 4 ,
29+ usage : GPUBufferUsage . UNIFORM | GPUBufferUsage . COPY_DST ,
30+ } ) ;
31+ // Default ISO threshold = 0.5
32+ device . queue . writeBuffer ( this . isoThresholdBuffer , 0 , new Float32Array ( [ 0.5 ] ) ) ;
33+
2634 // Indirect draw args: [indexCount, instanceCount, firstIndex, baseVertex, firstInstance]
2735 this . drawArgsBuffer = device . createBuffer ( {
2836 size : 20 ,
@@ -59,15 +67,19 @@ export class Phase5Draw {
5967 } ) ;
6068 }
6169
62- _createTopologyBG ( qefBuffer , hermiteBuffer , isoThreshold ) {
70+ _createTopologyBG ( qefBuffer , hermiteBuffer , isoThresholdValue ) {
71+ // Update ISO threshold buffer if a value is provided
72+ if ( isoThresholdValue !== undefined ) {
73+ this . device . queue . writeBuffer ( this . isoThresholdBuffer , 0 , new Float32Array ( [ isoThresholdValue ] ) ) ;
74+ }
6375 return this . device . createBindGroup ( {
6476 layout : this . pipelines . topology . getBindGroupLayout ( 0 ) ,
6577 entries : [
6678 { binding : 0 , resource : { buffer : qefBuffer } } ,
6779 { binding : 1 , resource : { buffer : hermiteBuffer } } ,
6880 { binding : 2 , resource : { buffer : this . indexBuffer } } ,
6981 { binding : 3 , resource : { buffer : this . indexCountBuffer } } ,
70- { binding : 4 , resource : { buffer : isoThreshold } } ,
82+ { binding : 4 , resource : { buffer : this . isoThresholdBuffer } } ,
7183 ] ,
7284 } ) ;
7385 }
@@ -84,24 +96,28 @@ export class Phase5Draw {
8496
8597 /**
8698 * Full mesh build: topology generation + LOD stitching + draw args.
99+ *
100+ * Topology: generates faces for all 255³ cells.
101+ * LOD stitching: corrects seams between LOD levels.
87102 */
88- async buildMesh ( qefBuffer , hermiteBuffer , lodBuffer , isoThresholdValue ) {
103+ async buildMesh ( qefBuffer , hermiteBuffer , lodBuffer , isoThresholdValue = 0.5 ) {
89104 const device = this . device ;
90105 const encoder = device . createCommandEncoder ( ) ;
91106
92107 // Reset index count
93108 device . queue . writeBuffer ( this . indexCountBuffer , 0 , new Uint32Array ( [ 0 ] ) ) ;
94109
95- // --- Pass 1: Topology generation ---
110+ // --- Pass 1: Topology generation (full 3D: 255³ cells) ---
96111 {
97112 const pass = encoder . beginComputePass ( ) ;
98113 pass . setPipeline ( this . pipelines . topology ) ;
99114 pass . setBindGroup ( 0 , this . _createTopologyBG ( qefBuffer , hermiteBuffer , isoThresholdValue ) ) ;
100- pass . dispatchWorkgroups ( 32 , 32 , 1 ) ; // 255 × 255 cells in XY
115+ // Dispatch: 32×32×32 workgroups = 1024³ threads covering 255³ cells
116+ pass . dispatchWorkgroups ( 32 , 32 , 32 ) ;
101117 pass . end ( ) ;
102118 }
103119
104- // --- Pass 2: LOD stitching ---
120+ // --- Pass 2: LOD stitching (full 3D: 255³ cells) ---
105121 {
106122 const pass = encoder . beginComputePass ( ) ;
107123 pass . setPipeline ( this . pipelines . stitch ) ;
@@ -113,8 +129,7 @@ export class Phase5Draw {
113129 // --- Update indirect draw args ---
114130 // copy indexCount → drawArgs[0] (indexCount)
115131 encoder . copyBufferToBuffer ( this . indexCountBuffer , 0 , this . drawArgsBuffer , 0 , 4 ) ;
116- // Set instanceCount = 1 (at offset 4)
117- // In a separate writeBuffer:
132+ // Set instanceCount = 1, firstIndex = 0, baseVertex = 0, firstInstance = 0
118133 device . queue . writeBuffer ( this . drawArgsBuffer , 4 , new Uint32Array ( [ 1 , 0 , 0 , 0 ] ) ) ;
119134
120135 device . queue . submit ( [ encoder . finish ( ) ] ) ;
@@ -149,7 +164,7 @@ export class Phase5Draw {
149164 }
150165
151166 destroy ( ) {
152- const bufs = [ 'indexBuffer' , 'indexCountBuffer' , 'drawArgsBuffer' , 'readbackBuffer' ] ;
167+ const bufs = [ 'indexBuffer' , 'indexCountBuffer' , 'isoThresholdBuffer' , ' drawArgsBuffer', 'readbackBuffer' ] ;
153168 for ( const key of bufs ) {
154169 if ( this [ key ] ) this [ key ] . destroy ( ) ;
155170 }
0 commit comments