|
151 | 151 | // Get 2-D compute coordinate from one-dimensional instanceIndex. The calculation will |
152 | 152 | // still work even if you dispatch your compute shader 2-dimensionally, since within a compute |
153 | 153 | // context, instanceIndex is a 1-dimensional value derived from the workgroup dimensions. |
154 | | - |
| 154 | + |
155 | 155 | // Cast to int to prevent unintended index overflow upon subtraction. |
156 | 156 | const x = int( index.mod( WIDTH ) ); |
157 | 157 | const y = int( index.div( WIDTH ) ); |
|
168 | 168 |
|
169 | 169 | const westIndex = y.mul( width ).add( leftX ); |
170 | 170 | const eastIndex = y.mul( width ).add( rightX ); |
171 | | - |
| 171 | + |
172 | 172 | const southIndex = bottomY.mul( width ).add( x ); |
173 | 173 | const northIndex = topY.mul( width ).add( x ); |
174 | 174 |
|
|
283 | 283 | meshRay.matrixAutoUpdate = false; |
284 | 284 | meshRay.updateMatrix(); |
285 | 285 | scene.add( meshRay ); |
286 | | - |
| 286 | + |
287 | 287 | // Initialize sphere mesh instance position and velocity. |
288 | 288 | // position<vec3> + velocity<vec2> + unused<vec3> = 8 floats per sphere. |
289 | 289 | // for structs arrays must be enclosed in multiple of 4 |
|
339 | 339 | const targetY = waterHeight.add( yOffset ); |
340 | 340 |
|
341 | 341 | const deltaY = targetY.sub( instancePosition.y ); |
342 | | - instancePosition.y.addAssign( deltaY.mul( verticalResponseFactor ) ); // Atualiza Y gradualmente |
| 342 | + instancePosition.y.addAssign( deltaY.mul( verticalResponseFactor ) ); // Gradually update position |
343 | 343 |
|
344 | 344 | // Get the normal of the water surface at the duck's position |
345 | 345 | const pushX = normalX.mul( waterPushFactor ); |
|
373 | 373 | If( instancePosition.z.lessThan( - limit ), () => { |
374 | 374 |
|
375 | 375 | instancePosition.z = - limit; |
376 | | - velocity.y.mulAssign( bounceDamping ); // Inverte e amortece vz (velocity.y) |
| 376 | + velocity.y.mulAssign( bounceDamping ); // Invert and damp vz (velocity.y) |
377 | 377 |
|
378 | 378 | } ).ElseIf( instancePosition.z.greaterThan( limit ), () => { |
379 | 379 |
|
|
448 | 448 | gui.add( effectController.viscosity, 'value', 0.9, 0.96, 0.001 ).name( 'viscosity' ); |
449 | 449 | gui.add( effectController, 'speed', 1, 6, 1 ); |
450 | 450 | gui.add( effectController, 'ducksEnabled' ).onChange( () => { |
451 | | - |
| 451 | + |
452 | 452 | duckMesh.visible = effectController.ducksEnabled; |
453 | | - |
| 453 | + |
454 | 454 | } ); |
455 | 455 | gui.add( effectController, 'wireframe' ).onChange( () => { |
456 | | - |
| 456 | + |
457 | 457 | waterMesh.material.wireframe = ! waterMesh.material.wireframe; |
458 | 458 | poolBorder.material.wireframe = ! poolBorder.material.wireframe; |
459 | 459 | duckModel.material.wireframe = ! duckModel.material.wireframe; |
460 | 460 | waterMesh.material.needsUpdate = true; |
461 | 461 | poolBorder.material.needsUpdate = true; |
462 | | - |
| 462 | + |
463 | 463 | } ); |
464 | 464 |
|
465 | 465 | } |
|
484 | 484 | mouseDown = true; |
485 | 485 | firstClick = true; |
486 | 486 | updateOriginMouseDown = true; |
487 | | - |
| 487 | + |
488 | 488 | } |
489 | 489 |
|
490 | 490 | function onPointerUp() { |
|
529 | 529 | effectController.mousePos.value.set( point.x, point.z ); |
530 | 530 |
|
531 | 531 | updateOriginMouseDown = false; |
532 | | - |
| 532 | + |
533 | 533 | } |
534 | 534 |
|
535 | 535 | effectController.mouseSpeed.value.set( |
|
554 | 554 | } |
555 | 555 |
|
556 | 556 | firstClick = false; |
557 | | - |
| 557 | + |
558 | 558 | } else { |
559 | 559 |
|
560 | 560 | updateOriginMouseDown = true; |
|
582 | 582 | } |
583 | 583 |
|
584 | 584 | frame = 0; |
585 | | - |
| 585 | + |
586 | 586 | } |
587 | 587 |
|
588 | 588 | renderer.render( scene, camera ); |
|
0 commit comments