|
|
@@ -27,7 +27,7 @@
|
|
|
<script type="module">
|
|
|
|
|
|
import * as THREE from 'three/webgpu';
|
|
|
- import { instanceIndex, struct, If, uint, int, floor, float, length, clamp, vec2, cos, vec3, vertexIndex, Fn, uniform, instancedArray, min, max, positionLocal, transformNormalToView } from 'three/tsl';
|
|
|
+ import { instanceIndex, struct, If, uint, int, floor, float, length, clamp, vec2, cos, vec3, vertexIndex, Fn, uniform, instancedArray, min, max, positionLocal, transformNormalToView, globalId } from 'three/tsl';
|
|
|
|
|
|
import { SimplexNoise } from 'three/addons/math/SimplexNoise.js';
|
|
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
|
@@ -228,9 +228,10 @@
|
|
|
|
|
|
const newHeight = neighborHeight.mul( viscosity );
|
|
|
|
|
|
- // Get 2-D compute coordinate from one-dimensional instanceIndex.
|
|
|
- const x = float( instanceIndex.mod( WIDTH ) ).mul( 1 / WIDTH );
|
|
|
- const y = float( instanceIndex.div( WIDTH ) ).mul( 1 / WIDTH );
|
|
|
+ // Get x and y position of the coordinate in the water plane
|
|
|
+
|
|
|
+ const x = float( globalId.x ).mul( 1 / WIDTH );
|
|
|
+ const y = float( globalId.y ).mul( 1 / WIDTH );
|
|
|
|
|
|
// Mouse influence
|
|
|
const centerVec = vec2( 0.5 );
|
|
|
@@ -244,7 +245,7 @@
|
|
|
prevHeightStorage.element( instanceIndex ).assign( height );
|
|
|
heightStorage.element( instanceIndex ).assign( newHeight );
|
|
|
|
|
|
- } )().compute( WIDTH * WIDTH );
|
|
|
+ } )().compute( WIDTH * WIDTH, [ 16, 16 ] );
|
|
|
|
|
|
// Water Geometry corresponds with buffered compute grid.
|
|
|
const waterGeometry = new THREE.PlaneGeometry( BOUNDS, BOUNDS, WIDTH - 1, WIDTH - 1 );
|
|
|
@@ -330,7 +331,7 @@
|
|
|
const linearDamping = float( 0.92 );
|
|
|
const bounceDamping = float( - 0.4 );
|
|
|
|
|
|
- // Get 2-D compute coordinate from one-dimensional instanceIndex. The calculation will
|
|
|
+ // Get 2-D compute coordinate from one-dimensional instanceIndex.
|
|
|
const instancePosition = duckInstanceDataStorage.element( instanceIndex ).get( 'position' ).toVar();
|
|
|
const velocity = duckInstanceDataStorage.element( instanceIndex ).get( 'velocity' ).toVar();
|
|
|
|
|
|
@@ -584,7 +585,7 @@
|
|
|
|
|
|
if ( frame >= 7 - effectController.speed ) {
|
|
|
|
|
|
- renderer.computeAsync( computeHeight );
|
|
|
+ renderer.computeAsync( computeHeight, [ 8, 8, 1 ] );
|
|
|
|
|
|
if ( effectController.ducksEnabled ) {
|
|
|
|