I am trying to write an expression which will mimic the mv2DToxik motion vectors, but for hardware particles. Therefore removing the need to instance some geo to get the motion vectors to render.
I have not got very far before I came across some vector maths...
Here is the setup which works for a camera pointing exactly down the z-axis.
Here is the render loaded into Nuke. Notice the RGB values.
I now need to find a way to convert World Velocity to Screen Space Velocity.
In a MEL expression. Hmmm, time to ask the Forum
After some great advice from Zoharl, I grabbed some code which uses the camera's worldInverseMatrix to transform the velocity vector.
Here is the expression:
//get the particle's World Space velocity
// create particle's velocity matrix which is in World Space
// get the camera's World Inverse Matrix
float $v=`getAttr camera1.worldInverseMatrix`;
matrix $camWIM=<< $v[ 0], $v[ 1], $v[ 2], $v[ 3]; $v[ 4], $v[ 5], $v[ 6], $v[ 7]; $v[ 8], $v[ 9], $v, $v; $v, $v, $v, $v >>;
//multiply particle's velocity matrix by the camera's World Inverse Matrix to get the velocity in Screen Space
matrix $SSvel=$WSvel * $camWIM;
vector $result = <<$SSvel,$SSvel,$SSvel>>;
float $xResult = $mult * $result.x;
float $yResult = $mult * $result.y;
float $zResult = $mult * $result.z;
So far it seems to be working, but I will try to test it and see if it breaks down.
Thanks to Zoharl on the CGTalk forum and to xyz2.net and 185vfx who came up with the original matrix manipulation code.
Post a Comment