1 Reply Latest reply on Feb 24, 2012 2:43 PM by PS::Chuck

    Some Pixel Blender Kernel help?

    rlt_games

      Hi Im just trying to learn pixel blender and attempting something relatively simple or so I would think it would be.

       

      I have attempted to find tutorials or other peoples kernels / shaders online to try and help me with this problem but still cant work out how to do it, if I am posting in the wrong place could someone also direct me to a good forum or site for the answer to my question.

       

      So I am attempting to create a kernel in which the first thing it does is take one image and repeat a portion of it, eg tile it, but the code ive built and I have been playing with it for hours, I still can't seem to get a repeating / tiling image, it just stretches before and after the image.

       

      Any help would be appreciated, ive included the source, there is some other stuff in their but if you just ignore the extra bits, the main stuff im trying to work on is in and around the for loops.

       

      Below is the kernel code:

       

       

      /*

      */

      <languageVersion : 1.0;>

       

      kernel Crossfade

      <   namespace : "RT";

          vendor : "Rhys Thomas";

          version : 1;

          description : "Scale sampler"; >

      {

         parameter float intensity

         < minValue: 0.0;

           maxValue: 1.0;

           defaultValue: 0.0;

         >;

        

         parameter float scale

         < minValue: 0.0;

           maxValue: 2.0;

           defaultValue: 1.0;

         >;

        

         parameter int repeats

         < minValue: 0;

           maxValue: 100;

           defaultValue: 100;

         >;

        

         parameter int spacing

         < minValue: 0;

           maxValue: 1024;

           defaultValue: 128;

         >;

       

         input image4 frontImage;

         input image4 backImage;

         output pixel4 dst;

        

         void evaluatePixel()

         {

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

              float4 frontPixel = sampleLinear(frontImage, outCoord());

              float2 type1 = float2(scale, scale);

              float4 backPixel = sampleLinear(backImage, (outCoord() / type1));

             

              // We set the output to the mix of the two pixels.  The mix function

              // applies the following equation to the pixel values:

              //    (1.0 - intensity) * frontPixel + intensity * backPixel

              /**/

              float i;

              float j;

              float4 pluckImage;

              float2 coOd;

              coOd = outCoord();

              for(j = float(0); j < float(2); j++)

              {

                  for(i = float(0); i < float(6); i++)

                  {

                      coOd.x = coOd.x - float(j*float(repeats));

                      //float2 pluckOffset = float2(float(i*float(spacing)),float(i*float(spacing)));

                      //float2 pluckOffset2 = float2(float(j*float(128)),float(j*float(128)));

                      pluckImage = sampleLinear(frontImage,clamp((coOd),float2(1,1),float2(256,256)));

                     

                  }

              }

              dst = mix(pluckImage, backPixel, intensity);

         }

      }

        • 1. Re: Some Pixel Blender Kernel help?
          PS::Chuck Adobe Employee

          Hi,

           

          You've got a number of things going on in your kernel, so I'm going to try and sidestep it a bit.  In PixelBender, when you do a sample{Linear/Nearest} call that is "off" the image, the value that is returned is transparent black.  If you're coding directly to OpenGL, you can set the texture mode to repeat the edge pixel, or tile the texture, or return transparent black.  For most image processing (as opposed to decaling on a 3D model), transparent black is the right choice and it's the one we (and our clients within Adobe) use.

           

          So if you're going to do something like what you want, you need to hand in either how big the image is or some other way of knowing to repeat the image.  Here's a small example kernel that displays the pixels up to the edge of a square box and then repeats them.  You could add things to shift the box, zoom over the whole image within the box, etc., but I hope this points you towards how you might do something like the kernel below. 

           

          I hope this helps,

          Chuck.

           

          <languageVersion : 1.0;>

           

          // this kernel is assuming an image which is located with in the canonical location on the plane with (0,0) being the lowest coordinate value

          // If you truly write kernels that need to know where they live on the plane, you must hand the location in as parameters to the kernel as

          // there is no way to get that information from within a PixelBender kernel.

           

          kernel BugEye

          <   namespace : "CFR";

              vendor : "Chuck Rose";

              version : 1;

              description : "An example of a bug eye's view of a picture"; >

          {

             input image4 frontImage;

             output pixel4 dst;

            

             parameter float repeatEdge <minValue: 1.0; maxValue:1000.0; defaultValue:50.0;>;

            

              void evaluatePixel()

              {

                  float2 p = outCoord(); 

                 

                  // did we go past the repeat edge?  If so, let's bring the number down so that it's in the window we want to repeat

           

           

                  float2 howFarOver = floor(p / repeatEdge);

           

           

                  p -= howFarOver * repeatEdge;

                 

                  p = max(float2(0.5, 0.5), p); // make sure we're at least on the first pixel

                     

                  dst = sampleLinear(frontImage, p);               

              }

          }