Wednesday, 26 February 2014

Fusion: Adding a curve multiplier to motion blur

This is a method I came up with to tackle quite a unique problem: I needed to adjust the falloff of motion blur, so where there wasn't much movement, the motion blur was lowered even more, but where there was fast movement the motion blur kept its intensity.

Note: This is working with post motion blur, created from a velocity pass. In this case in Fusion, using the "Vector Motion Blur" node. I used an unclamped velocity pass, so the range has not been normalized. I am also using the Krokodove plugin for Fusion, specifically the "Vector Visualization" node so I can show feedback on the motion blur vectors.

This is the velocity I will be using for this example. You can see a normalized version under it. It has red going in the x from -10 to 10, and green going from -10 to 10 in the y.


OK, first we need to understand how a velocity pass works. It is a data pass that stores how much a pixel moves both horizontally (x) and vertically (y). This is stored as red and green values within the image. These values help calculate the direction and magnitude of the motion blur. You can see for yourself by using Pythagoras' Theorem:
a^2 + b^2 = c^2

So you cannot simply add a curve to the velocity pass, as you would actually end up changing the direction of the vectors.

Original Vectors:


In the image below, the red is original vector and the green is the adjusted. You can see the deviation in the vectors:


This is because the red and green values are not going to be the same values in most cases. In the vector below you can see it goes diagonally across. It has a longer x value to produce the sloping angle.


If you wanted to half the vector using a clamp, and had the maximum threshold set to 4, it would pick up the y value but not the x. By changing only the y value, you are changing the direction of the vector, as well as not scaling the magnitude correctly:


What you really want to do is scale both values. The way to do this is to clamp the magnitude produced, not the x and y components.


To do this we work out the magnitude by using Pythagoras' Theorem. I used a custom tool in Fusion to do this.

Next I normalize the values to whatever I want the maximum velocity affected, and clamp the rest, so there are no values above 1 (this is important for when i multiply the curve onto the velocity pass later)

Then we can use a curve on this data, and then use this as a multiplier for velocity (red/green data).
If we have a curve that goes from 1,1 then the output will be unchanged, and from there we can draw a curve into the magnitude based on intensity.

Finally you can multiple this new pass with the velocity pass, and it will multiply the red and green in each pixel the same amount, scaling down the velocity correctly

Vectors with 1 to 1 curve:


Vectors with falloff (green are the original vectors, red the new vectors):


Fusion setup:


And expression used in nodes:


No comments:

Post a Comment