Compositor: Re-consider the way how track speed works
authorSergey Sharybin <sergey.vfx@gmail.com>
Mon, 15 Feb 2016 11:43:14 +0000 (12:43 +0100)
committerSergey Sharybin <sergey.vfx@gmail.com>
Mon, 15 Feb 2016 11:43:14 +0000 (12:43 +0100)
Based on an user feedback, previous implementation with providing
decoupled X and Y speeds didn't work in production at all: there
is no way to combine this speeds to an usable vector.

So now we're providing speed vector output instead, which provides
speed in an exactly the way Vector Blur node expects it to be:
first two components is a speed from the past, second two components
defines speed to the future.

Old behavior can be achieved by RGBA separating the speed output
and using first tow components.

Now this speed gives quite the same results as a speed pass, with
the only difference that track position speed uses "shutter" of
1 while pass uses shutter of 0.5 (and there's no way to affect on
that?).

source/blender/compositor/nodes/COM_TrackPositionNode.cpp
source/blender/compositor/operations/COM_TrackPositionOperation.cpp
source/blender/nodes/composite/nodes/node_composite_trackpos.c

index 7f23798b768b2df7c2a2a9b49bc390071d344f90..490f72b4aa1f403518b91d5e280a2380e430dfd8 100644 (file)
@@ -22,6 +22,8 @@
  */
 
 #include "COM_TrackPositionNode.h"
+
+#include "COM_ConvertOperation.h"
 #include "COM_ExecutionSystem.h"
 #include "COM_TrackPositionOperation.h"
 
@@ -36,6 +38,26 @@ TrackPositionNode::TrackPositionNode(bNode *editorNode) : Node(editorNode)
        /* pass */
 }
 
+static TrackPositionOperation *create_motion_operation(NodeConverter &converter,
+                                                       MovieClip *clip,
+                                                       NodeTrackPosData *trackpos_data,
+                                                       int axis,
+                                                       int frame_number,
+                                                       int delta)
+{
+       TrackPositionOperation *operation = new TrackPositionOperation();
+       operation->setMovieClip(clip);
+       operation->setTrackingObject(trackpos_data->tracking_object);
+       operation->setTrackName(trackpos_data->track_name);
+       operation->setFramenumber(frame_number);
+       operation->setAxis(axis);
+       operation->setPosition(CMP_TRACKPOS_ABSOLUTE);
+       operation->setRelativeFrame(frame_number + delta);
+       operation->setSpeedOutput(true);
+       converter.addOperation(operation);
+       return operation;
+}
+
 void TrackPositionNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
 {
        bNode *editorNode = this->getbNode();
@@ -44,8 +66,7 @@ void TrackPositionNode::convertToOperations(NodeConverter &converter, const Comp
        
        NodeOutput *outputX = this->getOutputSocket(0);
        NodeOutput *outputY = this->getOutputSocket(1);
-       NodeOutput *outputSpeedX = this->getOutputSocket(2);
-       NodeOutput *outputSpeedY = this->getOutputSocket(3);
+       NodeOutput *outputSpeed = this->getOutputSocket(2);
 
        int frame_number;
        if (editorNode->custom1 == CMP_TRACKPOS_ABSOLUTE_FRAME) {
@@ -64,6 +85,7 @@ void TrackPositionNode::convertToOperations(NodeConverter &converter, const Comp
        operationX->setPosition(editorNode->custom1);
        operationX->setRelativeFrame(editorNode->custom2);
        converter.addOperation(operationX);
+       converter.mapOutputSocket(outputX, operationX->getOutputSocket());
 
        TrackPositionOperation *operationY = new TrackPositionOperation();
        operationY->setMovieClip(clip);
@@ -74,31 +96,26 @@ void TrackPositionNode::convertToOperations(NodeConverter &converter, const Comp
        operationY->setPosition(editorNode->custom1);
        operationY->setRelativeFrame(editorNode->custom2);
        converter.addOperation(operationY);
+       converter.mapOutputSocket(outputY, operationY->getOutputSocket());
 
-       TrackPositionOperation *operationSpeedX = new TrackPositionOperation();
-       operationSpeedX->setMovieClip(clip);
-       operationSpeedX->setTrackingObject(trackpos_data->tracking_object);
-       operationSpeedX->setTrackName(trackpos_data->track_name);
-       operationSpeedX->setFramenumber(frame_number);
-       operationSpeedX->setAxis(0);
-       operationSpeedX->setPosition(editorNode->custom1);
-       operationSpeedX->setRelativeFrame(editorNode->custom2);
-       operationSpeedX->setSpeedOutput(true);
-       converter.addOperation(operationSpeedX);
-
-       TrackPositionOperation *operationSpeedY = new TrackPositionOperation();
-       operationSpeedY->setMovieClip(clip);
-       operationSpeedY->setTrackingObject(trackpos_data->tracking_object);
-       operationSpeedY->setTrackName(trackpos_data->track_name);
-       operationSpeedY->setFramenumber(frame_number);
-       operationSpeedY->setAxis(1);
-       operationSpeedY->setPosition(editorNode->custom1);
-       operationSpeedY->setRelativeFrame(editorNode->custom2);
-       operationSpeedY->setSpeedOutput(true);
-       converter.addOperation(operationSpeedY);
+       TrackPositionOperation *operationMotionPreX =
+               create_motion_operation(converter, clip, trackpos_data, 0, frame_number, -1);
+       TrackPositionOperation *operationMotionPreY =
+               create_motion_operation(converter, clip, trackpos_data, 1, frame_number, -1);
+       TrackPositionOperation *operationMotionPostX =
+               create_motion_operation(converter, clip, trackpos_data, 0, frame_number, 1);
+       TrackPositionOperation *operationMotionPostY =
+              create_motion_operation(converter, clip, trackpos_data, 1, frame_number, 1);
 
-       converter.mapOutputSocket(outputX, operationX->getOutputSocket());
-       converter.mapOutputSocket(outputY, operationY->getOutputSocket());
-       converter.mapOutputSocket(outputSpeedX, operationSpeedX->getOutputSocket());
-       converter.mapOutputSocket(outputSpeedY, operationSpeedY->getOutputSocket());
+       CombineChannelsOperation *combine_operation = new CombineChannelsOperation();
+       converter.addOperation(combine_operation);
+       converter.addLink(operationMotionPreX->getOutputSocket(),
+                         combine_operation->getInputSocket(0));
+       converter.addLink(operationMotionPreY->getOutputSocket(),
+                         combine_operation->getInputSocket(1));
+       converter.addLink(operationMotionPostX->getOutputSocket(),
+                         combine_operation->getInputSocket(2));
+       converter.addLink(operationMotionPostY->getOutputSocket(),
+                         combine_operation->getInputSocket(3));
+       converter.mapOutputSocket(outputSpeed, combine_operation->getOutputSocket());
 }
index 52ceb50e693fdd1ce5a135d3c1a2a26cd16271ca..f9db897deba126f285cb384f15d1da6e36e801a5 100644 (file)
@@ -80,13 +80,22 @@ void TrackPositionOperation::initExecution()
                        copy_v2_v2(this->m_markerPos, marker->pos);
 
                        if (this->m_speed_output) {
-                               marker = BKE_tracking_marker_get(track, clip_framenr - 1);
-                               if ((marker->flag & MARKER_DISABLED) == 0) {
+                               int relative_clip_framenr =
+                                       BKE_movieclip_remap_scene_to_clip_frame(
+                                               this->m_movieClip,
+                                               this->m_relativeFrame);
+
+                               marker = BKE_tracking_marker_get_exact(track,
+                                                                      relative_clip_framenr);
+                               if (marker != NULL && (marker->flag & MARKER_DISABLED) == 0) {
                                        copy_v2_v2(this->m_relativePos, marker->pos);
                                }
                                else {
                                        copy_v2_v2(this->m_relativePos, this->m_markerPos);
                                }
+                               if (this->m_relativeFrame < this->m_framenumber) {
+                                       swap_v2_v2(this->m_relativePos, this->m_markerPos);
+                               }
                        }
                        else if (this->m_position == CMP_TRACKPOS_RELATIVE_START) {
                                int i;
index de4fe47a6ece67f841a688fa7021c8d72c8bba3a..4a00fb5a9004fc1d0ec5b2ea052dd597f0ad8ede 100644 (file)
@@ -36,8 +36,7 @@
 static bNodeSocketTemplate cmp_node_trackpos_out[] = {
        {       SOCK_FLOAT,             0,      N_("X")},
        {       SOCK_FLOAT,             0,      N_("Y")},
-       {       SOCK_FLOAT,             0,      N_("Speed X")},
-       {       SOCK_FLOAT,             0,      N_("Speed Y")},
+       {       SOCK_VECTOR,            0,      N_("Speed"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_VELOCITY},
        {       -1, 0, ""       }
 };