[Bf-blender-cvs] [1dddcfb] master: Compositor: Implement sampled motion blur for plane track deform node

Sergey Sharybin noreply at git.blender.org
Tue Feb 3 21:18:07 CET 2015


Commit: 1dddcfbaff14ff2871918b044714c87c7024e589
Author: Sergey Sharybin
Date:   Wed Feb 4 01:16:28 2015 +0500
Branches: master
https://developer.blender.org/rB1dddcfbaff14ff2871918b044714c87c7024e589

Compositor: Implement sampled motion blur for plane track deform node

Quite striaghtforward change, and in theory we can even try supporting motion
blur for the corner pin node (which is tricky because coordinates actually
coming from sockets, but with some black magic should be doable).

===================================================================

M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp
M	source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp
M	source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
M	source/blender/compositor/operations/COM_PlaneDistortCommonOperation.h
M	source/blender/compositor/operations/COM_PlaneTrackOperation.cpp
M	source/blender/compositor/operations/COM_PlaneTrackOperation.h
M	source/blender/editors/space_node/drawnode.c
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/composite/nodes/node_composite_planetrackdeform.c

===================================================================

diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index a6320ed..096fc31 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -542,4 +542,21 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
 				part->child_flag |= PART_CHILD_USE_ROUGH_CURVE;
 		}
 	}
+
+	if (!DNA_struct_elem_find(fd->filesdna, "NodePlaneTrackDeformData", "char", "flag")) {
+		FOREACH_NODETREE(main, ntree, id) {
+			if (ntree->type == NTREE_COMPOSIT) {
+				bNode *node;
+				for (node = ntree->nodes.first; node; node = node->next) {
+					if (ELEM(node->type, CMP_NODE_PLANETRACKDEFORM)) {
+						NodePlaneTrackDeformData *data = node->storage;
+						data->flag = 0;
+						data->motion_blur_samples = 16;
+						data->motion_blur_shutter = 0.5f;
+					}
+				}
+			}
+		}
+		FOREACH_NODETREE_END
+	}
 }
diff --git a/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp b/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp
index 9b69bc5..379b9f1 100644
--- a/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp
+++ b/source/blender/compositor/nodes/COM_PlaneTrackDeformNode.cpp
@@ -54,6 +54,10 @@ void PlaneTrackDeformNode::convertToOperations(NodeConverter &converter, const C
 	warp_image_operation->setTrackingObject(data->tracking_object);
 	warp_image_operation->setPlaneTrackName(data->plane_track_name);
 	warp_image_operation->setFramenumber(frame_number);
+	if (data->flag & CMP_NODEFLAG_PLANETRACKDEFORM_MOTION_BLUR) {
+		warp_image_operation->setMotionBlurSamples(data->motion_blur_samples);
+		warp_image_operation->setMotionBlurShutter(data->motion_blur_shutter);
+	}
 	converter.addOperation(warp_image_operation);
 	
 	converter.mapInputSocket(input_image, warp_image_operation->getInputSocket(0));
@@ -64,6 +68,10 @@ void PlaneTrackDeformNode::convertToOperations(NodeConverter &converter, const C
 	plane_mask_operation->setTrackingObject(data->tracking_object);
 	plane_mask_operation->setPlaneTrackName(data->plane_track_name);
 	plane_mask_operation->setFramenumber(frame_number);
+	if (data->flag & CMP_NODEFLAG_PLANETRACKDEFORM_MOTION_BLUR) {
+		plane_mask_operation->setMotionBlurSamples(data->motion_blur_samples);
+		plane_mask_operation->setMotionBlurShutter(data->motion_blur_shutter);
+	}
 	converter.addOperation(plane_mask_operation);
 	
 	converter.mapOutputSocket(output_plane, plane_mask_operation->getOutputSocket());
diff --git a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp
index fe27200..fb8730c 100644
--- a/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp
+++ b/source/blender/compositor/operations/COM_PlaneCornerPinOperation.cpp
@@ -135,7 +135,7 @@ void *PlaneCornerPinMaskOperation::initializeTileData(rcti *rect)
 		                             getInputSocketReader(3) };
 		float corners[4][2];
 		readCornersFromSockets(rect, readers, corners);
-		calculateCorners(corners, true);
+		calculateCorners(corners, true, 0);
 		
 		m_corners_ready = true;
 	}
@@ -194,8 +194,7 @@ void *PlaneCornerPinWarpImageOperation::initializeTileData(rcti *rect)
 		                             getInputSocketReader(4) };
 		float corners[4][2];
 		readCornersFromSockets(rect, readers, corners);
-		calculateCorners(corners, true);
-		calculatePerspectiveMatrix();
+		calculateCorners(corners, true, 0);
 		
 		m_corners_ready = true;
 	}
diff --git a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
index c507b4c..e3095f7 100644
--- a/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
+++ b/source/blender/compositor/operations/COM_PlaneDistortCommonOperation.cpp
@@ -56,36 +56,38 @@ PlaneDistortWarpImageOperation::PlaneDistortWarpImageOperation() :
 	this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE);
 	this->addOutputSocket(COM_DT_COLOR);
 	this->m_pixelReader = NULL;
+	this->m_motion_blur_samples = 1;
+	this->m_motion_blur_shutter = 0.5f;
 	this->setComplex(true);
 }
 
-void PlaneDistortWarpImageOperation::calculateCorners(const float corners[4][2], bool normalized)
+void PlaneDistortWarpImageOperation::calculateCorners(const float corners[4][2],
+                                                      bool normalized,
+                                                      int sample)
 {
+	BLI_assert(sample < this->m_motion_blur_samples);
+	const int width = this->m_pixelReader->getWidth();
+	const int height = this->m_pixelReader->getHeight();
+	float frame_corners[4][2] = {{0.0f, 0.0f},
+	                             {(float) width, 0.0f},
+	                             {(float) width, (float) height},
+	                             {0.0f, (float) height}};
+	MotionSample *sample_data = &this->m_samples[sample];
 	if (normalized) {
 		for (int i = 0; i < 4; i++) {
-			this->m_frameSpaceCorners[i][0] = corners[i][0] * this->getWidth();
-			this->m_frameSpaceCorners[i][1] = corners[i][1] * this->getHeight();
+			sample_data->frameSpaceCorners[i][0] = corners[i][0] * this->getWidth();
+			sample_data->frameSpaceCorners[i][1] = corners[i][1] * this->getHeight();
 		}
 	}
 	else {
 		for (int i = 0; i < 4; i++) {
-			this->m_frameSpaceCorners[i][0] = corners[i][0];
-			this->m_frameSpaceCorners[i][1] = corners[i][1];
+			sample_data->frameSpaceCorners[i][0] = corners[i][0];
+			sample_data->frameSpaceCorners[i][1] = corners[i][1];
 		}
 	}
-}
-
-void PlaneDistortWarpImageOperation::calculatePerspectiveMatrix()
-{
-	const int width = this->m_pixelReader->getWidth();
-	const int height = this->m_pixelReader->getHeight();
-	float frame_corners[4][2] = {{0.0f, 0.0f},
-	                             {(float) width, 0.0f},
-	                             {(float) width, (float) height},
-	                             {0.0f, (float) height}};
-	BKE_tracking_homography_between_two_quads(this->m_frameSpaceCorners,
+	BKE_tracking_homography_between_two_quads(sample_data->frameSpaceCorners,
 	                                          frame_corners,
-	                                          this->m_perspectiveMatrix);
+	                                          sample_data->perspectiveMatrix);
 }
 
 void PlaneDistortWarpImageOperation::initExecution()
@@ -100,35 +102,47 @@ void PlaneDistortWarpImageOperation::deinitExecution()
 
 void PlaneDistortWarpImageOperation::executePixelSampled(float output[4], float x, float y, PixelSampler sampler)
 {
-	float xy[2] = {x, y};
 	float uv[2];
 	float deriv[2][2];
-
-	pixelTransform(xy, uv, deriv);
-
-	m_pixelReader->readFiltered(output, uv[0], uv[1], deriv[0], deriv[1], COM_PS_BILINEAR);
-}
-
-void PlaneDistortWarpImageOperation::pixelTransform(const float xy[2], float r_uv[2], float r_deriv[2][2])
-{
-	warpCoord(xy[0], xy[1], m_perspectiveMatrix, r_uv, r_deriv);
+	if (this->m_motion_blur_samples == 1) {
+		warpCoord(x, y, this->m_samples[0].perspectiveMatrix, uv, deriv);
+		m_pixelReader->readFiltered(output,
+		                            uv[0], uv[1],
+		                            deriv[0], deriv[1],
+		                            COM_PS_BILINEAR);
+	}
+	else {
+		zero_v4(output);
+		for (int sample = 0; sample < this->m_motion_blur_samples; ++sample) {
+			float color[4];
+			warpCoord(x, y, this->m_samples[sample].perspectiveMatrix, uv, deriv);
+			m_pixelReader->readFiltered(color,
+			                            uv[0], uv[1],
+			                            deriv[0], deriv[1],
+			                            COM_PS_BILINEAR);
+			add_v4_v4(output, color);
+		}
+		mul_v4_fl(output, 1.0f / (float)this->m_motion_blur_samples);
+	}
 }
 
 bool PlaneDistortWarpImageOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
 {
-	float UVs[4][2];
-	float deriv[2][2];
-
-	/* TODO(sergey): figure out proper way to do this. */
-	warpCoord(input->xmin - 2, input->ymin - 2, this->m_perspectiveMatrix, UVs[0], deriv);
-	warpCoord(input->xmax + 2, input->ymin - 2, this->m_perspectiveMatrix, UVs[1], deriv);
-	warpCoord(input->xmax + 2, input->ymax + 2, this->m_perspectiveMatrix, UVs[2], deriv);
-	warpCoord(input->xmin - 2, input->ymax + 2, this->m_perspectiveMatrix, UVs[3], deriv);
-
 	float min[2], max[2];
 	INIT_MINMAX2(min, max);
-	for (int i = 0; i < 4; i++) {
-		minmax_v2v2_v2(min, max, UVs[i]);
+
+	for (int sample = 0; sample < this->m_motion_blur_samples; ++sample) {
+		float UVs[4][2];
+		float deriv[2][2];
+		MotionSample *sample_data = &this->m_samples[sample];
+		/* TODO(sergey): figure out proper way to do this. */
+		warpCoord(input->xmin - 2, input->ymin - 2, sample_data->perspectiveMatrix, UVs[0], deriv);
+		warpCoord(input->xmax + 2, input->ymin - 2, sample_data->perspectiveMatrix, UVs[1], deriv);
+		warpCoord(input->xmax + 2, input->ymax + 2, sample_data->perspectiveMatrix, UVs[2], deriv);
+		warpCoord(input->xmin - 2, input->ymax + 2, sample_data->perspectiveMatrix, UVs[3], deriv);
+		for (int i = 0; i < 4; i++) {
+			minmax_v2v2_v2(min, max, UVs[i]);
+		}
 	}
 
 	rcti newInput;
@@ -151,20 +165,26 @@ PlaneDistortMaskOperation::PlaneDistortMaskOperation() :
 
 	/* Currently hardcoded to 8 samples. */
 	m_osa = 8;
+	this->m_motion_blur_samples = 1;
+	this->m_motion_blur_shutter = 0.5f;
 }
 
-void PlaneDistortMaskOperation::calculateCorners(const float corners[4][2], bool normalized)
+void PlaneDistortMaskOperation::calculateCorners(const float corners[4][2],
+                                                 bool normalized,
+                                                 int sample)
 {
+	BLI_assert(sample < this->m_motion_blur_samples);
+	MotionSample *sample_data = &this->m_samples[sample];
 	if (normalized) {
 		for (int i = 0; i < 4; i++) {
-			this->m_frameSpaceCorners[i][0] = corners[i][0] * this->getWidth();
-			this->m_frameSpaceCorners[i][1] = corners[i][1] * this->getHeight();
+			sample_data->frameSpaceCorners[i][0] = corners[i][0] * this->getWidth();
+			sample_data->frameSpaceCorners[i][1] = corners[i][1] * this->getHeight();
 		}
 	}
 	else {
 		for (int i = 0; i < 4; i++) {
-			this->m_fra

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list