8 Replies Latest reply on Dec 9, 2010 8:51 PM by unique_screenname_here

    Converting shaders from other programs?

    laserpilot

      I'm just getting started with Pixel bender, but I've played around with fairly simplified GLSL Shaders in Max/MSP and Quartz Composer before. I'm trying to convert this one shader for use in after effects, but I'm a bit stuck on converting some of the variable types and things like that. I'm also not sure if the effect is even possible to recreate in after effects because it requires a sort of feedback loop when I use it in Max/MSP. The effect basically creates video trails off of bright elements in the scene. Here is the code as it appears for the max/msp fragment shader. If anyone has some hints of whether it looks possible, let me know

       

      uniform float slide_up;
      uniform float slide_down;

       

      varying vec2 texcoord0;
      varying vec2 texcoord1;

       

      uniform sampler2DRect tex0;
      uniform sampler2DRect tex1;

       

      void main(void)
      {
          vec4 su, sd, up, down, amount;

       

          // sample inputs at texcoords
          vec4 input0 = texture2DRect(tex0, texcoord0);
          vec4 input1 = texture2DRect(tex1, texcoord1);
         
          // get contribution
          amount.x = input0.x > input1.x ? 1.0 : 0.0;
          amount.y = input0.y > input1.y ? 1.0 : 0.0;
          amount.z = input0.z > input1.z ? 1.0 : 0.0;
          amount.w = input0.w > input1.w ? 1.0 : 0.0;
         
          // calculate slide down
          float d = max(1.0, abs(slide_down));
          sd = vec4(1.0 / d);
          down = input1 + ((input0 - input1) * sd);

       

          // calculate slide up
          float u = max(1.0, abs(slide_up));
          su = vec4(1.0 / u);
          up = input1 + ((input0 - input1) * su);

       

          // mix between down and up
          gl_FragColor = mix(down, up, amount);
      }

        • 1. Re: Converting shaders from other programs?
          laserpilot Level 1

          Actually I managed to convert the right areas, but now I gues my question is more about setting up a feedback loop in after effects so that the effect can accumulate. Is this a possibility or should I be doing it another way? This is the code that I ended up with:

           

          {
              input image4 src;
              input image4 feedback;
              output pixel4 dst;
              parameter float slide_up;
              parameter float slide_down;

           

              void
              evaluatePixel()
              {
                  float4 su, sd, amount, up, down;

           

              // sample inputs at texcoords
              float4 input0 = sampleNearest(src, outCoord());
              float4 input1 = sampleNearest(feedback, outCoord());
             
              // get contribution
              amount.x = input0.x > input1.x ? 1.0 : 0.0;
              amount.y = input0.y > input1.y ? 1.0 : 0.0;
              amount.z = input0.z > input1.z ? 1.0 : 0.0;
              amount.w = input0.w > input1.w ? 1.0 : 0.0;
             
              // calculate slide down
              float d = max(1.0, abs(slide_down));
              sd = float4(1.0 / d);
              down = input1 + ((input0 - input1) * sd);

           

              // calculate slide up
              float u = max(1.0, abs(slide_up));
              su = float4(1.0 / u);
              up = input1 + ((input0 - input1) * su);

           

              // mix between down and up
                  dst = mix(down, up, amount);
              }
          }

          • 2. Re: Converting shaders from other programs?
            unique_screenname_here Level 3

            I'm not sure I understand. Do you need to accumulate the result across frames?

            • 3. Re: Converting shaders from other programs?
              laserpilot Level 1

              Yes, that's a bit how it works. Here is an example: http://vimeo.com/8360810 and http://www.youtube.com/watch?v=enaEdyw5J24&feature=player_detailpage#t=209s ..the sort of trails that come off of the floating pieces (those are real, not generated particles)

               

              I know I could do it with particles/motion masks/thresholding, but this seems like a simple enough way, or it usually is in Jitter

              • 4. Re: Converting shaders from other programs?
                unique_screenname_here Level 3

                Do you have a quartz composer project that does what you want? Would you send it to me?

                • 5. Re: Converting shaders from other programs?
                  laserpilot Level 1

                  I tried a while ago to get the shader to work fully in quartz because I couldn't figure out how to properly do a feedback loop with the GLSL object. I tried putting it in a render in image, but that didn't quite work.

                   

                  I guess my question is how to do a sort of running average of frames, but with a sort of luminance theshold and the ability to control how much feedback there is/how long the trails are. She pbk works in AE but I guess without a way to give it the proper frames, it might not work correctly.

                   

                  Maybe one idea is to give it the first video, then give it a second comp source with the frames offset by one from the original or something...no..that doesn't seem right, but just an idea

                  • 6. Re: Converting shaders from other programs?
                    laserpilot Level 1

                    Ah...I guess "Echo" is pretty close to what I'm thinking actually...maybe there is a way to adapt something like that? Probably not a way to open that in the pixel bender language though...

                    • 7. Re: Converting shaders from other programs?
                      unique_screenname_here Level 3

                      There's no way (at least that I'm aware of) to do what you want currently in Pixel Bender, if my understanding of your request is correct. We don't provide a way to do recursion or loops within graphs nor do we provide a way to persist data across frames short of storing the data out as part of an image and then sampling the data again in another invocation of the filter. You can fake recursion of a limited depth via graphs. I believe I posted on that sometime back so look through the recent posts if you're interested. It's also possible that there is a way to use other After Effects functionality in combination with Pixel Bender to achieve the desired result. You might ask out on the AE forums to see if you get any suggestions there. I apologize if I've misunderstood your request entirely.

                       

                      Where can I find "echo?" It doesn't appear to be part of the Quartz Composer patch library.

                      • 8. Re: Converting shaders from other programs?
                        unique_screenname_here Level 3

                        BTW, you certainly can convert many GLSL filters, including those intended for use within Quartz Composer, to Pixel Bender. I've converted a number of them for private use so don't give up on this possibility when it comes to other filters.