|
@@ -207,54 +207,53 @@
|
|
|
vec3 central = vec3( 0., 0., 0. );
|
|
|
dir = selfPosition - central;
|
|
|
dist = length( dir );
|
|
|
+
|
|
|
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++) {
|
|
|
|
|
|
- if (
|
|
|
- x == gl_FragCoord.x && y == gl_FragCoord.y) continue;
|
|
|
-
|
|
|
birdPosition = texture2D( texturePosition,
|
|
|
vec2( x / resolution.x, y / resolution.y ) ).xyz;
|
|
|
|
|
|
dir = birdPosition - selfPosition;
|
|
|
dist = length(dir);
|
|
|
- distSquared = dist * dist;
|
|
|
|
|
|
- if ( dist > 0.0 && distSquared < zoneRadiusSquared ) {
|
|
|
+ if (dist < 0.0001) continue;
|
|
|
+
|
|
|
+ distSquared = dist * dist;
|
|
|
|
|
|
- percent = distSquared / zoneRadiusSquared;
|
|
|
+ if (distSquared > zoneRadiusSquared ) continue;
|
|
|
|
|
|
- if ( percent < separationThresh ) { // low
|
|
|
+ percent = distSquared / zoneRadiusSquared;
|
|
|
|
|
|
- // Separation - Move apart for comfort
|
|
|
- f = (separationThresh / percent - 1.0) * delta;
|
|
|
- velocity -= normalize(dir) * f;
|
|
|
+ if ( percent < separationThresh ) { // low
|
|
|
|
|
|
- } else if ( percent < alignmentThresh ) { // high
|
|
|
+ // Separation - Move apart for comfort
|
|
|
+ f = (separationThresh / percent - 1.0) * delta;
|
|
|
+ velocity -= normalize(dir) * f;
|
|
|
|
|
|
- // Alignment - fly the same direction
|
|
|
- float threshDelta = alignmentThresh - separationThresh;
|
|
|
- float adjustedPercent = ( percent - separationThresh ) / threshDelta;
|
|
|
+ } else if ( percent < alignmentThresh ) { // high
|
|
|
|
|
|
- birdVelocity = texture2D( textureVelocity, vec2(x/resolution.x, y/resolution.y) ).xyz;
|
|
|
+ // Alignment - fly the same direction
|
|
|
+ float threshDelta = alignmentThresh - separationThresh;
|
|
|
+ float adjustedPercent = ( percent - separationThresh ) / threshDelta;
|
|
|
|
|
|
- f = ( 0.5 - cos( adjustedPercent * PI_2 ) * 0.5 + 0.5 ) * delta;
|
|
|
- velocity += normalize(birdVelocity) * f;
|
|
|
+ birdVelocity = texture2D( textureVelocity, vec2(x/resolution.x, y/resolution.y) ).xyz;
|
|
|
|
|
|
- } else {
|
|
|
+ f = ( 0.5 - cos( adjustedPercent * PI_2 ) * 0.5 + 0.5 ) * delta;
|
|
|
+ velocity += normalize(birdVelocity) * f;
|
|
|
|
|
|
- // Attraction / Cohesion - move closer
|
|
|
- float threshDelta = 1.0 - alignmentThresh;
|
|
|
- float adjustedPercent = ( percent - alignmentThresh ) / threshDelta;
|
|
|
+ } else {
|
|
|
|
|
|
- f = ( 0.5 - ( cos( adjustedPercent * PI_2 ) * -0.5 + 0.5 ) ) * delta;
|
|
|
+ // Attraction / Cohesion - move closer
|
|
|
+ float threshDelta = 1.0 - alignmentThresh;
|
|
|
+ float adjustedPercent = ( percent - alignmentThresh ) / threshDelta;
|
|
|
|
|
|
- velocity += normalize(dir) * f;
|
|
|
+ f = ( 0.5 - ( cos( adjustedPercent * PI_2 ) * -0.5 + 0.5 ) ) * delta;
|
|
|
|
|
|
- }
|
|
|
+ velocity += normalize(dir) * f;
|
|
|
|
|
|
}
|
|
|
|