@@ -111,6 +111,7 @@ export default async function demo({
111
111
112
112
const attr = {
113
113
loc : mustGetAttr ( 'loc' ) , // vec2
114
+ spin : mustGetAttr ( 'spin' ) , // float
114
115
size : mustGetAttr ( 'size' ) , // float
115
116
tileID : mustGetAttr ( 'tileID' ) , // uvec2
116
117
} ;
@@ -193,8 +194,8 @@ export default async function demo({
193
194
const H = Math . ceil ( height / cellSize ) ;
194
195
const N = ( W + 1 ) * H ;
195
196
196
- if ( locData . length != 2 * N )
197
- locData = new Float32Array ( 2 * N )
197
+ if ( locData . length != 3 * N )
198
+ locData = new Float32Array ( 3 * N )
198
199
else
199
200
locData . fill ( 0 ) ;
200
201
@@ -205,9 +206,15 @@ export default async function demo({
205
206
206
207
for ( let rand = 0xdeadbeefn , i = 0 , j = 0 , x = 0 , y = 0 ; i < N ; ) {
207
208
rand = rand * 6364136223846793005n + 1442695040888963407n ;
208
- tileData [ i ++ ] = Number ( rand >> 17n & 0xffffffffn ) % maxTileID ;
209
+ const tileID = Number ( rand >> 17n & 0xffffffffn ) % maxTileID ;
210
+
211
+ rand = rand * 6364136223846793005n + 1442695040888963407n ;
212
+ const spin = ( Number ( rand >> 17n & 0xffffffffn ) % 0xffff ) / 0x10000 ;
213
+
214
+ tileData [ i ++ ] = tileID ;
209
215
locData [ j ++ ] = x ;
210
216
locData [ j ++ ] = y ;
217
+ locData [ j ++ ] = spin ;
211
218
if ( ++ x > W ) x = 0 , y ++ ;
212
219
}
213
220
}
@@ -262,11 +269,15 @@ export default async function demo({
262
269
// to gl.draw* if/as we scale out to multiple draw calls
263
270
264
271
gl . enableVertexAttribArray ( attr . loc ) ;
272
+ gl . enableVertexAttribArray ( attr . spin ) ;
265
273
gl . enableVertexAttribArray ( attr . tileID ) ;
266
274
gl . vertexAttrib1f ( attr . size , cellSize ) ;
267
275
276
+ const locStride = 3 * locData . BYTES_PER_ELEMENT ;
277
+
268
278
gl . bindBuffer ( gl . ARRAY_BUFFER , locBuffer )
269
- gl . vertexAttribPointer ( attr . loc , 2 , gl . FLOAT , false , 0 , 0 ) ;
279
+ gl . vertexAttribPointer ( attr . loc , 2 , gl . FLOAT , false , locStride , 0 ) ;
280
+ gl . vertexAttribPointer ( attr . spin , 1 , gl . FLOAT , false , locStride , 2 * locData . BYTES_PER_ELEMENT ) ;
270
281
271
282
gl . bindBuffer ( gl . ARRAY_BUFFER , tileBuffer )
272
283
gl . vertexAttribIPointer ( attr . tileID , 1 , gl . UNSIGNED_SHORT , 0 , 0 ) ;
0 commit comments