Displace Node

December 30th, 2006 . 7 comments

Yesterday I added a new node to Blender’s compositor: Displace. It works very similarly to Shake’s iDisplace node, pushing pixels around based on an input vector mask, and is useful for all sorts of things like doing hot air distortion, quick and dirty refraction effects in post, and so on. The full documentation is in the commit log, I guess I’ll have to tidy it up for the release notes.

One curiousity of this one is the technique used to code it. Most of the code logic was done using Blender’s Python Image API, as a means of quickly testing and prototyping. Python is a lot slower at the actual processing, but it’s a heck of a lot quicker to test than having to compile Blender each time. I recommend it!

You can download the prototype script/.blend file if you’re curious (just press Alt P). I then ported to C, which is relatively easy to do for simple image processing code like this, and changed a few things around. Previously in the Python version I had to try and come up with my own not-too-bad antialiasing code, though I’m sure what I came up with has been done before and has a nice technical name or something 😉 In the C version I was able to use some nicer image sampling code that Ton used for the awesome Map UV node. Incidentally, I also used the same Python prototyping technique for the UV test grid option when creating new images in Blender (.blend file).

Displace node example

Quick demo video: hot air distortion

displace node displace node

Greyscale input, displacing in one direction (node setup)

2D vector input (normal map), independent (more accurate) X and Y displacement (node setup)

§ 7 Responses to Displace Node"

  • ibkanat says:

    thanks…. Been looking at motion tracking and hoping that I might be able to import in some of the readily availlible gpl code.

  • Leonardo, I’m telling you. Leonardo!

  • MrMunkily says:

    Hey Matt, this looks great!

    Just out of curiosity & envy, how is the UI work coming along? I remember so very pretty previews for 2.37… Any secret “drawtype” patches to spring on us all?

  • Matt says:

    Hi guys, thanks for the comments!

    MrMunkily: Well, lately I’ve been a bit demotivated to work on that sort of thing, and there’s been more than enough to do in polishing up other people’s current work and having fun with things like this post 😉 Porting this old code from Tuhopuu and cleaning it up, adjusting for newer changes, etc. is not the most fun and rewarding job.

    But it’s progressing, I have a portion of the buttons stuff up to date and improved in my current bf cvs tree, but it’d be really difficult to make a patch at this stage since there’s so much other stuff mixed through. Hopefully 2.5 will bring some freshness and motivation for this sort of thing, since UI and usability in Blender has been rather neglected recently in the mad rush for features for ED and Plumiferos.

  • QA says:

    This is so awesome! But I just ran it in Blender 2.68a and got an error. Not too surprised, because Blender has changed so much since you wrote this. Any chance you’ll update the code for the current version?

  • QA says:

    Ha! Never mind – I see there is a Displace Node built-in now as a standard feature. Still, it’s awesome that you did it first, and your blog post helped me track down the name of this effect. So thanks.

  • Matt says:

    yep, it’s from 2006 🙂 No worries.

Leave a Reply

Your email address will not be published. Required fields are marked *

What's this?

You are currently reading Displace Node at Matt Ebb.