|
|
@@ -4,13 +4,21 @@
|
|
|
<title>three.js webgpu - compute water</title>
|
|
|
<meta charset="utf-8">
|
|
|
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
|
|
- <link type="text/css" rel="stylesheet" href="main.css">
|
|
|
+ <link type="text/css" rel="stylesheet" href="example.css">
|
|
|
</head>
|
|
|
<body>
|
|
|
|
|
|
<div id="info">
|
|
|
- <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - <span id="waterSize"></span> webgpu compute water<br/>
|
|
|
- Click and move mouse to disturb water.
|
|
|
+ <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a>
|
|
|
+
|
|
|
+ <div class="title-wrapper">
|
|
|
+ <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a>
|
|
|
+ <span>Compute Water</span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <small>
|
|
|
+ Click and move mouse to disturb water.
|
|
|
+ </small>
|
|
|
</div>
|
|
|
|
|
|
<script type="importmap">
|
|
|
@@ -29,14 +37,14 @@
|
|
|
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, globalId } from 'three/tsl';
|
|
|
|
|
|
+ import { Inspector } from 'three/addons/inspector/Inspector.js';
|
|
|
+
|
|
|
import { SimplexNoise } from 'three/addons/math/SimplexNoise.js';
|
|
|
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
|
|
|
import { HDRLoader } from 'three/addons/loaders/HDRLoader.js';
|
|
|
import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
|
|
|
import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
|
|
|
|
|
|
- import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
|
|
|
- import Stats from 'three/addons/libs/stats.module.js';
|
|
|
import WebGPU from 'three/addons/capabilities/WebGPU.js';
|
|
|
|
|
|
// Dimensions of simulation grid.
|
|
|
@@ -49,7 +57,7 @@
|
|
|
|
|
|
const waterMaxHeight = 0.1;
|
|
|
|
|
|
- let container, stats;
|
|
|
+ let container;
|
|
|
let camera, scene, renderer, controls;
|
|
|
|
|
|
let mouseDown = false;
|
|
|
@@ -245,7 +253,7 @@
|
|
|
prevHeightStorage.element( instanceIndex ).assign( height );
|
|
|
heightStorage.element( instanceIndex ).assign( newHeight );
|
|
|
|
|
|
- } )().compute( WIDTH * WIDTH, [ 16, 16 ] );
|
|
|
+ } )().compute( WIDTH * WIDTH, [ 16, 16 ] ).setName( 'Update Height' );
|
|
|
|
|
|
// Water Geometry corresponds with buffered compute grid.
|
|
|
const waterGeometry = new THREE.PlaneGeometry( BOUNDS, BOUNDS, WIDTH - 1, WIDTH - 1 );
|
|
|
@@ -399,7 +407,7 @@
|
|
|
duckInstanceDataStorage.element( instanceIndex ).get( 'position' ).assign( instancePosition );
|
|
|
duckInstanceDataStorage.element( instanceIndex ).get( 'velocity' ).assign( velocity );
|
|
|
|
|
|
- } )().compute( NUM_DUCKS );
|
|
|
+ } )().compute( NUM_DUCKS ).setName( 'Update Ducks' );
|
|
|
|
|
|
// Models / Textures
|
|
|
|
|
|
@@ -433,17 +441,17 @@
|
|
|
renderer.setSize( window.innerWidth, window.innerHeight );
|
|
|
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
|
|
renderer.toneMappingExposure = 0.5;
|
|
|
- renderer.setAnimationLoop( animate );
|
|
|
+ renderer.setAnimationLoop( render );
|
|
|
container.appendChild( renderer.domElement );
|
|
|
|
|
|
+ renderer.inspector = new Inspector();
|
|
|
+ document.body.appendChild( renderer.inspector.domElement );
|
|
|
+
|
|
|
controls = new OrbitControls( camera, container );
|
|
|
|
|
|
container.style.touchAction = 'none';
|
|
|
|
|
|
- // Stats
|
|
|
-
|
|
|
- stats = new Stats();
|
|
|
- container.appendChild( stats.dom );
|
|
|
+ //
|
|
|
|
|
|
container.style.touchAction = 'none';
|
|
|
container.addEventListener( 'pointermove', onPointerMove );
|
|
|
@@ -454,7 +462,7 @@
|
|
|
|
|
|
// GUI
|
|
|
|
|
|
- const gui = new GUI();
|
|
|
+ const gui = renderer.inspector.createParameters( 'Settings' );
|
|
|
gui.add( effectController.mouseSize, 'value', 0.1, .3 ).name( 'Mouse Size' );
|
|
|
gui.add( effectController.mouseDeep, 'value', 0.1, 1 ).name( 'Mouse Deep' );
|
|
|
gui.add( effectController.viscosity, 'value', 0.9, 0.96, 0.001 ).name( 'viscosity' );
|
|
|
@@ -517,13 +525,6 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- function animate() {
|
|
|
-
|
|
|
- render();
|
|
|
- stats.update();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
function raycast() {
|
|
|
|
|
|
if ( mouseDown && ( firstClick || ! controls.enabled ) ) {
|
|
|
@@ -585,11 +586,11 @@
|
|
|
|
|
|
if ( frame >= 7 - effectController.speed ) {
|
|
|
|
|
|
- renderer.computeAsync( computeHeight, [ 8, 8, 1 ] );
|
|
|
+ renderer.compute( computeHeight, [ 8, 8, 1 ] );
|
|
|
|
|
|
if ( effectController.ducksEnabled ) {
|
|
|
|
|
|
- renderer.computeAsync( computeDucks );
|
|
|
+ renderer.compute( computeDucks );
|
|
|
|
|
|
}
|
|
|
|