3 Replies Latest reply on Apr 18, 2009 12:07 PM by AIF Bob

    Pixel sampling aliasing

      I've run into a problem when scaling an image's pixel coordinates. I'm using 1 image as texture coordinates for another. The problem i'm running into is that there is some serious aliasing going on when i scale the texture down. Here's an image of what I'm ending up with, Image A is distorted using image B's coordinates and C is the result yucky pixels I figure it has to do with the way i'm sampling the final image that has it's coordinates distorted, is there any way i could super sample this or anti-alias it? or am I just screwed? :) I've attached my code....I tried sample, sampleLinear, and sampleNearest and they all look pretty bad, just varying levels of bad...
        • 1. Re: Pixel sampling aliasing
          AIF Bob Level 3

          I'm sorry to have to ask you for your code again, but it looks as though it got lost when they changed the forum software over the weekend. Could you post the code you were having trouble with and I'll take a look at it.

          • 2. Re: Pixel sampling aliasing
            Level 1

            I'm pretty sure my problem is coming from sampling pixels that are scaled down.  If I was doing this in HLSL it would be using mipmapping and it would look a lot smoother.  What would be an alternative to that in PixelBender?  Here's the code from my program...sorry if this is a really simple question...I'm more of an artist than programmer :\


            <languageVersion : 1.0;>


            kernel DistortTexture

            <   namespace : "DistortTexture";

                vendor : "JordanWalker";

                version : 2;

                description : "Distort a texture with UV coordinates";



                //R channel is U coordinates, G is V coordinates and B is the image to be distorted

                input image4 frontImage;

                output pixel4 dst;


                parameter float imageSize


                    minValue: float(0);

                    maxValue: float(4096);

                    defaultValue: float(512);


                parameter float tiling


                    minValue: float(0);

                    maxValue: float(20);

                    defaultValue: float(1);






                    // Acquire the pixel values from both images at the current location

                    float4 coordPixel = sampleNearest(frontImage, outCoord());

                    //Create image coordinates from the 2nd input image

                    float2 imageCoord = float2(coordPixel.r, coordPixel.g);

                    //Tile the coordinates and the run frac on it to get them back into 0-1

                    imageCoord = imageCoord * tiling;

                    imageCoord = fract(imageCoord);

                    imageCoord = imageCoord * float2(imageSize, imageSize);

                    //distorted image is stored in the B channel of the image

                    float4 distortedTexture = sampleNearest(frontImage, imageCoord);

                    distortedTexture = float4(distortedTexture.b, distortedTexture.b, distortedTexture.b, float(1));


                    //Render the image

                    dst = distortedTexture;



            • 3. Re: Pixel sampling aliasing
              AIF Bob Level 3

              You're righ - the problem is the lack of mipmapping. Each pixel in your output covers a number of pixels in your input the exact mnumber depends on the value of the tiling parameter. When you use sampleNearest, you are just getting the value from a single pixel in the input. If you switch to sampleLinear you are getting linear interpolation but only over 4 pixels of the input - depending on how much you are scaling you need to interpolate over more than 4 input pixels.


              There is no automatic way to do this in PB. You can, however, write your own interpolation function in PB in order to do whatever sample interpolation you need to.