1 Reply Latest reply on Apr 1, 2009 9:14 AM by AIF Bob

    By Reference or By Value

    maltaannon Level 1
      I'm working on a PixelBender filter for After Effects. One of the parameters is a AE's Point Controller. Let's call it "Offset". It's default value is 0.5, 0.5 - so that it sits in the center of the layer (like most AE plugins behave at default)

      parameter float2 offset
      <
      aeUIControl: "aePoint";
      aePointRelativeDefaultValue: float2(0.5, 0.5);
      aeDisplayName: "Offset";
      >;

      Lets say I want to use this parameter to offset the image using for example a code that looks like this:

      void evaluatePixel()
      {
      dst = sampleLinear(src, outCoord() + offset * 1000.0); //multiplied by 1000.0 for the sake of testing it in PB Toolkit
      }

      If I run this code in AE (without multiplication) my image will be shifted right after applying the filter. I'd like this to act as a offset to the starting position. Solution seems simple. Since PixelBender retrieves pixel measured values from the Point Controller (so if my layer is 100x100, default Point Controller's value of 0.5, 0.5 will return 50,50 to PixelBender) I only need to save the initial position in pixels of the Offset Point Controller.

      To do that I tried creating a dependent "center" variable that would get evaluated when the filter starts and then subtract it from the Offset. So my code looks like this:

      dependent float2 center;

      void evaluateDependents()
      {
      center = origin;
      }

      void evaluatePixel()
      {
      dst = sampleLinear(src, outCoord() + (offset-center) * 1000.0 );
      }

      Unfortunately this doesn't work. The image doesn't move at all, since each time I change the Offset value the Center value updates as well to the same value.

      It seems like the Center value is assigned "by reference" creating a link between the two values. And now the question: Is there any way to create variables "by value" instead of "by reference"? If so, how? If not, what is the workaround?

      Thanks

        • 1. Re: By Reference or By Value
          AIF Bob Level 3
          First of all, could you post your entire code - the snippets you've posted don't add up to a working program - in particular, you reference a variable called "origin" in evaluateDependents which is never defined anywhere.

          To try and get you an answer quicker I am going to assume that where you wrote "origin" in evaluateDependents you actually meant to write "offset", in which case what you are seeing (no movement) is correct, even though it isn't what you expect.

          Whenever the pixel bender runtime calculates a frame of the output image it starts off by running the evaluateDependents function, and the runtime will calculate a new frame every time you change the offset parameter. This means that every time offset is changed, evaluateDependents gets run and center will be set to the same value as offset. This means that (offset - center) is always going to be zero, hence no movement.

          Saving the initial position of the offset won't work - pixel bender itself has no memory in this respect - every frame is calculated starting from scratch, and every frame reruns evaluateDependents.