2 Replies Latest reply on Aug 17, 2009 6:49 PM by Rinick

    sampleNearest return wrong value when width*height > 4000 ?

    Rinick

      Hi,

      I implemented the Conway's Game of Life with Pixel Blender and ran it on flashplayer10.

      It's a simple iteration of shaderFilter at each frame.

       

      The result is perfect when board size <= 80*50

       

      However, I get wrong result for any width* height > 4000.

       

      Please check the attached swf files, the left side and the right side should always be identical because the initial states are identical.

       

       

      the shader
          const float4 k0 = float4(0.0, 0.0, 0.0, 1.0);
          const float4 k1 = float4(0.0, 1.0, 0.0, 1.0);
          input image4 src;
          output pixel4 dst;


          void evaluatePixel() {
              float2 pos = outCoord();
              float4 me = sampleNearest(src, pos);
              float4 sum = sampleNearest(src,pos+float2( 1.0, 1.0))
                         + sampleNearest(src,pos+float2( 1.0,-1.0))
                         + sampleNearest(src,pos+float2( 1.0, 0.0))
                         + sampleNearest(src,pos+float2( 0.0, 1.0))
                         + sampleNearest(src,pos+float2( 0.0,-1.0))
                         + sampleNearest(src,pos+float2(-1.0, 1.0))
                         + sampleNearest(src,pos+float2(-1.0,-1.0))
                         + sampleNearest(src,pos+float2(-1.0, 0.0));
              if (me.g == 1.0) {
                  if (sum.g > 3.0 || sum.g < 2.0) {
                      dst = k0;
                  } else {
                      dst = k1;
                  }
              }
              else
              {
                  if (sum.g == 3.0 ) {
                      dst = k1;
                  } else {
                      dst = k0;
                  }
              }
          }

         

      the flash
          public class Main extends Sprite
          {
              [Embed(source="life.pbj", mimeType="application/octet-stream")]
              protected var lifeCore:Class;
              protected var lifeCoreShader:Shader;
              protected var lifeCoreFilter:ShaderFilter;
             
              public const w:int = 80;
              public const h:int = 50;

              public var bmp1:BitmapData;
              public var image1:Bitmap;
              public var bmp2:BitmapData;
              public var image2:Bitmap;
              public function Main():void
              {   
                  addEventListener(Event.ENTER_FRAME, round);

                  lifeCoreShader = new Shader(new lifeCore() as ByteArray);
                  lifeCoreFilter = new ShaderFilter(lifeCoreShader);
                 
                  bmp1 = new BitmapData(w , h , true, 0xFF000000);
                  bmp2 = new BitmapData(w , h , true, 0xFF000000);
                 
                  for (var i:int = 1; i < 80; ++i)
                  for (var j:int = 1; j < 80; ++j)
                  {
                      if (Math.pow(i,j)%10 > 4) { // pseudo random initial state
                          bmp1.setPixel32(i, j, 0xFF00FF00);
                          bmp2.setPixel32(i, j, 0xFF00FF00);
                      }   
                  }   
                  image1 = new Bitmap(bmp1);    image2 = new Bitmap(bmp2);
                  image1.scaleX = 3;                   image2.scaleX = 3;
                  image1.scaleY = 3;                   image2.scaleY = 3;
                  addChild(image1);                     addChild(image2);
                 
                  image2.x = 320;
              }
             
              private function round(e:Event):void
              {
                  bmp1.applyFilter(bmp1, new Rectangle(0, 0, w, h), new Point(), lifeCoreFilter);
                  bmp2.applyFilter(bmp2, new Rectangle(0, 0, w, h), new Point(), lifeCoreFilter);
              }
          }