1 Reply Latest reply on Jul 23, 2010 11:18 AM by AIF Bob

    multiple calls to sampleNearest?


      Hello there,


      I'm new to Pixel Bender and just trying to write sort of a smart blur filter. First it creates a mask by running a soble edge detection algorithm setting edge pixels to black and other pixels to white. Second step is to gaussian blur every pixel of the original image that is marked white in the mask. Every black mask pixel is copied from the source image.


      The sobel edge detection is done by a convolution filter routine. You can see the whole Pixel Bender source code here: http://pastebin.com/iXrcNikN It's not optimized yet nor any kind well thought out.


      Now, my problem is that it works only as long as I leave the first line of the evaluatePixel function commented. A simple call to sampleNearest in the evaluatePixel function and the filter stops working (no edge detection anymore, just all black or white pixel, depending on Factor and Bias setting). Can anybody tell me why?


      Thanks a lot!




      //edit: I have to add to this that the filter also stops working when I create a function that contains the call to sampleNearest. A function that isn't called at all! What's that?


      Message was edited by: SeveQ - I've added further information.

        • 1. Re: multiple calls to sampleNearest?
          AIF Bob Level 3

          I think there might be a couple of things going on here, and we have to sort out the first one before we get onto the

          second. I ran this through the toolkit in GPU and in CPU mode. I got different results in the two modes. That usually indicates that we have some undefined operation that is treated differently by the CPU and the GPU. In this particular filter the undefined operation is a divide by zero that's happening here:


          conv_result /= float4(divisor);


          The reason we're getting zero in the divisor is because we're calling convolve with this matrix:


          1.0, 2.0, 1.0,
          0.0, 0.0, 0.0,
          -1.0, -2.0, -1.0



          in one place and this matrix:


          -1.0, 0.0, 1.0,
          -2.0, 0.0, 2.0,
          -1.0, 0.0, 1.0


          in another.


          Since divisor is just the sum of the elements in the matrices it'll be zero when these matrices are used.