[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49278] trunk/blender/source/blender: motion blur for mask node:

Campbell Barton ideasman42 at gmail.com
Fri Jul 27 11:32:47 CEST 2012


Revision: 49278
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49278
Author:   campbellbarton
Date:     2012-07-27 09:32:47 +0000 (Fri, 27 Jul 2012)
Log Message:
-----------
motion blur for mask node:

TODO
- add shutter speed option
- add blur option

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/nodes/COM_MaskNode.cpp
    trunk/blender/source/blender/compositor/operations/COM_MaskOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_MaskOperation.h
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c

Modified: trunk/blender/source/blender/compositor/nodes/COM_MaskNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_MaskNode.cpp	2012-07-27 08:58:34 UTC (rev 49277)
+++ trunk/blender/source/blender/compositor/nodes/COM_MaskNode.cpp	2012-07-27 09:32:47 UTC (rev 49278)
@@ -69,5 +69,9 @@
 	operation->setSmooth((bool)(editorNode->custom1 & CMP_NODEFLAG_MASK_AA) != 0);
 	operation->setFeather((bool)(editorNode->custom1 & CMP_NODEFLAG_MASK_NO_FEATHER) == 0);
 
+	if (editorNode->custom1 & CMP_NODEFLAG_MASK_MOTION_BLUR) {
+		operation->setMotionBlurSamples(editorNode->custom2);
+	}
+
 	graph->addOperation(operation);
 }

Modified: trunk/blender/source/blender/compositor/operations/COM_MaskOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_MaskOperation.cpp	2012-07-27 08:58:34 UTC (rev 49277)
+++ trunk/blender/source/blender/compositor/operations/COM_MaskOperation.cpp	2012-07-27 09:32:47 UTC (rev 49278)
@@ -137,28 +137,74 @@
 	this->m_mask = NULL;
 	this->m_maskWidth = 0;
 	this->m_maskHeight = 0;
+	this->m_maskWidthInv = 0.0f;
+	this->m_maskHeightInv = 0.0f;
 	this->m_framenumber = 0;
-	this->m_rasterMaskHandle = NULL;
+	this->m_rasterMaskHandleTot = 1;
+	memset(this->m_rasterMaskHandles, 0, sizeof(this->m_rasterMaskHandles));
 }
 
 void MaskOperation::initExecution()
 {
-	if (this->m_mask) {
-		if (this->m_rasterMaskHandle == NULL) {
-			this->m_rasterMaskHandle = BKE_maskrasterize_handle_new();
+	if (this->m_mask && this->m_rasterMaskHandles[0] == NULL) {
+		if (this->m_rasterMaskHandleTot == 1) {
+			this->m_rasterMaskHandles[0] = BKE_maskrasterize_handle_new();
 
-			BKE_maskrasterize_handle_init(this->m_rasterMaskHandle, this->m_mask,
-			                              this->m_maskWidth, this->m_maskHeight,
-			                              TRUE, this->m_do_smooth, this->m_do_feather);
+			BKE_maskrasterize_handle_init(this->m_rasterMaskHandles[0], this->m_mask,
+			        this->m_maskWidth, this->m_maskHeight,
+			        TRUE, this->m_do_smooth, this->m_do_feather);
 		}
+		else {
+			/* make a throw away copy of the mask */
+			const float frame_range = 1.0f; /* should be 1 max, could be configurable */
+			const float frame = (float)this->m_framenumber - frame_range;
+			const float frame_step = (frame_range * 2.0f) / this->m_rasterMaskHandleTot;
+			float frame_iter = frame;
+
+			Mask *mask_temp;
+
+			mask_temp = BKE_mask_copy_nolib(this->m_mask);
+
+			/* trick so we can get unkeyed edits to display */
+			{
+				MaskLayer *masklay;
+				MaskLayerShape *masklay_shape;
+
+				for (masklay = (MaskLayer *)mask_temp->masklayers.first;
+				     masklay;
+				     masklay = (MaskLayer *)masklay->next)
+				{
+					masklay_shape = BKE_mask_layer_shape_varify_frame(masklay, this->m_framenumber);
+					BKE_mask_layer_shape_from_mask(masklay, masklay_shape);
+				}
+			}
+
+			for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) {
+				this->m_rasterMaskHandles[i] = BKE_maskrasterize_handle_new();
+
+				/* re-eval frame info */
+				BKE_mask_evaluate(mask_temp, frame_iter, TRUE);
+
+				BKE_maskrasterize_handle_init(this->m_rasterMaskHandles[i], mask_temp,
+				                              this->m_maskWidth, this->m_maskHeight,
+				                              TRUE, this->m_do_smooth, this->m_do_feather);
+
+				frame_iter += frame_step;
+			}
+
+			BKE_mask_free(mask_temp);
+			MEM_freeN(mask_temp);
+		}
 	}
 }
 
 void MaskOperation::deinitExecution()
 {
-	if (this->m_rasterMaskHandle) {
-		BKE_maskrasterize_handle_free(this->m_rasterMaskHandle);
-		this->m_rasterMaskHandle = NULL;
+	for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) {
+		if (this->m_rasterMaskHandles[i]) {
+			BKE_maskrasterize_handle_free(this->m_rasterMaskHandles[i]);
+			this->m_rasterMaskHandles[i] = NULL;
+		}
 	}
 }
 
@@ -182,12 +228,28 @@
 
 void MaskOperation::executePixel(float *color, float x, float y, PixelSampler sampler)
 {
-	if (this->m_rasterMaskHandle) {
-		const float xy[2] = {x * this->m_maskWidthInv, y * this->m_maskHeightInv};
-		color[0] = BKE_maskrasterize_handle_sample(this->m_rasterMaskHandle, xy);
+	const float xy[2] = {x * this->m_maskWidthInv, y * this->m_maskHeightInv};
+
+	if (this->m_rasterMaskHandleTot == 1) {
+		if (this->m_rasterMaskHandles[0]) {
+			color[0] = BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[0], xy);
+		}
+		else {
+			color[0] = 0.0f;
+		}
 	}
 	else {
+		/* incase loop below fails */
 		color[0] = 0.0f;
+
+		for (unsigned int i = 0; i < this->m_rasterMaskHandleTot; i++) {
+			if (this->m_rasterMaskHandles[i]) {
+				color[0] += BKE_maskrasterize_handle_sample(this->m_rasterMaskHandles[i], xy);
+			}
+		}
+
+		/* until we get better falloff */
+		color[0] /= this->m_rasterMaskHandleTot;
 	}
 }
 

Modified: trunk/blender/source/blender/compositor/operations/COM_MaskOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_MaskOperation.h	2012-07-27 08:58:34 UTC (rev 49277)
+++ trunk/blender/source/blender/compositor/operations/COM_MaskOperation.h	2012-07-27 09:32:47 UTC (rev 49278)
@@ -64,7 +64,8 @@
 	ListBase m_maskLayers;
 
 #else /* USE_RASKTER */
-	struct MaskRasterHandle *m_rasterMaskHandle;
+	struct MaskRasterHandle *m_rasterMaskHandles[32];
+	unsigned int             m_rasterMaskHandleTot;
 #endif /* USE_RASKTER */
 
 	/**
@@ -93,6 +94,7 @@
 	void setFramenumber(int framenumber) { this->m_framenumber = framenumber; }
 	void setSmooth(bool smooth) { this->m_do_smooth = smooth; }
 	void setFeather(bool feather) { this->m_do_feather = feather; }
+	void setMotionBlurSamples(int samples) { this->m_rasterMaskHandleTot = max(1, samples); }
 
 #ifdef USE_RASKTER
 	void *initializeTileData(rcti *rect);

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2012-07-27 08:58:34 UTC (rev 49277)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2012-07-27 09:32:47 UTC (rev 49278)
@@ -2490,19 +2490,23 @@
 
 static void node_composit_buts_mask(uiLayout *layout, bContext *C, PointerRNA *ptr)
 {
+	bNode *node = ptr->data;
+
 	uiTemplateID(layout, C, ptr, "mask", NULL, NULL, NULL);
 	uiItemR(layout, ptr, "use_antialiasing", 0, NULL, ICON_NONE);
 	uiItemR(layout, ptr, "use_feather", 0, NULL, ICON_NONE);
 
 	uiItemR(layout, ptr, "size_source", 0, "", ICON_NONE);
 
-	{
-		bNode *node = ptr->data;
-		if (node->custom1 & (CMP_NODEFLAG_MASK_FIXED | CMP_NODEFLAG_MASK_FIXED_SCENE)) {
-			uiItemR(layout, ptr, "size_x", 0, NULL, ICON_NONE);
-			uiItemR(layout, ptr, "size_y", 0, NULL, ICON_NONE);
-		}
+	if (node->custom1 & (CMP_NODEFLAG_MASK_FIXED | CMP_NODEFLAG_MASK_FIXED_SCENE)) {
+		uiItemR(layout, ptr, "size_x", 0, NULL, ICON_NONE);
+		uiItemR(layout, ptr, "size_y", 0, NULL, ICON_NONE);
 	}
+
+	uiItemR(layout, ptr, "use_motion_blur", 0, NULL, ICON_NONE);
+	if (node->custom1 & CMP_NODEFLAG_MASK_MOTION_BLUR) {
+		uiItemR(layout, ptr, "motion_blur_samples", 0, NULL, ICON_NONE);
+	}
 }
 
 static void node_composit_buts_keyingscreen(uiLayout *layout, bContext *C, PointerRNA *ptr)

Modified: trunk/blender/source/blender/makesdna/DNA_node_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_node_types.h	2012-07-27 08:58:34 UTC (rev 49277)
+++ trunk/blender/source/blender/makesdna/DNA_node_types.h	2012-07-27 09:32:47 UTC (rev 49278)
@@ -375,8 +375,9 @@
 };
 
 enum {
-	CMP_NODEFLAG_MASK_AA         = (1 << 0),
-	CMP_NODEFLAG_MASK_NO_FEATHER = (1 << 1),
+	CMP_NODEFLAG_MASK_AA          = (1 << 0),
+	CMP_NODEFLAG_MASK_NO_FEATHER  = (1 << 1),
+	CMP_NODEFLAG_MASK_MOTION_BLUR = (1 << 2),
 
 	/* we may want multiple aspect options, exposed as an rna enum */
 	CMP_NODEFLAG_MASK_FIXED       = (1 << 8),

Modified: trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2012-07-27 08:58:34 UTC (rev 49277)
+++ trunk/blender/source/blender/makesrna/intern/rna_nodetree.c	2012-07-27 09:32:47 UTC (rev 49278)
@@ -3184,6 +3184,17 @@
 	RNA_def_property_ui_text(prop, "Feather", "Use feather information from the mask");
 	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 
+	prop = RNA_def_property(srna, "use_motion_blur", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "custom1", CMP_NODEFLAG_MASK_MOTION_BLUR);
+	RNA_def_property_ui_text(prop, "Motion Blur", "Use feather information from the mask");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+	prop = RNA_def_property(srna, "motion_blur_samples", PROP_INT, PROP_NONE);
+	RNA_def_property_int_sdna(prop, NULL, "custom2");
+	RNA_def_property_range(prop, 1, 32);
+	RNA_def_property_ui_text(prop, "Samples", "Number of motion blur samples");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
 	prop = RNA_def_property(srna, "size_source", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_bitflag_sdna(prop, NULL, "custom1");
 	RNA_def_property_enum_items(prop, aspect_type_items);




More information about the Bf-blender-cvs mailing list