webgpu_compute_water.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgpu - compute water</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <meta property="og:title" content="three.js webgpu - compute water">
  8. <meta property="og:type" content="website">
  9. <meta property="og:url" content="https://threejs.org/examples/webgpu_compute_water.html">
  10. <meta property="og:image" content="https://threejs.org/examples/screenshots/webgpu_compute_water.jpg">
  11. <link type="text/css" rel="stylesheet" href="example.css">
  12. </head>
  13. <body>
  14. <div id="info">
  15. <a href="https://threejs.org/" target="_blank" rel="noopener" class="logo-link"></a>
  16. <div class="title-wrapper">
  17. <a href="https://threejs.org/" target="_blank" rel="noopener">three.js</a>
  18. <span>Compute Water</span>
  19. </div>
  20. <small>
  21. Click and move mouse to disturb water.
  22. </small>
  23. </div>
  24. <script type="importmap">
  25. {
  26. "imports": {
  27. "three": "../build/three.webgpu.js",
  28. "three/webgpu": "../build/three.webgpu.js",
  29. "three/tsl": "../build/three.tsl.js",
  30. "three/addons/": "./jsm/"
  31. }
  32. }
  33. </script>
  34. <script type="module">
  35. import * as THREE from 'three/webgpu';
  36. import { instanceIndex, struct, If, uint, int, floor, float, length, clamp, vec2, cos, vec3, vertexIndex, Fn, uniform, instancedArray, min, max, positionLocal, transformNormalToView, select, globalId } from 'three/tsl';
  37. import { Inspector } from 'three/addons/inspector/Inspector.js';
  38. import { SimplexNoise } from 'three/addons/math/SimplexNoise.js';
  39. import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
  40. import { HDRLoader } from 'three/addons/loaders/HDRLoader.js';
  41. import { DRACOLoader, DRACO_GLTF_CONFIG } from 'three/addons/loaders/DRACOLoader.js';
  42. import { OrbitControls } from 'three/addons/controls/OrbitControls.js';
  43. import WebGPU from 'three/addons/capabilities/WebGPU.js';
  44. // Dimensions of simulation grid.
  45. const WIDTH = 128;
  46. // Water size in system units.
  47. const BOUNDS = 6;
  48. const BOUNDS_HALF = BOUNDS * 0.5;
  49. const limit = BOUNDS_HALF - 0.2;
  50. const waterMaxHeight = 0.1;
  51. let container;
  52. let camera, scene, renderer, controls;
  53. let mouseDown = false;
  54. let firstClick = true;
  55. let updateOriginMouseDown = false;
  56. const mouseCoords = new THREE.Vector2();
  57. const raycaster = new THREE.Raycaster();
  58. let frame = 0;
  59. const effectController = {
  60. mousePos: uniform( new THREE.Vector2() ).setName( 'mousePos' ),
  61. mouseSpeed: uniform( new THREE.Vector2() ).setName( 'mouseSpeed' ),
  62. mouseDeep: uniform( .5 ).setName( 'mouseDeep' ),
  63. mouseSize: uniform( 0.12 ).setName( 'mouseSize' ),
  64. viscosity: uniform( 0.96 ).setName( 'viscosity' ),
  65. ducksEnabled: true,
  66. wireframe: false,
  67. speed: 5,
  68. };
  69. let sun;
  70. let waterMesh;
  71. let poolBorder;
  72. let meshRay;
  73. let computeHeightAtoB, computeHeightBtoA, computeDucks;
  74. let pingPong = 0;
  75. const readFromA = uniform( 1 );
  76. let duckModel = null;
  77. const NUM_DUCKS = 100;
  78. const simplex = new SimplexNoise();
  79. // TODO: Fix example with WebGL backend
  80. if ( WebGPU.isAvailable() === false ) {
  81. document.body.appendChild( WebGPU.getErrorMessage() );
  82. throw new Error( 'No WebGPU support' );
  83. }
  84. init();
  85. function noise( x, y ) {
  86. let multR = waterMaxHeight;
  87. let mult = 0.025;
  88. let r = 0;
  89. for ( let i = 0; i < 15; i ++ ) {
  90. r += multR * simplex.noise( x * mult, y * mult );
  91. multR *= 0.53 + 0.025 * i;
  92. mult *= 1.25;
  93. }
  94. return r;
  95. }
  96. async function init() {
  97. container = document.createElement( 'div' );
  98. document.body.appendChild( container );
  99. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 3000 );
  100. camera.position.set( 0, 2.00, 4 );
  101. camera.lookAt( 0, 0, 0 );
  102. scene = new THREE.Scene();
  103. sun = new THREE.DirectionalLight( 0xFFFFFF, 4.0 );
  104. sun.position.set( - 1, 2.6, 1.4 );
  105. scene.add( sun );
  106. //
  107. // Initialize height storage buffers
  108. const heightArray = new Float32Array( WIDTH * WIDTH );
  109. const prevHeightArray = new Float32Array( WIDTH * WIDTH );
  110. let p = 0;
  111. for ( let j = 0; j < WIDTH; j ++ ) {
  112. for ( let i = 0; i < WIDTH; i ++ ) {
  113. const x = i * 128 / WIDTH;
  114. const y = j * 128 / WIDTH;
  115. const height = noise( x, y );
  116. heightArray[ p ] = height;
  117. prevHeightArray[ p ] = height;
  118. p ++;
  119. }
  120. }
  121. // Ping-pong height storage buffers
  122. const heightStorageA = instancedArray( heightArray ).setName( 'HeightA' );
  123. const heightStorageB = instancedArray( new Float32Array( heightArray ) ).setName( 'HeightB' );
  124. const prevHeightStorage = instancedArray( prevHeightArray ).setName( 'PrevHeight' );
  125. // Get Indices of Neighbor Values of an Index in the Simulation Grid
  126. const getNeighborIndicesTSL = ( index ) => {
  127. const width = uint( WIDTH );
  128. // Get 2-D compute coordinate from one-dimensional instanceIndex. The calculation will
  129. // still work even if you dispatch your compute shader 2-dimensionally, since within a compute
  130. // context, instanceIndex is a 1-dimensional value derived from the workgroup dimensions.
  131. // Cast to int to prevent unintended index overflow upon subtraction.
  132. const x = int( index.mod( WIDTH ) );
  133. const y = int( index.div( WIDTH ) );
  134. // The original shader accesses height via texture uvs. However, unlike with textures, we can't
  135. // access areas that are out of bounds. Accordingly, we emulate the Clamp to Edge Wrapping
  136. // behavior of accessing a DataTexture with out of bounds uvs.
  137. const leftX = max( 0, x.sub( 1 ) );
  138. const rightX = min( x.add( 1 ), width.sub( 1 ) );
  139. const bottomY = max( 0, y.sub( 1 ) );
  140. const topY = min( y.add( 1 ), width.sub( 1 ) );
  141. const westIndex = y.mul( width ).add( leftX );
  142. const eastIndex = y.mul( width ).add( rightX );
  143. const southIndex = bottomY.mul( width ).add( x );
  144. const northIndex = topY.mul( width ).add( x );
  145. return { northIndex, southIndex, eastIndex, westIndex };
  146. };
  147. // Get simulation index neighbor values
  148. const getNeighborValuesTSL = ( index, store ) => {
  149. const { northIndex, southIndex, eastIndex, westIndex } = getNeighborIndicesTSL( index );
  150. const north = store.element( northIndex );
  151. const south = store.element( southIndex );
  152. const east = store.element( eastIndex );
  153. const west = store.element( westIndex );
  154. return { north, south, east, west };
  155. };
  156. // Create compute shader for height simulation with explicit read/write buffers
  157. const createComputeHeight = ( readBuffer, writeBuffer ) => Fn( () => {
  158. const { viscosity, mousePos, mouseSize, mouseDeep, mouseSpeed } = effectController;
  159. const height = readBuffer.element( instanceIndex ).toVar();
  160. const prevHeight = prevHeightStorage.element( instanceIndex ).toVar();
  161. const { north, south, east, west } = getNeighborValuesTSL( instanceIndex, readBuffer );
  162. const neighborHeight = north.add( south ).add( east ).add( west );
  163. neighborHeight.mulAssign( 0.5 );
  164. neighborHeight.subAssign( prevHeight );
  165. const newHeight = neighborHeight.mul( viscosity );
  166. // Get x and y position of the coordinate in the water plane
  167. const x = float( globalId.x ).mul( 1 / WIDTH );
  168. const y = float( globalId.y ).mul( 1 / WIDTH );
  169. // Mouse influence
  170. const centerVec = vec2( 0.5 );
  171. // Get length of position in range [ -BOUNDS / 2, BOUNDS / 2 ], offset by mousePos, then scale.
  172. const mousePhase = clamp( length( ( vec2( x, y ).sub( centerVec ) ).mul( BOUNDS ).sub( mousePos ) ).mul( Math.PI ).div( mouseSize ), 0.0, Math.PI );
  173. // "Indent" water down by scaled distance from center of mouse impact
  174. newHeight.addAssign( cos( mousePhase ).add( 1.0 ).mul( mouseDeep ).mul( mouseSpeed.length() ) );
  175. prevHeightStorage.element( instanceIndex ).assign( height );
  176. writeBuffer.element( instanceIndex ).assign( newHeight );
  177. } )().compute( WIDTH * WIDTH, [ 16, 16 ] );
  178. // Create both ping-pong compute shaders
  179. computeHeightAtoB = createComputeHeight( heightStorageA, heightStorageB ).setName( 'Update Height A→B' );
  180. computeHeightBtoA = createComputeHeight( heightStorageB, heightStorageA ).setName( 'Update Height B→A' );
  181. // Water Geometry corresponds with buffered compute grid.
  182. const waterGeometry = new THREE.PlaneGeometry( BOUNDS, BOUNDS, WIDTH - 1, WIDTH - 1 );
  183. const waterMaterial = new THREE.MeshStandardNodeMaterial( {
  184. color: 0x9bd2ec,
  185. metalness: 0.9,
  186. roughness: 0,
  187. transparent: true,
  188. opacity: 0.8,
  189. side: THREE.DoubleSide
  190. } );
  191. // Helper to get height from the current read buffer
  192. const getCurrentHeight = ( index ) => {
  193. return select( readFromA, heightStorageA.element( index ), heightStorageB.element( index ) );
  194. };
  195. // Helper to get normals from the current read buffer
  196. const getCurrentNormals = ( index ) => {
  197. const { northIndex, southIndex, eastIndex, westIndex } = getNeighborIndicesTSL( index );
  198. const north = getCurrentHeight( northIndex );
  199. const south = getCurrentHeight( southIndex );
  200. const east = getCurrentHeight( eastIndex );
  201. const west = getCurrentHeight( westIndex );
  202. const normalX = ( west.sub( east ) ).mul( WIDTH / BOUNDS );
  203. const normalY = ( south.sub( north ) ).mul( WIDTH / BOUNDS );
  204. return { normalX, normalY };
  205. };
  206. waterMaterial.normalNode = Fn( () => {
  207. // To correct the lighting as our mesh undulates, we have to reassign the normals in the normal shader.
  208. const { normalX, normalY } = getCurrentNormals( vertexIndex );
  209. return transformNormalToView( vec3( normalX, normalY.negate(), 1.0 ) ).toVertexStage();
  210. } )();
  211. waterMaterial.positionNode = Fn( () => {
  212. return vec3( positionLocal.x, positionLocal.y, getCurrentHeight( vertexIndex ) );
  213. } )();
  214. waterMesh = new THREE.Mesh( waterGeometry, waterMaterial );
  215. waterMesh.rotation.x = - Math.PI * 0.5;
  216. waterMesh.matrixAutoUpdate = false;
  217. waterMesh.updateMatrix();
  218. scene.add( waterMesh );
  219. // Pool border
  220. const borderGeom = new THREE.TorusGeometry( 4.2, 0.1, 12, 4 );
  221. borderGeom.rotateX( Math.PI * 0.5 );
  222. borderGeom.rotateY( Math.PI * 0.25 );
  223. poolBorder = new THREE.Mesh( borderGeom, new THREE.MeshStandardMaterial( { color: 0x908877, roughness: 0.2 } ) );
  224. scene.add( poolBorder );
  225. // THREE.Mesh just for mouse raycasting
  226. const geometryRay = new THREE.PlaneGeometry( BOUNDS, BOUNDS, 1, 1 );
  227. meshRay = new THREE.Mesh( geometryRay, new THREE.MeshBasicMaterial( { color: 0xFFFFFF, visible: false } ) );
  228. meshRay.rotation.x = - Math.PI / 2;
  229. meshRay.matrixAutoUpdate = false;
  230. meshRay.updateMatrix();
  231. scene.add( meshRay );
  232. // Initialize sphere mesh instance position and velocity.
  233. // position<vec3> + velocity<vec2> + unused<vec3> = 8 floats per sphere.
  234. // for structs arrays must be enclosed in multiple of 4
  235. const duckStride = 8;
  236. const duckInstanceDataArray = new Float32Array( NUM_DUCKS * duckStride );
  237. // Only hold velocity in x and z directions.
  238. // The sphere is wedded to the surface of the water, and will only move vertically with the water.
  239. for ( let i = 0; i < NUM_DUCKS; i ++ ) {
  240. duckInstanceDataArray[ i * duckStride + 0 ] = ( Math.random() - 0.5 ) * BOUNDS * 0.7;
  241. duckInstanceDataArray[ i * duckStride + 1 ] = 0;
  242. duckInstanceDataArray[ i * duckStride + 2 ] = ( Math.random() - 0.5 ) * BOUNDS * 0.7;
  243. }
  244. const DuckStruct = struct( {
  245. position: 'vec3',
  246. velocity: 'vec2'
  247. } );
  248. // Duck instance data storage
  249. const duckInstanceDataStorage = instancedArray( duckInstanceDataArray, DuckStruct ).setName( 'DuckInstanceData' );
  250. computeDucks = Fn( () => {
  251. const yOffset = float( - 0.04 );
  252. const verticalResponseFactor = float( 0.98 );
  253. const waterPushFactor = float( 0.015 );
  254. const linearDamping = float( 0.92 );
  255. const bounceDamping = float( - 0.4 );
  256. // Get 2-D compute coordinate from one-dimensional instanceIndex.
  257. const instancePosition = duckInstanceDataStorage.element( instanceIndex ).get( 'position' ).toVar();
  258. const velocity = duckInstanceDataStorage.element( instanceIndex ).get( 'velocity' ).toVar();
  259. const gridCoordX = instancePosition.x.div( BOUNDS ).add( 0.5 ).mul( WIDTH );
  260. const gridCoordZ = instancePosition.z.div( BOUNDS ).add( 0.5 ).mul( WIDTH );
  261. // Cast to int to prevent unintended index overflow upon subtraction.
  262. const xCoord = uint( clamp( floor( gridCoordX ), 0, WIDTH - 1 ) );
  263. const zCoord = uint( clamp( floor( gridCoordZ ), 0, WIDTH - 1 ) );
  264. const heightInstanceIndex = zCoord.mul( WIDTH ).add( xCoord );
  265. // Get height of water at the duck's position (use current read buffer)
  266. const waterHeight = getCurrentHeight( heightInstanceIndex );
  267. const { normalX, normalY } = getCurrentNormals( heightInstanceIndex );
  268. // Calculate the target Y position based on the water height and the duck's vertical offset
  269. const targetY = waterHeight.add( yOffset );
  270. const deltaY = targetY.sub( instancePosition.y );
  271. instancePosition.y.addAssign( deltaY.mul( verticalResponseFactor ) ); // Gradually update position
  272. // Get the normal of the water surface at the duck's position
  273. const pushX = normalX.mul( waterPushFactor );
  274. const pushZ = normalY.mul( waterPushFactor );
  275. // Apply the water push to the duck's velocity
  276. velocity.x.mulAssign( linearDamping );
  277. velocity.y.mulAssign( linearDamping );
  278. velocity.x.addAssign( pushX );
  279. velocity.y.addAssign( pushZ );
  280. // update position based on velocity
  281. instancePosition.x.addAssign( velocity.x );
  282. instancePosition.z.addAssign( velocity.y );
  283. // Clamp position to the pool bounds
  284. If( instancePosition.x.lessThan( - limit ), () => {
  285. instancePosition.x = - limit;
  286. velocity.x.mulAssign( bounceDamping );
  287. } ).ElseIf( instancePosition.x.greaterThan( limit ), () => {
  288. instancePosition.x = limit;
  289. velocity.x.mulAssign( bounceDamping );
  290. } );
  291. If( instancePosition.z.lessThan( - limit ), () => {
  292. instancePosition.z = - limit;
  293. velocity.y.mulAssign( bounceDamping ); // Invert and damp vz (velocity.y)
  294. } ).ElseIf( instancePosition.z.greaterThan( limit ), () => {
  295. instancePosition.z = limit;
  296. velocity.y.mulAssign( bounceDamping );
  297. } );
  298. // assignment of new values to the instance data storage
  299. duckInstanceDataStorage.element( instanceIndex ).get( 'position' ).assign( instancePosition );
  300. duckInstanceDataStorage.element( instanceIndex ).get( 'velocity' ).assign( velocity );
  301. } )().compute( NUM_DUCKS ).setName( 'Update Ducks' );
  302. // Models / Textures
  303. const hdrLoader = new HDRLoader().setPath( './textures/equirectangular/' );
  304. const glbloader = new GLTFLoader().setPath( 'models/gltf/' );
  305. glbloader.setDRACOLoader( new DRACOLoader().setDecoderPath( DRACO_GLTF_CONFIG ) );
  306. const [ env, model ] = await Promise.all( [ hdrLoader.loadAsync( 'blouberg_sunrise_2_1k.hdr' ), glbloader.loadAsync( 'duck.glb' ) ] );
  307. env.mapping = THREE.EquirectangularReflectionMapping;
  308. scene.environment = env;
  309. scene.background = env;
  310. scene.backgroundBlurriness = 0.3;
  311. scene.environmentIntensity = 1.25;
  312. duckModel = model.scene.children[ 0 ];
  313. duckModel.material.positionNode = Fn( () => {
  314. const instancePosition = duckInstanceDataStorage.element( instanceIndex ).get( 'position' );
  315. const newPosition = positionLocal.add( instancePosition );
  316. return newPosition;
  317. } )();
  318. const duckMesh = new THREE.InstancedMesh( duckModel.geometry, duckModel.material, NUM_DUCKS );
  319. scene.add( duckMesh );
  320. renderer = new THREE.WebGPURenderer( { antialias: true, requiredLimits: { maxStorageBuffersInVertexStage: 2 } } );
  321. renderer.setPixelRatio( window.devicePixelRatio );
  322. renderer.setSize( window.innerWidth, window.innerHeight );
  323. renderer.toneMapping = THREE.ACESFilmicToneMapping;
  324. renderer.toneMappingExposure = 0.5;
  325. renderer.setAnimationLoop( render );
  326. container.appendChild( renderer.domElement );
  327. renderer.inspector = new Inspector();
  328. document.body.appendChild( renderer.inspector.domElement );
  329. controls = new OrbitControls( camera, container );
  330. //
  331. container.style.touchAction = 'none';
  332. container.addEventListener( 'pointermove', onPointerMove );
  333. container.addEventListener( 'pointerdown', onPointerDown );
  334. container.addEventListener( 'pointerup', onPointerUp );
  335. window.addEventListener( 'resize', onWindowResize );
  336. // GUI
  337. const gui = renderer.inspector.createParameters( 'Settings' );
  338. gui.add( effectController.mouseSize, 'value', 0.1, .3 ).name( 'Mouse Size' );
  339. gui.add( effectController.mouseDeep, 'value', 0.1, 1 ).name( 'Mouse Deep' );
  340. gui.add( effectController.viscosity, 'value', 0.9, 0.96, 0.001 ).name( 'viscosity' );
  341. gui.add( effectController, 'speed', 1, 6, 1 );
  342. gui.add( effectController, 'ducksEnabled' ).onChange( () => {
  343. duckMesh.visible = effectController.ducksEnabled;
  344. } );
  345. gui.add( effectController, 'wireframe' ).onChange( () => {
  346. waterMesh.material.wireframe = ! waterMesh.material.wireframe;
  347. poolBorder.material.wireframe = ! poolBorder.material.wireframe;
  348. duckModel.material.wireframe = ! duckModel.material.wireframe;
  349. waterMesh.material.needsUpdate = true;
  350. poolBorder.material.needsUpdate = true;
  351. } );
  352. }
  353. function onWindowResize() {
  354. camera.aspect = window.innerWidth / window.innerHeight;
  355. camera.updateProjectionMatrix();
  356. renderer.setSize( window.innerWidth, window.innerHeight );
  357. }
  358. function setMouseCoords( x, y ) {
  359. mouseCoords.set( ( x / renderer.domElement.clientWidth ) * 2 - 1, - ( y / renderer.domElement.clientHeight ) * 2 + 1 );
  360. }
  361. function onPointerDown() {
  362. mouseDown = true;
  363. firstClick = true;
  364. updateOriginMouseDown = true;
  365. }
  366. function onPointerUp() {
  367. mouseDown = false;
  368. firstClick = false;
  369. updateOriginMouseDown = false;
  370. controls.enabled = true;
  371. }
  372. function onPointerMove( event ) {
  373. if ( event.isPrimary === false ) return;
  374. setMouseCoords( event.clientX, event.clientY );
  375. }
  376. function raycast() {
  377. if ( mouseDown && ( firstClick || ! controls.enabled ) ) {
  378. raycaster.setFromCamera( mouseCoords, camera );
  379. const intersects = raycaster.intersectObject( meshRay );
  380. if ( intersects.length > 0 ) {
  381. const point = intersects[ 0 ].point;
  382. if ( updateOriginMouseDown ) {
  383. effectController.mousePos.value.set( point.x, point.z );
  384. updateOriginMouseDown = false;
  385. }
  386. effectController.mouseSpeed.value.set(
  387. ( point.x - effectController.mousePos.value.x ),
  388. ( point.z - effectController.mousePos.value.y )
  389. );
  390. effectController.mousePos.value.set( point.x, point.z );
  391. if ( firstClick ) {
  392. controls.enabled = false;
  393. }
  394. } else {
  395. updateOriginMouseDown = true;
  396. effectController.mouseSpeed.value.set( 0, 0 );
  397. }
  398. firstClick = false;
  399. } else {
  400. updateOriginMouseDown = true;
  401. effectController.mouseSpeed.value.set( 0, 0 );
  402. }
  403. }
  404. function render() {
  405. raycast();
  406. frame ++;
  407. if ( frame >= 7 - effectController.speed ) {
  408. // Ping-pong: alternate which buffer we read from and write to
  409. if ( pingPong === 0 ) {
  410. renderer.compute( computeHeightAtoB, [ 8, 8, 1 ] );
  411. readFromA.value = 0; // Material now reads from B (just written)
  412. } else {
  413. renderer.compute( computeHeightBtoA, [ 8, 8, 1 ] );
  414. readFromA.value = 1; // Material now reads from A (just written)
  415. }
  416. pingPong = 1 - pingPong;
  417. if ( effectController.ducksEnabled ) {
  418. renderer.compute( computeDucks );
  419. }
  420. frame = 0;
  421. }
  422. renderer.render( scene, camera );
  423. }
  424. </script>
  425. </body>
  426. </html>
粤ICP备19079148号