|
378 | 378 | for ( let v = 0; v < triangles * 3; v ++ ) { |
379 | 379 |
|
380 | 380 | const triangleIndex = ~ ~ ( v / 3 ); |
381 | | - const birdIndex = ~ ~ ( triangleIndex / trianglesPerBird ) |
| 381 | + const birdIndex = ~ ~ ( triangleIndex / trianglesPerBird ); |
382 | 382 | const x = ( birdIndex % WIDTH ) / WIDTH; |
383 | 383 | const y = ~ ~ ( birdIndex / WIDTH ) / WIDTH; |
384 | 384 |
|
|
468 | 468 |
|
469 | 469 | const valuesChanger = function () { |
470 | 470 |
|
471 | | - velocityUniforms[ "separationDistance" ].value = effectController.separation; |
472 | | - velocityUniforms[ "alignmentDistance" ].value = effectController.alignment; |
473 | | - velocityUniforms[ "cohesionDistance" ].value = effectController.cohesion; |
474 | | - velocityUniforms[ "freedomFactor" ].value = effectController.freedom; |
| 471 | + velocityUniforms[ 'separationDistance' ].value = effectController.separation; |
| 472 | + velocityUniforms[ 'alignmentDistance' ].value = effectController.alignment; |
| 473 | + velocityUniforms[ 'cohesionDistance' ].value = effectController.cohesion; |
| 474 | + velocityUniforms[ 'freedomFactor' ].value = effectController.freedom; |
475 | 475 |
|
476 | 476 | }; |
477 | 477 |
|
478 | 478 | valuesChanger(); |
479 | 479 |
|
480 | | - gui.add( effectController, "separation", 0.0, 100.0, 1.0 ).onChange( valuesChanger ); |
481 | | - gui.add( effectController, "alignment", 0.0, 100, 0.001 ).onChange( valuesChanger ); |
482 | | - gui.add( effectController, "cohesion", 0.0, 100, 0.025 ).onChange( valuesChanger ); |
| 480 | + gui.add( effectController, 'separation', 0.0, 100.0, 1.0 ).onChange( valuesChanger ); |
| 481 | + gui.add( effectController, 'alignment', 0.0, 100, 0.001 ).onChange( valuesChanger ); |
| 482 | + gui.add( effectController, 'cohesion', 0.0, 100, 0.025 ).onChange( valuesChanger ); |
483 | 483 | gui.close(); |
484 | 484 |
|
485 | 485 | initBirds(); |
|
501 | 501 | fillPositionTexture( dtPosition ); |
502 | 502 | fillVelocityTexture( dtVelocity ); |
503 | 503 |
|
504 | | - velocityVariable = gpuCompute.addVariable( "textureVelocity", document.getElementById( 'fragmentShaderVelocity' ).textContent, dtVelocity ); |
505 | | - positionVariable = gpuCompute.addVariable( "texturePosition", document.getElementById( 'fragmentShaderPosition' ).textContent, dtPosition ); |
| 504 | + velocityVariable = gpuCompute.addVariable( 'textureVelocity', document.getElementById( 'fragmentShaderVelocity' ).textContent, dtVelocity ); |
| 505 | + positionVariable = gpuCompute.addVariable( 'texturePosition', document.getElementById( 'fragmentShaderPosition' ).textContent, dtPosition ); |
506 | 506 |
|
507 | 507 | gpuCompute.setVariableDependencies( velocityVariable, [ positionVariable, velocityVariable ] ); |
508 | 508 | gpuCompute.setVariableDependencies( positionVariable, [ positionVariable, velocityVariable ] ); |
509 | 509 |
|
510 | 510 | positionUniforms = positionVariable.material.uniforms; |
511 | 511 | velocityUniforms = velocityVariable.material.uniforms; |
512 | 512 |
|
513 | | - positionUniforms[ "time" ] = { value: 0.0 }; |
514 | | - positionUniforms[ "delta" ] = { value: 0.0 }; |
515 | | - velocityUniforms[ "time" ] = { value: 1.0 }; |
516 | | - velocityUniforms[ "delta" ] = { value: 0.0 }; |
517 | | - velocityUniforms[ "testing" ] = { value: 1.0 }; |
518 | | - velocityUniforms[ "separationDistance" ] = { value: 1.0 }; |
519 | | - velocityUniforms[ "alignmentDistance" ] = { value: 1.0 }; |
520 | | - velocityUniforms[ "cohesionDistance" ] = { value: 1.0 }; |
521 | | - velocityUniforms[ "freedomFactor" ] = { value: 1.0 }; |
522 | | - velocityUniforms[ "predator" ] = { value: new THREE.Vector3() }; |
| 513 | + positionUniforms[ 'time' ] = { value: 0.0 }; |
| 514 | + positionUniforms[ 'delta' ] = { value: 0.0 }; |
| 515 | + velocityUniforms[ 'time' ] = { value: 1.0 }; |
| 516 | + velocityUniforms[ 'delta' ] = { value: 0.0 }; |
| 517 | + velocityUniforms[ 'testing' ] = { value: 1.0 }; |
| 518 | + velocityUniforms[ 'separationDistance' ] = { value: 1.0 }; |
| 519 | + velocityUniforms[ 'alignmentDistance' ] = { value: 1.0 }; |
| 520 | + velocityUniforms[ 'cohesionDistance' ] = { value: 1.0 }; |
| 521 | + velocityUniforms[ 'freedomFactor' ] = { value: 1.0 }; |
| 522 | + velocityUniforms[ 'predator' ] = { value: new THREE.Vector3() }; |
523 | 523 | velocityVariable.material.defines.BOUNDS = BOUNDS.toFixed( 2 ); |
524 | 524 |
|
525 | 525 | velocityVariable.wrapS = THREE.RepeatWrapping; |
|
549 | 549 |
|
550 | 550 | // For Vertex and Fragment |
551 | 551 | birdUniforms = { |
552 | | - "color": { value: new THREE.Color( 0xff2200 ) }, |
553 | | - "texturePosition": { value: null }, |
554 | | - "textureVelocity": { value: null }, |
555 | | - "time": { value: 1.0 }, |
556 | | - "delta": { value: 0.0 } |
| 552 | + 'color': { value: new THREE.Color( 0xff2200 ) }, |
| 553 | + 'texturePosition': { value: null }, |
| 554 | + 'textureVelocity': { value: null }, |
| 555 | + 'time': { value: 1.0 }, |
| 556 | + 'delta': { value: 0.0 } |
557 | 557 | }; |
558 | 558 |
|
559 | 559 | // THREE.ShaderMaterial |
|
652 | 652 | if ( delta > 1 ) delta = 1; // safety cap on large deltas |
653 | 653 | last = now; |
654 | 654 |
|
655 | | - positionUniforms[ "time" ].value = now; |
656 | | - positionUniforms[ "delta" ].value = delta; |
657 | | - velocityUniforms[ "time" ].value = now; |
658 | | - velocityUniforms[ "delta" ].value = delta; |
659 | | - birdUniforms[ "time" ].value = now; |
660 | | - birdUniforms[ "delta" ].value = delta; |
| 655 | + positionUniforms[ 'time' ].value = now; |
| 656 | + positionUniforms[ 'delta' ].value = delta; |
| 657 | + velocityUniforms[ 'time' ].value = now; |
| 658 | + velocityUniforms[ 'delta' ].value = delta; |
| 659 | + birdUniforms[ 'time' ].value = now; |
| 660 | + birdUniforms[ 'delta' ].value = delta; |
661 | 661 |
|
662 | | - velocityUniforms[ "predator" ].value.set( 0.5 * mouseX / windowHalfX, - 0.5 * mouseY / windowHalfY, 0 ); |
| 662 | + velocityUniforms[ 'predator' ].value.set( 0.5 * mouseX / windowHalfX, - 0.5 * mouseY / windowHalfY, 0 ); |
663 | 663 |
|
664 | 664 | mouseX = 10000; |
665 | 665 | mouseY = 10000; |
666 | 666 |
|
667 | 667 | gpuCompute.compute(); |
668 | 668 |
|
669 | | - birdUniforms[ "texturePosition" ].value = gpuCompute.getCurrentRenderTarget( positionVariable ).texture; |
670 | | - birdUniforms[ "textureVelocity" ].value = gpuCompute.getCurrentRenderTarget( velocityVariable ).texture; |
| 669 | + birdUniforms[ 'texturePosition' ].value = gpuCompute.getCurrentRenderTarget( positionVariable ).texture; |
| 670 | + birdUniforms[ 'textureVelocity' ].value = gpuCompute.getCurrentRenderTarget( velocityVariable ).texture; |
671 | 671 |
|
672 | 672 | renderer.render( scene, camera ); |
673 | 673 |
|
|
0 commit comments