Browse Source

Examples: Make GPGPU Birds texture fetches more accurate

Joshua Koo 10 years ago
parent
commit
a742c6e012
1 changed files with 3 additions and 3 deletions
  1. 3 3
      examples/webgl_gpgpu_birds.html

+ 3 - 3
examples/webgl_gpgpu_birds.html

@@ -214,8 +214,8 @@
 				for (float y=0.0;y<height;y++) {
 				for (float y=0.0;y<height;y++) {
 					for (float x=0.0;x<width;x++) {
 					for (float x=0.0;x<width;x++) {
 
 
-						birdPosition = texture2D( texturePosition,
-							vec2( x / resolution.x,  y / resolution.y ) ).xyz;
+						vec2 ref = vec2( x + 0.5, y + 0.5 ) / resolution.xy;
+						birdPosition = texture2D( texturePosition, ref ).xyz;
 
 
 						dir = birdPosition - selfPosition;
 						dir = birdPosition - selfPosition;
 						dist = length(dir);
 						dist = length(dir);
@@ -240,7 +240,7 @@
 							float threshDelta = alignmentThresh - separationThresh;
 							float threshDelta = alignmentThresh - separationThresh;
 							float adjustedPercent = ( percent - separationThresh ) / threshDelta;
 							float adjustedPercent = ( percent - separationThresh ) / threshDelta;
 
 
-							birdVelocity = texture2D( textureVelocity, vec2(x/resolution.x, y/resolution.y) ).xyz;
+							birdVelocity = texture2D( textureVelocity, ref ).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;