Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions examples/webgl_gpgpu_birds.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@

const float SPEED_LIMIT = 9.0;

float rand(vec2 co){
return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
float rand( vec2 co ){
return fract( sin( dot( co.xy, vec2(12.9898,78.233) ) ) * 43758.5453 );
}

void main() {
Expand Down Expand Up @@ -150,7 +150,7 @@


// move birds away from predator
if (dist < preyRadius) {
if ( dist < preyRadius ) {

f = ( distSquared / preyRadiusSq - 1.0 ) * delta * 100.;
velocity += normalize( dir ) * f;
Expand All @@ -170,28 +170,28 @@
dir.y *= 2.5;
velocity -= normalize( dir ) * delta * 5.;

for (float y=0.0;y<height;y++) {
for (float x=0.0;x<width;x++) {
for ( float y = 0.0; y < height; y++ ) {
for ( float x = 0.0; x < width; x++ ) {

vec2 ref = vec2( x + 0.5, y + 0.5 ) / resolution.xy;
birdPosition = texture2D( texturePosition, ref ).xyz;

dir = birdPosition - selfPosition;
dist = length(dir);
dist = length( dir );

if (dist < 0.0001) continue;
if ( dist < 0.0001 ) continue;

distSquared = dist * dist;

if (distSquared > zoneRadiusSquared ) continue;
if ( distSquared > zoneRadiusSquared ) continue;

percent = distSquared / zoneRadiusSquared;

if ( percent < separationThresh ) { // low

// Separation - Move apart for comfort
f = (separationThresh / percent - 1.0) * delta;
velocity -= normalize(dir) * f;
f = ( separationThresh / percent - 1.0 ) * delta;
velocity -= normalize( dir ) * f;

} else if ( percent < alignmentThresh ) { // high

Expand All @@ -202,7 +202,7 @@
birdVelocity = texture2D( textureVelocity, ref ).xyz;

f = ( 0.5 - cos( adjustedPercent * PI_2 ) * 0.5 + 0.5 ) * delta;
velocity += normalize(birdVelocity) * f;
velocity += normalize( birdVelocity ) * f;

} else {

Expand All @@ -212,7 +212,7 @@

f = ( 0.5 - ( cos( adjustedPercent * PI_2 ) * -0.5 + 0.5 ) ) * delta;

velocity += normalize(dir) * f;
velocity += normalize( dir ) * f;

}

Expand Down