@@ -8,6 +8,10 @@ import drawShader from './draw.wgsl?raw'
88import binShader from './bin-fill.wgsl?raw'
99import updateShader from './update.wgsl?raw'
1010
11+ // const particleCount = 200_000
12+ const particleCount = 100_000
13+ // const particleCount = 20_000
14+
1115export const meta : RouteMeta = {
1216 title : 'Particle Life GPU' ,
1317 tags : [ 'simulation' , 'webgpu' , 'particles' ] ,
@@ -34,12 +38,14 @@ export default function ParticleLifeGPUPage() {
3438 controller . abort ( )
3539 }
3640 } , [ supported ] )
41+
42+ const [ numberFormat ] = useState ( ( ) => new Intl . NumberFormat ( 'en-US' ) )
3743
3844 return (
3945 < div className = { styles . main } >
4046 < div className = { styles . head } >
4147 < Head />
42- { supported && < pre > { fps } FPS </ pre > }
48+ { supported && < pre > { numberFormat . format ( particleCount ) } particles, { fps } fps </ pre > }
4349 { ! supported && < pre > Your browser does not support WebGPU.</ pre > }
4450 </ div >
4551 < canvas ref = { canvasRef } />
@@ -90,9 +96,8 @@ async function start(
9096 const toBinX = widthDivisions / width
9197 const toBinY = heightDivisions / height
9298 const binCount = widthDivisions * heightDivisions
93- // const particleCount = 200_000
94- const particleCount = 100_000
95- // const particleCount = 20_000
99+
100+ const numberOfColors = 8
96101
97102 const particlePositionBuffer = device . createBuffer ( {
98103 label : 'particle position storage buffer' ,
@@ -118,7 +123,7 @@ async function start(
118123 {
119124 const staticStorageArray = new Uint32Array ( particleColorBuffer . getMappedRange ( ) )
120125 for ( let i = 0 ; i < particleCount ; i ++ ) {
121- staticStorageArray [ i ] = i % 6
126+ staticStorageArray [ i ] = i % numberOfColors
122127 }
123128 particleColorBuffer . unmap ( )
124129 onAbort ( ( ) => particleColorBuffer . destroy ( ) )
@@ -140,16 +145,16 @@ async function start(
140145 }
141146 const particleInteractionsBuffer = device . createBuffer ( {
142147 label : 'particle interactions storage buffer' ,
143- size : 6 * 6 * Float32Array . BYTES_PER_ELEMENT ,
148+ size : numberOfColors * numberOfColors * Float32Array . BYTES_PER_ELEMENT ,
144149 usage : GPUBufferUsage . STORAGE | GPUBufferUsage . COPY_DST ,
145150 mappedAtCreation : true ,
146151 } )
147152 {
148153 const staticStorageArray = new Float32Array ( particleInteractionsBuffer . getMappedRange ( ) )
149- for ( let i = 0 ; i < 6 ; i ++ ) {
150- for ( let j = 0 ; j < 6 ; j ++ ) {
151- staticStorageArray [ i * 6 + j ] = Math . random ( ) * 2 - 1
152- // staticStorageArray[i * 6 + j] = i === j ? 1 : 0
154+ for ( let i = 0 ; i < numberOfColors ; i ++ ) {
155+ for ( let j = 0 ; j < numberOfColors ; j ++ ) {
156+ staticStorageArray [ i * numberOfColors + j ] = Math . random ( ) * 2 - 1
157+ // staticStorageArray[i * numberOfColors + j] = i === j ? 1 : 0
153158 }
154159 }
155160 particleInteractionsBuffer . unmap ( )
@@ -612,7 +617,7 @@ async function start(
612617 colorAttachments : [
613618 {
614619 view : null ! as GPUTextureView ,
615- clearValue : [ 0.1 , 0.1 , 0.1 , 1 ] ,
620+ clearValue : [ 0.06 , 0.06 , 0.08 , 1 ] ,
616621 loadOp : 'clear' ,
617622 storeOp : 'store' ,
618623 } ,
0 commit comments