Skip to content

Commit

Permalink
WebGPURenderer: Fix storage buffer example (mrdoob#28729)
Browse files Browse the repository at this point in the history
* fix storage buffer webgpu

* bind groups cache per renderer

* Revert "bind groups cache per renderer"

This reverts commit 6fe58cc.
  • Loading branch information
sunag committed Jun 24, 2024
1 parent 172f0c6 commit 05b5c20
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/webgpu_storage_buffer.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@

// texture

const size = 1024; // non power of two buffer size is not well supported in WebGPU
const size = 32; // non power of two buffer size is not well supported in WebGPU
const barCount = 32;

const type = [ 'float', 'vec2', 'vec3', 'vec4' ];


const arrayBufferNodes = [];

for ( let i = 0; i < type.length; i ++ ) {
Expand Down Expand Up @@ -110,7 +110,7 @@

for ( let i = 0; i < type.length; i ++ ) {

const invertIndex = arrayBufferNodes[ i ].element( uint( size ).sub( instanceIndex ) );
const invertIndex = arrayBufferNodes[ i ].element( uint( size - 1 ).sub( instanceIndex ) );
arrayBufferNodes[ i ].element( instanceIndex ).assign( invertIndex );

}
Expand Down Expand Up @@ -140,7 +140,7 @@
If( uv().y.greaterThan( 0.0 ), () => {

const indexValue = arrayBufferNodes[ 0 ].element( index ).toVar();
const value = float( indexValue ).div( float( size ) ).mul( 20 ).floor().div( 20 );
const value = float( indexValue ).div( float( size ) ).mul( barCount ).floor().div( barCount );

color.assign( vec3( value, 0, 0 ) );

Expand All @@ -149,7 +149,7 @@
If( uv().y.greaterThan( 0.25 ), () => {

const indexValue = arrayBufferNodes[ 1 ].element( index ).toVar();
const value = float( indexValue ).div( float( size ) ).mul( 20 ).floor().div( 20 );
const value = float( indexValue ).div( float( size ) ).mul( barCount ).floor().div( barCount );

color.assign( vec3( 0, value, 0 ) );

Expand All @@ -158,7 +158,7 @@
If( uv().y.greaterThan( 0.5 ), () => {

const indexValue = arrayBufferNodes[ 2 ].element( index ).toVar();
const value = float( indexValue ).div( float( size ) ).mul( 20 ).floor().div( 20 );
const value = float( indexValue ).div( float( size ) ).mul( barCount ).floor().div( barCount );

color.assign( vec3( 0, 0, value ) );

Expand All @@ -167,7 +167,7 @@
If( uv().y.greaterThan( 0.75 ), () => {

const indexValue = arrayBufferNodes[ 3 ].element( index ).toVar();
const value = float( indexValue ).div( float( size ) ).mul( 20 ).floor().div( 20 );
const value = float( indexValue ).div( float( size ) ).mul( barCount ).floor().div( barCount );

color.assign( vec3( value, value, value ) );

Expand Down

0 comments on commit 05b5c20

Please sign in to comment.