0 Replies Latest reply on Nov 22, 2009 8:08 AM by Ed Ryzhov

    strange behavior of "distance" for two floats

    Ed Ryzhov

      I have shader (here short test version):

       

       

          input image3 dir;
          input image3 shd;
          output pixel3 dst;

       

          parameter float2 offset
          <
              defaultValue:float2(0.0, 0.0);
          >;
         
          parameter float3 mult
          <
              defaultValue:float3(256.0, 256.0, 256.0);
          >;
         
         
          void evaluatePixel()
          {
              float2 oc = outCoord()+offset;
              float3 dirPx = sampleNearest(dir, oc)*mult;

       

      // dirPx.g -> oc.x
              float2 shdOc = float2(dirPx.r, 1056.0-oc.x-dirPx.b);
              float3 shdPx = sampleNearest(shd, shdOc)*mult;

       

              dst.gb = float2(0.5, 0.5);
      //        if(abs(shdPx.g-oc.x)<0.5)
              if(distance(shdPx.g, oc.x) < 0.5)
              {
                  dst.r = 1.0;
              }
              else
              {
                  dst.r = 0.0;
              }

       

          }

       

       

      Line:

      if(distance(shdPx.g, oc.x) < 0.5)

       

      Shows error at runtime:

      ArgumentError: Error #2004: One of the parameters is invalid.
          at flash.display::ShaderData/_setByteCode()
          at flash.display::ShaderData()
          at flash.display::Shader/set byteCode()
          at flash.display::Shader()

       

      I replace "distance" with "abs()", but why "distance" not works correctly?