webgl_gpgpu_birds.html 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - gpgpu - flocking</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. <style>
  8. body {
  9. background-color: #ffffff;
  10. margin: 0px;
  11. overflow: hidden;
  12. font-family:Monospace;
  13. font-size:13px;
  14. text-align:center;
  15. text-align:center;
  16. cursor: pointer;
  17. }
  18. a {
  19. color:#0078ff;
  20. }
  21. #info {
  22. color: #000;
  23. position: absolute;
  24. top: 10px;
  25. width: 100%;
  26. }
  27. </style>
  28. </head>
  29. <body>
  30. <div id="info">
  31. <a href="http://threejs.org" target="_blank">three.js</a> - <span id="birds"></span> webgl gpgpu birds<br/>
  32. Select <span id="options"></span> birds<br/>
  33. Move mouse to disturb birds.
  34. </div>
  35. <script src="../build/three.min.js"></script>
  36. <script src="js/Detector.js"></script>
  37. <script src="js/libs/stats.min.js"></script>
  38. <script src="js/libs/dat.gui.min.js"></script>
  39. <script src="js/SimulatorRenderer.js"></script>
  40. <!--
  41. TODO: If you're reading this, you may wish to improve this example by
  42. - Replacing the custom BirdGeometry with a BufferGeometry?
  43. - Create a better shading for the birds?
  44. - Refactoring the SimulationRenderer to a more generic TextureRenderer / making the GPGPU workflow easier?
  45. -->
  46. <!-- pass through vertex shader -->
  47. <script id="vertexShader" type="x-shader/x-vertex">
  48. void main() {
  49. gl_Position = vec4( position, 1.0 );
  50. }
  51. </script>
  52. <!-- pass through fragment shader -->
  53. <script id="fragmentShader" type="x-shader/x-fragment">
  54. uniform vec2 resolution;
  55. uniform float time;
  56. uniform sampler2D texture;
  57. void main() {
  58. vec2 uv = gl_FragCoord.xy / resolution.xy;
  59. vec3 color = texture2D( texture, uv ).xyz;
  60. gl_FragColor=vec4(color, 1.0);
  61. }
  62. </script>
  63. <!-- end pass through shaders -->
  64. <!-- shader for bird's position -->
  65. <script id="fragmentShaderPosition" type="x-shader/x-fragment">
  66. uniform vec2 resolution;
  67. uniform float time;
  68. uniform float delta;
  69. uniform sampler2D textureVelocity;
  70. uniform sampler2D texturePosition;
  71. void main() {
  72. vec2 uv = gl_FragCoord.xy / resolution.xy;
  73. vec4 tmpPos = texture2D( texturePosition, uv );
  74. vec3 position = tmpPos.xyz;
  75. vec3 velocity = texture2D( textureVelocity, uv ).xyz;
  76. float phase = tmpPos.w;
  77. phase = mod( ( phase + delta +
  78. length( velocity.xz ) * delta * 3. +
  79. max( velocity.y, 0.0 ) * delta * 6. ), 62.83 );
  80. gl_FragColor = vec4( position + velocity * delta * 15. , phase );
  81. }
  82. </script>
  83. <!-- shader for bird's velocity -->
  84. <script id="fragmentShaderVelocity" type="x-shader/x-fragment">
  85. uniform vec2 resolution;
  86. uniform float time;
  87. uniform float testing;
  88. uniform float delta; // about 0.016
  89. uniform float seperationDistance; // 20
  90. uniform float alignmentDistance; // 40
  91. uniform float cohesionDistance; //
  92. uniform float freedomFactor;
  93. uniform vec3 predator;
  94. uniform sampler2D textureVelocity;
  95. uniform sampler2D texturePosition;
  96. const float width = WIDTH;
  97. const float height = WIDTH;
  98. const float PI = 3.141592653589793;
  99. const float PI_2 = PI * 2.0;
  100. // const float VISION = PI * 0.55;
  101. float zoneRadius = 40.0;
  102. float zoneRadiusSquared = zoneRadius * zoneRadius;
  103. float separationThresh = 0.45;
  104. float alignmentThresh = 0.65;
  105. const float UPPER_BOUNDS = 400.0;
  106. const float LOWER_BOUNDS = -UPPER_BOUNDS;
  107. const float SPEED_LIMIT = 9.0;
  108. float rand(vec2 co){
  109. return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
  110. }
  111. void main() {
  112. zoneRadius = seperationDistance + alignmentDistance + cohesionDistance;
  113. separationThresh = seperationDistance / zoneRadius;
  114. alignmentThresh = ( seperationDistance + alignmentDistance ) / zoneRadius;
  115. zoneRadiusSquared = zoneRadius * zoneRadius;
  116. vec2 uv = gl_FragCoord.xy / resolution.xy;
  117. vec3 birdPosition, birdVelocity;
  118. vec3 selfPosition = texture2D( texturePosition, uv ).xyz;
  119. vec3 selfVelocity = texture2D( textureVelocity, uv ).xyz;
  120. float dist;
  121. vec3 dir; // direction
  122. float distSquared;
  123. float seperationSquared = seperationDistance * seperationDistance;
  124. float cohesionSquared = cohesionDistance * cohesionDistance;
  125. float f;
  126. float percent;
  127. vec3 velocity = selfVelocity;
  128. float limit = SPEED_LIMIT;
  129. dir = predator * UPPER_BOUNDS - selfPosition;
  130. dir.z = 0.;
  131. // dir.z *= 0.6;
  132. dist = length( dir );
  133. distSquared = dist * dist;
  134. float preyRadius = 150.0;
  135. float preyRadiusSq = preyRadius * preyRadius;
  136. // move birds away from predator
  137. if (dist < preyRadius) {
  138. f = ( distSquared / preyRadiusSq - 1.0 ) * delta * 100.;
  139. velocity += normalize( dir ) * f;
  140. limit += 5.0;
  141. }
  142. // if (testing == 0.0) {}
  143. // if ( rand( uv + time ) < freedomFactor ) {}
  144. // Attract flocks to the center
  145. vec3 central = vec3( 0., 0., 0. );
  146. dir = selfPosition - central;
  147. dist = length( dir );
  148. dir.y *= 2.5;
  149. velocity -= normalize( dir ) * delta * 5.;
  150. for (float y=0.0;y<height;y++) {
  151. for (float x=0.0;x<width;x++) {
  152. if (
  153. x == gl_FragCoord.x && y == gl_FragCoord.y) continue;
  154. birdPosition = texture2D( texturePosition,
  155. vec2( x / resolution.x, y / resolution.y ) ).xyz;
  156. dir = birdPosition - selfPosition;
  157. dist = length(dir);
  158. distSquared = dist * dist;
  159. if ( dist > 0.0 && distSquared < zoneRadiusSquared ) {
  160. percent = distSquared / zoneRadiusSquared;
  161. if ( percent < separationThresh ) { // low
  162. // Separation - Move apart for comfort
  163. f = (separationThresh / percent - 1.0) * delta;
  164. velocity -= normalize(dir) * f;
  165. } else if ( percent < alignmentThresh ) { // high
  166. // Alignment - fly the same direction
  167. float threshDelta = alignmentThresh - separationThresh;
  168. float adjustedPercent = ( percent - separationThresh ) / threshDelta;
  169. birdVelocity = texture2D( textureVelocity, vec2(x/resolution.x, y/resolution.y) ).xyz;
  170. f = ( 0.5 - cos( adjustedPercent * PI_2 ) * 0.5 + 0.5 ) * delta;
  171. velocity += normalize(birdVelocity) * f;
  172. } else {
  173. // Attraction / Cohesion - move closer
  174. float threshDelta = 1.0 - alignmentThresh;
  175. float adjustedPercent = ( percent - alignmentThresh ) / threshDelta;
  176. f = ( 0.5 - ( cos( adjustedPercent * PI_2 ) * -0.5 + 0.5 ) ) * delta;
  177. velocity += normalize(dir) * f;
  178. }
  179. }
  180. }
  181. }
  182. // this make tends to fly around than down or up
  183. // if (velocity.y > 0.) velocity.y *= (1. - 0.2 * delta);
  184. // Speed Limits
  185. if ( length( velocity ) > limit ) {
  186. velocity = normalize( velocity ) * limit;
  187. }
  188. gl_FragColor = vec4( velocity, 1.0 );
  189. }
  190. </script>
  191. <script type="x-shader/x-vertex" id="birdVS">
  192. attribute vec2 reference;
  193. attribute float birdVertex;
  194. attribute vec3 birdColor;
  195. uniform sampler2D texturePosition;
  196. uniform sampler2D textureVelocity;
  197. varying vec3 vNormal;
  198. varying vec2 vUv;
  199. varying vec4 vColor;
  200. varying float z;
  201. uniform float time;
  202. void main() {
  203. vNormal = normal;
  204. vec4 tmpPos = texture2D( texturePosition, reference );
  205. vec3 pos = tmpPos.xyz;
  206. vec3 velocity = normalize(texture2D( textureVelocity, reference ).xyz);
  207. vec3 newPosition = position;
  208. if ( birdVertex == 4.0 || birdVertex == 7.0 ) {
  209. // flap wings
  210. newPosition.y = sin( tmpPos.w ) * 5.;
  211. }
  212. newPosition = mat3( modelMatrix ) * newPosition;
  213. velocity.z *= -1.;
  214. float xz = length( velocity.xz );
  215. float xyz = 1.;
  216. float x = sqrt( 1. - velocity.y * velocity.y );
  217. float cosry = velocity.x / xz;
  218. float sinry = velocity.z / xz;
  219. float cosrz = x / xyz;
  220. float sinrz = velocity.y / xyz;
  221. mat3 maty = mat3(
  222. cosry, 0, -sinry,
  223. 0 , 1, 0 ,
  224. sinry, 0, cosry
  225. );
  226. mat3 matz = mat3(
  227. cosrz , sinrz, 0,
  228. -sinrz, cosrz, 0,
  229. 0 , 0 , 1
  230. );
  231. newPosition = maty * matz * newPosition;
  232. newPosition += pos;
  233. z = newPosition.z;
  234. vColor = vec4( birdColor, 1.0 );
  235. gl_Position = projectionMatrix * viewMatrix * vec4( newPosition, 1.0 );
  236. }
  237. </script>
  238. <!-- bird geometry shader -->
  239. <script type="x-shader/x-fragment" id="birdFS">
  240. varying vec3 vNormal;
  241. varying vec2 vUv;
  242. varying vec4 vColor;
  243. varying float z;
  244. uniform vec3 color;
  245. void main() {
  246. // Fake colors for now
  247. float z2 = 0.2 + ( 1000. - z ) / 1000. * vColor.x;
  248. gl_FragColor = vec4( z2, z2, z2, 1. );
  249. // vec3 light = vec3( 0.0, 1.0, 1.0 );
  250. // light = normalize( light );
  251. // float dProd = dot( vNormal, light ) ; //* 0.5 + 0.5;
  252. // vec4 tcolor = vColor;
  253. // vec4 gray = vec4( vec3( tcolor.r * 0.3 + tcolor.g * 0.59 + tcolor.b * 0.11 ), 1.0 );
  254. // gl_FragColor = gray * dProd;
  255. // gl_FragColor = vec4( dProd * tcolor );
  256. }
  257. </script>
  258. <script>
  259. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  260. var hash = document.location.hash.substr( 1 );
  261. if (hash) hash = parseInt(hash, 0);
  262. /* TEXTURE WIDTH FOR SIMULATION */
  263. var WIDTH = hash || 32;
  264. var BIRDS = 1024;
  265. // Custom Geometry
  266. THREE.BirdGeometry = function () {
  267. THREE.Geometry.call( this );
  268. BIRDS = WIDTH * WIDTH;
  269. var verts = this.vertices;
  270. var faces = this.faces;
  271. var uvs = this.faceVertexUvs[ 0 ];
  272. var fi = 0;
  273. for (var f = 0; f<BIRDS; f++ ) {
  274. verts.push(
  275. new THREE.Vector3(0, -0, -20),
  276. new THREE.Vector3(0, 4, -20),
  277. new THREE.Vector3(0, 0, 30)
  278. );
  279. faces.push(new THREE.Face3(
  280. fi++,
  281. fi++,
  282. fi++
  283. ));
  284. uvs.push([
  285. new THREE.Vector2(0, 0),
  286. new THREE.Vector2(0, 1),
  287. new THREE.Vector2(1, 1)
  288. ]);
  289. var wingsSpan = 20;
  290. verts.push(
  291. new THREE.Vector3(0, 0, -15),
  292. new THREE.Vector3(-wingsSpan, 0, 0),
  293. new THREE.Vector3(0, 0, 15)
  294. );
  295. verts.push(
  296. new THREE.Vector3(0, 0, 15),
  297. new THREE.Vector3(wingsSpan, 0, 0),
  298. new THREE.Vector3(0, 0, -15)
  299. );
  300. faces.push(new THREE.Face3(
  301. fi++,
  302. fi++,
  303. fi++
  304. ));
  305. faces.push(new THREE.Face3(
  306. fi++,
  307. fi++,
  308. fi++
  309. ));
  310. uvs.push([
  311. new THREE.Vector2(0, 0),
  312. new THREE.Vector2(0, 1),
  313. new THREE.Vector2(1, 1)
  314. ]);
  315. uvs.push([
  316. new THREE.Vector2(0, 0),
  317. new THREE.Vector2(0, 1),
  318. new THREE.Vector2(1, 1)
  319. ]);
  320. }
  321. this.applyMatrix( new THREE.Matrix4().makeScale( 0.2, 0.2, 0.2 ) );
  322. this.computeFaceNormals();
  323. this.computeVertexNormals();
  324. }
  325. THREE.BirdGeometry.prototype = Object.create( THREE.Geometry.prototype );
  326. var container, stats;
  327. var camera, scene, renderer, geometry, i, h, color;
  328. var mouseX = 0, mouseY = 0;
  329. var windowHalfX = window.innerWidth / 2;
  330. var windowHalfY = window.innerHeight / 2;
  331. var HEIGHT = WIDTH;
  332. var PARTICLES = WIDTH * WIDTH;
  333. var BOUNDS = 800, BOUNDS_HALF = BOUNDS / 2;
  334. document.getElementById('birds').innerText = PARTICLES;
  335. function change(n) {
  336. location.hash = n;
  337. location.reload();
  338. return false;
  339. }
  340. var options = '';
  341. for (i=1; i<7; i++) {
  342. var j = Math.pow(2, i);
  343. options += '<a href="#" onclick="return change(' + j + ')">' + (j * j) + '</a> ';
  344. }
  345. document.getElementById('options').innerHTML = options;
  346. var debug;
  347. var data, texture;
  348. var spline = new THREE.SplineCurve3();
  349. var timer = 0;
  350. var paused = false;
  351. var last = performance.now();
  352. var delta, now, t = 0;
  353. var simulator;
  354. init();
  355. animate();
  356. onMouseDown();
  357. function init() {
  358. container = document.createElement( 'div' );
  359. document.body.appendChild( container );
  360. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 3000 );
  361. camera.position.z = 350;
  362. scene = new THREE.Scene();
  363. scene.fog = new THREE.Fog( 0xffffff, 100, 1000 );
  364. renderer = new THREE.WebGLRenderer();
  365. renderer.setSize( window.innerWidth, window.innerHeight );
  366. container.appendChild( renderer.domElement );
  367. renderer.setClearColor( scene.fog.color, 1 );
  368. renderer.autoClear = true;
  369. ////////
  370. simulator = new SimulatorRenderer(WIDTH, renderer);
  371. simulator.init();
  372. /////////
  373. plane = new THREE.PlaneGeometry( BOUNDS, BOUNDS, 1, 1 );
  374. // new THREE.BoxGeometry( BOUNDS, BOUNDS, BOUNDS),
  375. cube = new THREE.Mesh(
  376. plane,
  377. new THREE.MeshBasicMaterial( {color: 0xdddddd, wireframe: true, depthWrite: false} )
  378. );
  379. cube.rotation.x = -Math.PI / 2;
  380. cube.position.y = -400;
  381. // scene.add(cube);
  382. stats = new Stats();
  383. stats.domElement.style.position = 'absolute';
  384. stats.domElement.style.top = '0px';
  385. container.appendChild( stats.domElement );
  386. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  387. // document.addEventListener( 'mousedown', onMouseDown, false );
  388. document.addEventListener( 'mouseup', onMouseUp, false );
  389. document.addEventListener( 'touchstart', onDocumentTouchStart, false );
  390. document.addEventListener( 'touchmove', onDocumentTouchMove, false );
  391. //
  392. window.addEventListener( 'resize', onWindowResize, false );
  393. var gui = new dat.GUI();
  394. var effectController = {
  395. seperation: 20.0,
  396. alignment: 20.0,
  397. cohesion: 20.0,
  398. freedom: 0.75
  399. };
  400. var valuesChanger = function() {
  401. simulator.velocityUniforms.seperationDistance.value = effectController.seperation;
  402. simulator.velocityUniforms.alignmentDistance.value = effectController.alignment;
  403. simulator.velocityUniforms.cohesionDistance.value = effectController.cohesion;
  404. simulator.velocityUniforms.freedomFactor.value = effectController.freedom;
  405. };
  406. valuesChanger();
  407. gui.add( effectController, "seperation", 0.0, 100.0, 1.0 ).onChange( valuesChanger );
  408. gui.add( effectController, "alignment", 0.0, 100, 0.001 ).onChange( valuesChanger );
  409. gui.add( effectController, "cohesion", 0.0, 100, 0.025 ).onChange( valuesChanger );
  410. // gui.add( effectController, "freedom", 0.0, 1.0, 0.025 ).onChange( valuesChanger );
  411. gui.close();
  412. initBirds();
  413. // var ambient = new THREE.AmbientLight( 0x444444 );
  414. // scene.add( ambient );
  415. // light = new THREE.DirectionalLight( 0xffffff );
  416. // light.position.set( 1, 1, 1 );
  417. // scene.add( light );
  418. // light = new THREE.DirectionalLight( 0xffffff );
  419. // light.position.set( -1, -1, -1 );
  420. // scene.add( light );
  421. }
  422. function initBirds() {
  423. var geometry = new THREE.BirdGeometry( );
  424. // For Vertex Shaders
  425. birdAttributes = {
  426. index: { type: 'i', value: [] },
  427. birdColor: { type: 'c', value: [] },
  428. reference: { type: 'v2', value: [] },
  429. birdVertex: { type: 'f', value: [] },
  430. };
  431. // For Vertex and Fragment
  432. birdUniforms = {
  433. color: { type: "c", value: new THREE.Color( 0xff2200 ) },
  434. texturePosition: { type: "t", value: null },
  435. textureVelocity: { type: "t", value: null },
  436. time: { type: "f", value: 1.0 },
  437. delta: { type: "f", value: 0.0 },
  438. };
  439. // ShaderMaterial
  440. var shaderMaterial = new THREE.ShaderMaterial( {
  441. uniforms: birdUniforms,
  442. attributes: birdAttributes,
  443. vertexShader: document.getElementById( 'birdVS' ).textContent,
  444. fragmentShader: document.getElementById( 'birdFS' ).textContent,
  445. side: THREE.DoubleSide,
  446. // wireframe: true
  447. });
  448. // geometry.dynamic = false;
  449. var vertices = geometry.vertices;
  450. var birdColors = birdAttributes.birdColor.value;
  451. var references = birdAttributes.reference.value;
  452. var birdVertex = birdAttributes.birdVertex.value;
  453. for( var v = 0; v < vertices.length; v++ ) {
  454. var i = ~~(v / 3);
  455. var x = (i % WIDTH) / WIDTH;
  456. var y = ~~(i / WIDTH) / WIDTH;
  457. birdColors[ v ] = new THREE.Color(
  458. 0x444444 +
  459. ~~(v / 9) / BIRDS * 0x666666
  460. );
  461. references[ v ] = new THREE.Vector2( x, y );
  462. birdVertex[ v ] = v % 9;
  463. }
  464. // var
  465. birdMesh = new THREE.Mesh( geometry, shaderMaterial );
  466. birdMesh.rotation.y = Math.PI / 2;
  467. birdMesh.sortObjects = false;
  468. birdMesh.matrixAutoUpdate = false;
  469. birdMesh.updateMatrix();
  470. scene.add(birdMesh);
  471. }
  472. function onWindowResize() {
  473. windowHalfX = window.innerWidth / 2;
  474. windowHalfY = window.innerHeight / 2;
  475. camera.aspect = window.innerWidth / window.innerHeight;
  476. camera.updateProjectionMatrix();
  477. renderer.setSize( window.innerWidth, window.innerHeight );
  478. }
  479. function onDocumentMouseMove( event ) {
  480. mouseX = event.clientX - windowHalfX;
  481. mouseY = event.clientY - windowHalfY;
  482. }
  483. function onDocumentTouchStart( event ) {
  484. if ( event.touches.length === 1 ) {
  485. event.preventDefault();
  486. mouseX = event.touches[ 0 ].pageX - windowHalfX;
  487. mouseY = event.touches[ 0 ].pageY - windowHalfY;
  488. }
  489. }
  490. function onDocumentTouchMove( event ) {
  491. if ( event.touches.length === 1 ) {
  492. event.preventDefault();
  493. mouseX = event.touches[ 0 ].pageX - windowHalfX;
  494. mouseY = event.touches[ 0 ].pageY - windowHalfY;
  495. }
  496. }
  497. //
  498. function animate() {
  499. requestAnimationFrame( animate );
  500. render();
  501. stats.update();
  502. }
  503. function render() {
  504. now = performance.now()
  505. delta = (now - last) / 1000;
  506. if (delta > 1) delta = 1; // safety cap on large deltas
  507. last = now;
  508. birdUniforms.time.value = now;
  509. birdUniforms.delta.value = delta;
  510. // if ( paused ) {
  511. // camera.position.x += ( mouseX * 2 - camera.position.x ) * 0.05;
  512. // camera.position.y += ( - mouseY * 2 - camera.position.y ) * 0.05;
  513. // camera.lookAt( scene.position );
  514. // delta = 0.0001;
  515. // }
  516. if (!paused) {
  517. simulator.simulate( delta );
  518. birdUniforms.texturePosition.value = simulator.currentPosition;
  519. birdUniforms.textureVelocity.value = simulator.currentVelocity;
  520. }
  521. simulator.velocityUniforms.predator.value.set( mouseX / windowHalfX, -mouseY / windowHalfY, 0 );
  522. mouseX = 10000;
  523. mouseY = 10000;
  524. renderer.render( scene, camera );
  525. }
  526. function onMouseDown() {
  527. // simulator.velocityUniforms.testing.value = 0;
  528. }
  529. function onMouseUp() {
  530. // simulator.velocityUniforms.testing.value = 1;
  531. }
  532. </script>
  533. </body>
  534. </html>