提交 a2258a2b 编写于 作者: M michael

Updated gpgpu birds example to work with new BufferAttribute changes.

上级 5564fdee
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<a href="http://threejs.org" target="_blank">three.js</a> - <span id="birds"></span> webgl gpgpu birds<br/> <a href="http://threejs.org" target="_blank">three.js</a> - <span id="birds"></span> webgl gpgpu birds<br/>
Select <span id="options"></span> birds<br/> Select <span id="options"></span> birds<br/>
Move mouse to disturb birds. Move mouse to disturb birds.
</div> </div>
<script src="../build/three.min.js"></script> <script src="../build/three.min.js"></script>
...@@ -122,7 +122,7 @@ ...@@ -122,7 +122,7 @@
uniform float delta; // about 0.016 uniform float delta; // about 0.016
uniform float seperationDistance; // 20 uniform float seperationDistance; // 20
uniform float alignmentDistance; // 40 uniform float alignmentDistance; // 40
uniform float cohesionDistance; // uniform float cohesionDistance; //
uniform float freedomFactor; uniform float freedomFactor;
uniform vec3 predator; uniform vec3 predator;
...@@ -189,7 +189,7 @@ ...@@ -189,7 +189,7 @@
float preyRadius = 150.0; float preyRadius = 150.0;
float preyRadiusSq = preyRadius * preyRadius; float preyRadiusSq = preyRadius * preyRadius;
// move birds away from predator // move birds away from predator
if (dist < preyRadius) { if (dist < preyRadius) {
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
float adjustedPercent = ( percent - separationThresh ) / threshDelta; float adjustedPercent = ( percent - separationThresh ) / threshDelta;
birdVelocity = texture2D( textureVelocity, vec2(x/resolution.x, y/resolution.y) ).xyz; birdVelocity = texture2D( textureVelocity, vec2(x/resolution.x, y/resolution.y) ).xyz;
f = ( 0.5 - cos( adjustedPercent * PI_2 ) * 0.5 + 0.5 ) * delta; f = ( 0.5 - cos( adjustedPercent * PI_2 ) * 0.5 + 0.5 ) * delta;
velocity += normalize(birdVelocity) * f; velocity += normalize(birdVelocity) * f;
...@@ -262,7 +262,7 @@ ...@@ -262,7 +262,7 @@
} }
// this make tends to fly around than down or up // this make tends to fly around than down or up
// if (velocity.y > 0.) velocity.y *= (1. - 0.2 * delta); // if (velocity.y > 0.) velocity.y *= (1. - 0.2 * delta);
...@@ -284,7 +284,7 @@ ...@@ -284,7 +284,7 @@
attribute float birdVertex; attribute float birdVertex;
attribute vec3 birdColor; attribute vec3 birdColor;
uniform sampler2D texturePosition; uniform sampler2D texturePosition;
uniform sampler2D textureVelocity; uniform sampler2D textureVelocity;
...@@ -313,7 +313,7 @@ ...@@ -313,7 +313,7 @@
float xz = length( velocity.xz ); float xz = length( velocity.xz );
float xyz = 1.; float xyz = 1.;
float x = sqrt( 1. - velocity.y * velocity.y ); float x = sqrt( 1. - velocity.y * velocity.y );
float cosry = velocity.x / xz; float cosry = velocity.x / xz;
float sinry = velocity.z / xz; float sinry = velocity.z / xz;
...@@ -337,7 +337,7 @@ ...@@ -337,7 +337,7 @@
newPosition += pos; newPosition += pos;
z = newPosition.z; z = newPosition.z;
vColor = vec4( birdColor, 1.0 ); vColor = vec4( birdColor, 1.0 );
gl_Position = projectionMatrix * viewMatrix * vec4( newPosition, 1.0 ); gl_Position = projectionMatrix * viewMatrix * vec4( newPosition, 1.0 );
} }
...@@ -370,7 +370,7 @@ ...@@ -370,7 +370,7 @@
if (hash) hash = parseInt(hash, 0); if (hash) hash = parseInt(hash, 0);
/* TEXTURE WIDTH FOR SIMULATION */ /* TEXTURE WIDTH FOR SIMULATION */
var WIDTH = hash || 32; var WIDTH = hash || 32;
var BIRDS = WIDTH * WIDTH; var BIRDS = WIDTH * WIDTH;
...@@ -382,10 +382,10 @@ ...@@ -382,10 +382,10 @@
THREE.BufferGeometry.call( this ); THREE.BufferGeometry.call( this );
var vertices = new THREE.Float32Attribute( points * 3, 3 ); var vertices = new THREE.BufferAttribute( new Float32Array( points * 3 ), 3 );
var birdColors = new THREE.Float32Attribute( points * 3, 3 ); var birdColors = new THREE.BufferAttribute( new Float32Array( points * 3 ), 3 );
var references = new THREE.Float32Attribute( points * 2, 2 ); var references = new THREE.BufferAttribute( new Float32Array( points * 2 ), 2 );
var birdVertex = new THREE.Float32Attribute( points, 1 ); var birdVertex = new THREE.BufferAttribute( new Float32Array( points ), 1 );
this.addAttribute( 'position', vertices ); this.addAttribute( 'position', vertices );
this.addAttribute( 'birdColor', birdColors ); this.addAttribute( 'birdColor', birdColors );
...@@ -465,7 +465,7 @@ ...@@ -465,7 +465,7 @@
var windowHalfX = window.innerWidth / 2; var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2; var windowHalfY = window.innerHeight / 2;
var PARTICLES = WIDTH * WIDTH; var PARTICLES = WIDTH * WIDTH;
var BOUNDS = 800, BOUNDS_HALF = BOUNDS / 2; var BOUNDS = 800, BOUNDS_HALF = BOUNDS / 2;
...@@ -555,7 +555,7 @@ ...@@ -555,7 +555,7 @@
gui.close(); gui.close();
initBirds(); initBirds();
} }
...@@ -594,7 +594,7 @@ ...@@ -594,7 +594,7 @@
}); });
// var // var
birdMesh = new THREE.Mesh( geometry, shaderMaterial ); birdMesh = new THREE.Mesh( geometry, shaderMaterial );
birdMesh.rotation.y = Math.PI / 2; birdMesh.rotation.y = Math.PI / 2;
birdMesh.matrixAutoUpdate = false; birdMesh.matrixAutoUpdate = false;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册