9 Replies Latest reply on Jan 27, 2010 4:04 PM by tschmimo

    && doesn't work correctly?!?

    tschmimo

      Hi, I started using Pixel Bender just the day before yesterday, so excuse me, if I ask a question, that's already answered - I didn't find an answer.

       

      For a filter kernel I needed to find white pixel. Can anybody tell me, why does

       

      dst = sampleNearest(src,outCoord());
      if (dst.r == 1.0)
      if (dst.g == 1.0)
      if (dst.b == 1.0) { ... }

       

      execute as expected, but

       

      dst = sampleNearest(src,outCoord());

      if ((dst.r == 1.0) && (dst.g == 1.0) && (dst.b == 1.0)) { ... }

       

      doesn't?

       

      thank you

        • 1. Re: && doesn't work correctly?!?
          unique_screenname_here Level 3

          This is likely a result of floating point equality comparisons--you should avoid them. There are numerous threads (http://forums.adobe.com/thread/497374?tstart=0 for example) dealing with that topic so take a look back through the forum history and you'll get a more complete answer. That said, I'm not exactly sure why the equality comparisons succeed in one case but not another. I'll look into it, but the real fix at this point is avoid floating point equality comparisons.

          1 person found this helpful
          • 2. Re: && doesn't work correctly?!?
            tschmimo Level 1

            sorry, but it doesn't seem to be an error in floatingpoint calculation.

             

            if ((dst.r > 0.999999) && (dst.g < 0.000001) && (dst.b < 0.000001)) { ... }

             

            doesn't evaluate, while

             

            if (dst.r > 0.999999)
            if (dst.g < 0.000001)
            if (dst.b < 0.000001) { ... }

             

            does.

            • 3. Re: && doesn't work correctly?!?
              tschmimo Level 1

              interesting enough, following the exampels, i tried

               

              float3 a = float3(1.0,1.0,1.0);

              dst = sampleNearest(src,outCoord());

              if (all(equal(a, dst.rgb))) { ... }

               

              and if i missunderstood

               

              float3 a = float3(1.0,1.0,1.0);

              float3 b;

              dst = sampleNearest(src,outCoord());

              b = float3(dst.r, dst.g, dst.b));

              if (all(equal(a, b))) { ... }

               

              neither codesnippet  found the white pixels.

               

              Could it be an issue belonging to my version (1.51, build 02)?

              • 4. Re: && doesn't work correctly?!?
                AIF Bob Level 3

                I'm trying to reproduce this, and failing to do so. Can you post the full kernel that you're testing and also tell me whether you're running it in the toolkit or in Flash. If you're running in the toolkit are you running on GPU or CPU, and if you're on GPU, what GPU do you have and have you got the latest drivers for it?

                 

                Also, if you're running in the toolkit make sure you have the latest version of the toolkit.

                • 5. Re: && doesn't work correctly?!?
                  tschmimo Level 1

                  hi bob,

                  i'm testing in the toolkit and as mentioned above it is V1.51 build 02. I didn't change any options, so I expect it's gpu . The snipets from above are all from diverse testings because the evaluation of my statements didn't have the expected results. And if I need to install extra drivers for gpu, or even a gpu, that may be the reason, because I haven't.

                   

                   

                  I haven't postet my complete code because I did't think it relevant, but here it is:

                   

                  <languageVersion : 1.0;>

                  kernel DeMaskRed
                  <   namespace : "flash";
                      vendor : "tschmimo@web.de";
                      version : 1;
                      description : "red pixel (#ff0000) invert their alpha, all else become green with alpha 1.0";
                  >
                  {
                      input image4 src;
                      output pixel4 dst;

                      void
                      evaluatePixel()
                      {
                          dst = sampleNearest(src,outCoord());
                          if (dst.r == 1.0) {
                              if (dst.b == 0.0) {
                                  if (dst.g == 0.0) {
                                      dst.a = 1.0 - dst.a;
                                  } else {
                                      dst.a = 1.0;
                                      dst.r = dst.b = 0.0;
                                      dst.g = 1.0;
                                  }
                              } else {
                                  dst.a = 1.0;
                                  dst.r = dst.b = 0.0;
                                  dst.g = 1.0;
                              }
                          }
                      }
                  }

                   

                  As you can see, not using && forces me to use nested if-then-else, and if I read the other posts, that would result in not running in flash.

                  Sorry for not using the attach files option, but i couldn't find the file on the filesystem. I really hate Vista's virtual filesystem.

                  • 6. Re: && doesn't work correctly?!?
                    unique_screenname_here Level 3

                    Sorry to be a stickler, but would you please post the kernel exactly as you would like it to be written/work. Would you also please post the actual result and the expected result received when running that kernel on the GPU. In the meantime, I've attached a kernel that I believe produces the result you are expecting. Please give it a try and let us know whether it matches your expected behavior. Thanks.

                    • 7. Re: && doesn't work correctly?!?
                      tschmimo Level 1

                      yes, but for setting dst before the question and the parameter that's my code too. What it does is setting the whole picture to green with alpha 1.

                       

                      regards Thomas

                      • 8. Re: && doesn't work correctly?!?
                        AIF Bob Level 3

                        I'm still failing to reproduce the problem you're seeing.

                         

                        Using your kernel that does not give the results you expect, switch the toolkit into CPU mode and see if the results are better. Let me know the result of that experiment.

                         

                        Please post the kernel that is failing for you. Please post the full kernel. Tell me what you expect to see and what you actually see (please tell me this even if it's obvious to you - sometimes it isn't always obvious to us what should be happening).

                         

                        Tell me whether you're running on Mac or Windows.

                         

                        Tell me what GPU you're using.

                         

                        If you're on Windows, download and install the latest drivers for your GPU (go to www.nvidia.com or www.ati.com as appropriate and look in their support sections). Try running the toolkit again in GPU mode.

                        • 9. Re: && doesn't work correctly?!?
                          tschmimo Level 1

                          Thank you,

                          my driver worked in cpu-mode and with the latest drivers (from yesterday) gpu-mode worked too.

                           

                          Thanks to all of you for your time and help!

                           

                           

                          Just to complete the infos: I use Windows Vista Premium, and have an ATI Radeon HD 3850 graficcard.

                          My issue was, that while the condition without && evaluated correctly, the condition with && resulted every time in false.

                          The last version of my kernel:

                           

                           

                          <languageVersion : 1.0;>

                          kernel DeMaskRed
                          <   namespace : "flash";
                              vendor : "";

                              version : 1;
                              description : "red pixel (#ff0000) invert their alpha, all else become green with alpha 1.0";
                          >
                          {
                              input image4 src;
                              output pixel4 dst;

                              void
                              evaluatePixel()
                              {
                                  bool isRed = true;
                                  float epsilon = 0.1;
                                  dst = sampleNearest(src,outCoord());
                                  /*
                                  // condition without &&
                                  if (dst.r < 1.0 - epsilon) isRed = false;
                                  if (dst.g > epsilon) isRed = false;
                                  if (dst.b > epsilon) isRed = false;
                                  */
                                  // condition with &&
                                  isRed = (dst.r >= 1.0 - epsilon) && (dst.g <= epsilon) && (dst.b <= epsilon);
                                  if (isRed) {
                                      dst.a = 1.0 - dst.a;
                                  } else {
                                      dst.a = 1.0;
                                      dst.r = dst.b = 0.0;
                                      dst.g = 1.0;
                                  }
                              }
                          }