Jump to content
Sign in to follow this  
JJ FX

mantra velocity pass

Recommended Posts

Hi, 

So there is no default velocity pass in mantra. At least I cant see it. I added extra image plane, the v variable, but nothing renders out.

Yeah I can colorize by velocity and render out, and this would be my veloctiy pass. But that needs additional rendering. And I dont have time to do additional renders now

Can I render out velocity as one render?

Edited by JJ FX

Share this post


Link to post
Share on other sites

Always seemed odd that there's no simple way to do this - I guess most FX is rendered with motion blur since it's fast these days and looks better :)

It's quite tricky to handle all cases - below is how I do, but I wonder if this misses any potential combination of v attribute from a sim, animated scene transforms and camera motion...

/* All-purpose motion vector output - creates 2D vectors in absolute pixels,
   suitable for Flame MotionBlur or Nuke VectorBlur
   lewis@lewissaunders.com Dec 2017

   This works with or without a v attribute from the geo, and includes 
   effect of scene-level transforms.

   Inside a /mat shader (not at the top /mat level), paste this
   in an Inline Code VOP - turn on "Expand Expressions in Code" and
   add a single vector output called mv, which should be connected to a Bind
   Export.  The name in the Bind will be what you use in Mantra's Extra
   Image Planes Section.  Add a Bind VOP with name set to v and plug it into
   the first input on the Inline Code.

   On the Mantra ROP, turn on "Allow Motion Blur" and disable "Allow Image
   Motion Blur" if the blur will be done purely in post.  If you don't have
   a v attribute on your geo, turn "Geo Time Samples" up to 2, or sprinkle
   Trail SOPs around to taste */

// Find position at start of shutter opening - if rendering in
// raytrace mode with image motion blur on, the regular P global
// is offset for the current sample time which we don't want
vector p0 = getblurP(0.0);

vector camerav;
if(isbound("v")) {
    // We have a v attribute on the geometry
    // This will likely be per second rather than per frame
    vector framev = v / $FPS;
    
    // Transform from object space into camera space
    // This takes into account scene-level transforms
    camerav = vtransform("space:object", "space:camera", framev);
} else {
    // No v attribute on geometry, so work one out
    camerav = getblurP(1.0) - p0;
}

// Find difference between start of shutter opening and end in
// NDC space
vector ndcv = toNDC(p0 + camerav) - toNDC(p0);

// Multiply by render resolution to get screen space in pixels
vector res;
renderstate("image:resolution", res);
ndcv *= set(res.x, res.y, 0.0);

// $mv has to be escaped here because we need expressions expanded to get $FPS
\$mv = ndcv;

http://lewisinthelandofmachines.tumblr.com/post/159532447318/houdini-2d-motion-vectors-from-mantra

 

Edited by Lcrs
updated code for H16

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×