[sharing] New Distortions


    Mar 30 2009 | 6:49 pm
    Hello Folks,
    I would like to share with you a couple of little things I've been keeping under my hat until I had time to make them presentable and readable for others. Originally, I had intended to write up a recipe or article about this stuff, but due to my current to-do list I wouldn't get around to it for several months. So I'm just going to put it out there.
    Attached is a collection of shaders and Max patches that implement an optical-flow driven distortion. This allows you to do things like fake compression-artifact effects as well as some really swirly feedback stuff. It's all based around an aproximate implementation of Horn-Shuncke optical flow within a shader (good enough for experimental video) and a special "repos" shader that is optimized for the ab.hsflow output. The idea for these arose from research I was doing for a current video project, and was encouraged by the recent explosion of interest in these sorts of video effects. Please take a moment to play around with these, and be sure to post your own creations and alterations for everyone else.
    Let me know what you think...
    Andrew Benson

    • Mar 31 2009 | 1:05 am
      Your the best andrew! Good work on these!
      I just played around and its crazy, its exactly the same as the first cv.hsflow patch that I made! The only difference being that they are slabs instead of jit objects, and thus they run 640 at 60fps rather then 320 at 30fps.
      Last night I ended up staying up and working on a different approach, I used the cv flow object at a low resolution to distort a mesh with a feedback texture on it, its working out great so far, it can go super high resolution and its very smooth and responsive, and runs at very high frame rate even full screen HD! The most fun aspect of it is that Ive gotten the distortion to be very accurate to the amount of motion, when your using it you really feel like your pushing the goo around with your movements.
      Heres the first test video:
      I hope to add bubbles/metaballs and other fluid characteristics and get a nice abstract fluid simulation going.
      Thanks again andrew!
    • Mar 31 2009 | 7:03 pm
      All I can say is...
    • Mar 31 2009 | 10:37 pm
      In making a tutorial on how to use this in DNA (http://www.lividindustry.com/culture/?p=198), I had to convert the max5 patch to a max 4 patch. Might as well post it!
      Of course, you'll still need Andrew's zip for the shaders.
    • Apr 01 2009 | 1:43 pm
      please post max 4.6 version....
      thanks!
    • Apr 01 2009 | 4:32 pm
      isnt that it right above the message you just posted?
    • Apr 01 2009 | 7:12 pm
      Any trick to getting this going? Should both of the presets in the patch give glitching straight from the start?
      What I'm seeing is something like a posterize, as well as a bit of lower res (ie, squares) following motion. I've tried a ton of different settings, and even tried the same settings shown in the DNA how-to video and nothing gave me the imagery like I'm seeing in people's videos. That said, what I'm seeing looks pretty nice, if quite a bit more normal.
    • Apr 01 2009 | 9:09 pm
      upps... yes sorry.. to fast
      would be nice to have a simple standalone max5 to 4.6 converter (drag&drop)
    • Apr 02 2009 | 10:30 pm
      Andrew, would it be possible to create a motion blur by using your hsflow and a blur based on motion ammount + direction?
    • Apr 03 2009 | 3:27 am
      Axiom-Crux wrote on Thu, 02 April 2009 16:30Andrew, would it be possible to create a motion blur by using your hsflow and a blur based on motion ammount + direction?
      Thats a great idea. Ill see what I can whip up
      edit:
      rough draft of a blur: I played with this last night and while it works, its very picky. You need to do multi-pass to get it to show up, maybe 3 + passes. Keep feeding the same flow output to tex1, but chain tex0 from the output of one of these blurs to the next. It could use some work, it gets trippy fast, and is not *quite* what you would expect.
      ---
      //setup for 2 texture
      varying vec2 texcoord0;
      varying vec2 texcoord1;
      uniform float amt;
      uniform sampler2DRect tex0;
      uniform sampler2DRect tex1;
      void main()
      {
      vec4 blurVector = texture2DRect(tex1,texcoord1); //sample flow texture
      vec2 blurAmount = vec2(blurVector.y-blurVector.x, blurVector.w-blurVector.z);
      /* vec4 blur1 = texture2DRect(tex1, texcoord1 + blurAmount);
      vec2 blurAmount1 = vec2(blur1.y-blur1.x, blur1.w-blur1.z);
      vec4 blur2 = texture2DRect(tex1, texcoord1 + blurAmount * 2.0);
      vec2 blurAmount2 = vec2(blur2.y-blur2.x, blur2.w-blur2.z);
      */
      vec2 amount1 = blurAmount;// + blurAmount1 + blurAmount2;
      amount1 *= amt;
      vec2 amount2,amount3,amount4,amount5,amount6,amount7,amount8;
      amount2 = amount1 *1.5;
      amount3 = amount1 *3.0;
      amount4 = amount1 *6.0;
      amount5 = amount1 * 8.0;
      amount6 = amount1 * 10.0;
      amount7 = amount1 * 12.0;
      amount8 = amount1 * 18.0;
      // sample our textures
      vec4 sample0 = texture2DRect(tex0, texcoord0);
      vec4 sample1 = texture2DRect(tex0, texcoord0 + amount1);
      vec4 sample2 = texture2DRect(tex0, texcoord0 + amount2);
      vec4 sample3 = texture2DRect(tex0, texcoord0 + amount3);
      vec4 sample4 = texture2DRect(tex0, texcoord0 + amount4);
      vec4 sample5 = texture2DRect(tex0, texcoord0 + amount5);
      vec4 sample6 = texture2DRect(tex0, texcoord0 + amount6);
      vec4 sample7 = texture2DRect(tex0, texcoord0 + amount7);
      vec4 sample8 = texture2DRect(tex0, texcoord0 + amount8);
      gl_FragColor = (sample0 + sample1 + sample2 + sample3 + sample4 + sample5 + sample6 + sample7 + sample8) / 9.0;
      }
    • Apr 03 2009 | 5:34 pm
      Thanks to pnyboer for converting a. benson's patch to 4.6. However when I turn it on I get the following errors with every bang: jit.gl.pbuffer: error binding texture: GL Error: Invalid operation and then error: jit.gl.texture: unable to create texture!
      When I run a. benson's patch in Max 5 runtime there are no errors and the patch seems to work just fine so it seems that my gpu should be able to handle this. Any idea what could be causing this? Any idea how I might be able to fix it?
      I'm using a MacBookPro running 10.5.5 with 2.16 Intel Core Duo, 2 Gb ram, the gpu is RadeonX1600 with 256mb of vram.
      Thanks,
      S.
    • Apr 03 2009 | 5:50 pm
      try switching the readback mechanism. paste this snippet into the patch:
      let us know if that works.
    • Apr 03 2009 | 6:54 pm
      Thanks for sending that code. I pasted it into the patch and it seemed to take care of the problem. The strange thing is, just out of curiosity I tried the patch again without your code and didn't get the gl errors this time. crazy! Wish I understood how all this worked better. Can you explain more about what the code that code is and/or maybe where I can find out more information about it someplace else? Thanks again.
      S.
    • Apr 04 2009 | 6:25 pm
      nice one vade, im about to test it out! Is there anything special I need other then the hsflow and your blur? Also, will this work in jitter without the jxs wrapper? (for some reason they dont show up for me in here, just the shader code, I think the forum eats javascript)
      Andrew had recently posted a luma based blur in a post that I am working on a depth of field blur, and if you check out that one, it may be helpful to try and make something between what you have made and what he did in the luma based blur+ flow>repos shaders.
      Im glad to see your back, even if it is just to scoop up some shaders to take over into QC
    • Apr 04 2009 | 6:43 pm
      here is an early version by nesa.
      i lost my ilok dongle (bahh) so i cant see the difference.
    • Apr 04 2009 | 8:08 pm
      rob the rich:
      does it have to be capitol FBO? I tried fbo and it seems to turn off the feedback, and when I do capitol FBO it works again... is there any info in the documentation about this setting?
    • Apr 04 2009 | 9:59 pm
      actually, i believe the "fbo" is correct, but "RTT" should be "rtt". however i think the default mode is "rtt" so when you give a bad argument (like FBO or RTT) it defaults to rtt.
      my apologies for the misinformation.
      these are undocumented messages for now.
    • Apr 05 2009 | 1:16 am
      a couple more tests of my mesh distortion fluid feedback patch, doesn't use the shaders that andrew made, just the cv.jit.hsflow
      i put a small camera feed in the top right to show what im doing.
    • Apr 05 2009 | 11:02 am
      damn vade, this motion blur is fckn trippy as hell! IM getting really wild results, its like the repos that andrew made but with crazy smeary spikes. Ill post a patch and jitterified shader in a bit.
    • Apr 05 2009 | 12:03 pm
      Axiom-Crux wrote on Sat, 04 April 2009 19:16http://vimeo.com/4006177
      a couple more tests of my mesh distortion fluid feedback patch, doesn't use the shaders that andrew made, just the cv.jit.hsflow
      i put a small camera feed in the top right to show what im doing.
      Beautiful clip.
      Very much interested into seeing this patch...
      would be very kind
    • Apr 06 2009 | 2:14 am
      Axiom, glad you are enjoying it
      Its much more 'smeary' than 'blurry', I was trying to write a good motion blur shader based off of the code I wrote for QC, but I was not expecting this.
      Another fun trick I found:
      Readback the HSFlow output and Average it out. This gives you the average motion vector for the whole scene/frame. Apply that as a blur vector for a full frame blur.
      Now you can control with one video the motion blur of another. Its kind of a one trick piny but fun to be able to blur using your hand gesture...
    • Apr 06 2009 | 11:31 pm
      actually thats what I have heen doing, I love it! ahahah, you guys rock so much!
    • Apr 12 2009 | 2:20 am
      Sounds awesome, but I can't seem to get it working.
      The output screen ('fa') fills with green, then Max becomes unresponsive, and I have to shut it down.
      I'm on Windows, so I replaced jit.qt.grab with jit.dx.grab.
      I've used the same camera with Max 5 before...
    • Apr 13 2009 | 3:51 am
      Andrew:
      Ive been making some great things with your shaders, I noticed that if you mix feedback the final output from the repos you can get much more interesting fluidy effects, and combining your repos and vades motion blur in various ways is making some great watercolor type effects. Ill post some vimeo clips soon.
      I made a motion blur for full openGL scenes using frame differencing slab and your lumablur, as well as the depth of field I showed in the other thread (which I improved greatly with a multipass of your lumablur). I should technically be able to implement them both together in any patch without significantly more gpu resources by just doing a lightness composite of depth map and motion blur map and just one chain of multipass lumablur. Once I get some of the other shaders Im working on perfected and hopefully figure out shadows we should all finally be able to make jitter opengl look like what ive been seeing in current videogame quality. Ill post some of the things im working on soon as they are refined.
      I cant thank you enough for all of these!
      Vade:
      Im curious about the QC port, I tried to install it on my 10.4.11 computer and it didn't seem to work and then tried it on my gf 10.5 computer and it didnt' work either, Im sure they are in the right spot and on 10.5 it seems to load the patches with no errors but just outputs black? strange.. I like QC, Its like super easyified jitter, with some interesting final application + screensaver possibilities, but I just wish you could do more indepth stuff like with jitter, as in manipulating geometry etc..
    • Apr 13 2009 | 6:33 pm
      This is a bit OT, but QC plugins require 10.5, and ive gotten no reports of issues like that. Email me at vade at vade dot info and we can work it out
      Sorry for OT post.
    • Apr 14 2009 | 7:11 am
      Hello Andrew,
      I have been patching your flow distortions in with some video I have been working on and they are awesome. But I keep having this problem that is starting to drive me a little insane, recently whenever I run video through your flow distortion patch, the hs flow I get this black "swirl" that just turns the entire image to black and then there is nothing I can do to get it back I have to restart my computer and now I have restarted and I 'm still having the problem! I'm pretty new to max so I am going to attach my dinky and unfinished patch to this post, but I seem to remember having this problem once or twice when I first opened your patch and was just experimenting with my mac's camera.
      Any help would be really awesome and thanks of these patches.
      thanks
      jjr
    • Apr 14 2009 | 8:08 pm
      again, toggling the readback mechanism seemed to fix problems like this for me. not really sure why.
    • Apr 14 2009 | 10:13 pm
      would you suggest a loadbang on one of these so it bangs when I open the patch, do you think that that would help it usually happens right away when I get the black screen.
      I've pasted them in
      thanks
      jjr
    • Apr 15 2009 | 1:11 am
      oh yeah, jimmy, I like your version of the patch, its so nitty gritty. I keep pushing mine to these very smooth painterly filters but its cool to see the opposite. works fine on my comp. Try these buttons,
      be gentle with them, one of those modes might be the one making your thing mess up so try one at a time
    • Apr 16 2009 | 12:48 am
      Hello all,
      thanks for everyones help, one more question. Where can I attach a jit.pwindow in this patch so that i can see what the effects are doing while I am performing if the projection is behind me?
      basically how do I attach a pwindow in addition to the jit.window producing the floating "fa" 640 =480 images.
      thanks
      !
      jjr
    • Apr 17 2009 | 12:30 am
      I've attempted to recreate Andrew Benson's ab.hasflow.jxs-help.maxpat in 4.6.3. and with a movie player rather than camera input. I keep getting errors on my messages into the hsflow shader. The errors I get are message doesn't understand scale, lambda and offset. The flowrepos part of the patch seems to be working. Can anybody tell me what I've done wrong. I'm also not sure if I completely understand what the ab.rgbluma.jxs shader is doing. If I hook it up directly to my videoplane I get a white jit.window. I'm also interested in knowing where I might find more information on the lambda message. As always, assistance is most sincerely appreciated.
      Thanks,
      S.
      max v2;
    • Apr 17 2009 | 12:55 am
      why dont you copy paste the one the other dude made? its in the same post near the top
    • Apr 17 2009 | 1:09 am
      He converted the other help patch. I'm trying to convert the simpler one and for some reason I can't get it to work. Thanks anyhow . . .
    • Apr 17 2009 | 2:02 am
      the simpler one is similar with the lumakey, and slide taken out, I can post a screenshot if it helps
    • Apr 17 2009 | 2:04 am
    • Apr 17 2009 | 2:17 am
      thanks, for the screen shot. I just figured out I made a typo and forgot to label the rgbluma slab properly. Left out my FOO and that is what caused all the problems. Should have known. Just dumb user error. Should have spent a little more time troubleshooting before I hit the post button. If you know what the Lambda argument does I'd be grateful. I'm really trying to understand this deeper and not just enough to cut and paste. Thanks for your help.
      S.
    • Apr 17 2009 | 2:29 am
      hello max lordsss
      I tried to patch a jit.pwindow into hsflow following instructions I got from one of ab's tutorials call "preview, which had me patching a second jit.gl.render in to the patch adding a "@shared contex" but all I'm getting is a white screen. I'll attach the patch if someone wouldn't mind taking a look.
      thanks
      jjr
    • Apr 17 2009 | 2:53 am
      lambda does a sort of noise removal, just limits the ammount of detail and little interactions that the hsflow calculates, which will give a more accurate and simplified motion gradient.
    • Apr 17 2009 | 5:16 am
      BaltimoreMAX wrote on Thu, 16 April 2009 20:29hello max lordsss
      I tried to patch a jit.pwindow into hsflow following instructions I got from one of ab's tutorials call "preview, which had me patching a second jit.gl.render in to the patch adding a "@shared contex" but all I'm getting is a white screen. I'll attach the patch if someone wouldn't mind taking a look.
      thanks
      jjr
      your patch has a typo. you name your texture "mytex" but you set your videoplane's texture attribute to "mytext"
    • Apr 19 2009 | 3:21 pm
      Thank you, Andrew, for your great work, I love your hsflow shaders!
      I used it in my new MaxMSP/Jitter patch in combination with the jit.atari object and it works very well to me!
      I've uploaded some examples from my last live-performance at the Philharmonie in Essen (Germany) on vimeo:
      I'm using the one-turntable setup extended with KP-mini, Kaossilator and my MaxMSP/Jitter Patch. The visuals are controlled by audio input from turntable and kaossilator.
      Thank you very much!
      Damian
    • Apr 29 2009 | 3:14 pm
      I'd love to port this to Processing - you're all getting some gorgeous results, but I don't have much experience with MAX and Jitter - can anyone point me in a good starting direction?
    • May 13 2009 | 3:08 am
      it would be easy to port, just take the shaders and input them into whatever processing library takes GLSL shaders. Then from there if you want Im down to talk on or off list about how to get them working. I dont know much processing yet, but I was hoping to do the same. I just chilled with casey reas all of saturday after we both gave lectures at the museum of contemporary art, and he was very cool. (one of the two co-founders of processing), it was funny cause I actually started talking about GPU and glsl during the lecture and everyone in the audience was well... lets say it was over their heads, hehehe
      but yeah, message me or keep posting on the thread and Ill see what I can do, and Im sure if I dont have an answer mr reas or his students/colleagues will.
      Oh and just fyi the things Ive been posting dont use what andrew posted, they are just using a similar algorythm from the cv.jit.HSflow but andrews is way faster and better on a good card.
    • May 14 2009 | 3:01 pm
      oh and I think there might even be a hsflow opencv library for processing, it wont be as nice as converting the one andrew made but it will be able to do a ton of cool stuff
    • Nov 29 2009 | 2:59 am
      "But I keep having this problem that is starting to drive me a little insane, recently whenever I run video through your flow distortion patch, the hs flow I get this black "swirl" that just turns the entire image to black and then there is nothing I can do to get it back I have to restart my computer and now I have restarted and I 'm still having the problem!"
      I am having the same problem for some reason and toggling the readback mechanism doesn't seem to fix the problem. Its really weird because it works fine on my macbookpro and my house mates mac pro but im setting up an installation using 3 imacs running 10.5.8, 2.16ghz and they dont seem to be able to load the shaders or something.
      Im not getting any error msg's in the max window either. Really desperate to get this working. Any ideas....
      Sorry for dredging up an old post as well.
      Thanks.
    • Nov 29 2009 | 3:32 am
      also the graphics card on these computers are NVIDIA GeForce 7300 GT and the graphics card on my mac book pro is an NVIDIA GeForce 8600M GT.
      Could it be that the graphics card isn't reading these shaders properly. >?
    • Nov 29 2009 | 11:50 pm
      @Buffer, I have seen this effect before too, and it usually arises when I am using a lot of floating point textures. Switching to @type char (even temporarily) seems to clear it up. It appears there is some sort of floating-point arithmetic error that gets propagated (and appears as black pixels) in the feedback. I don't actually understand enough of the inner voodoo of fragment processing units to say exactly what the cause is.
    • Nov 30 2009 | 1:16 am
      Thanks Andrew. Yeah it does seem like there is some serious inner voodoo going on under the hood of this patch.
      I found a work around that refreshes the image if it all swirls to black by hitting escape if its set up to make the window full screen. seems to reset the image to be moshed again.
      Thanks for reply.
    • Dec 01 2009 | 5:39 am
      Here is a link for the missing attachment.
      Andrew B.
    • Mar 18 2011 | 2:08 pm
      Hi All.
      I try to make the vade's shader (modification from flowrepos),
      but I have several errors message (unable to bind scale and bias)…
      Any idea of the issue ?
      high-quality relative distortion based on hsflow output position map
      Thx.
      Ad
    • Mar 18 2011 | 6:53 pm
      i think it's because you're not actually using those uniforms in the program code. for whatever reason glsl generates an error in this case. either incorporate the uniforms into the code, or get rid of them.
    • Mar 21 2011 | 9:53 am
      thank you rob !
      ad-
    • Apr 03 2011 | 5:57 pm
      does anyone know where Andrew's attachment has gone form this thread? For example, the optical flow shader. Its not attached to his initial message....
    • Apr 03 2011 | 6:14 pm
      sorry, found it :->
    • May 04 2011 | 8:12 am
      where is the attachment aaaaaa
    • May 04 2011 | 8:49 am
      jk found it sorry
    • Sep 24 2012 | 1:32 pm
      link no longer works. would love to give this a test!
    • Sep 25 2012 | 9:48 am
      I've uploaded it there
    • Sep 25 2012 | 6:54 pm
      Thanks, much appreciated!