[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43215] branches/tile/source/blender/ compositor: Distance Matte node - Tile

Dalai Felinto dfelinto at gmail.com
Sun Jan 8 03:12:15 CET 2012


Revision: 43215
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43215
Author:   dfelinto
Date:     2012-01-08 02:11:59 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
Distance Matte node - Tile
this matte operation is outputting RGBA (in oppose to only the A value as some other mattes).
The reason for this is to avoid and extra operation to get the main output ready (which is always needed
for the preview so we may as well get it done).

Instead of using the SetAlphaOperation I'm using SeparateChannel to extract the alpha from the output
of the Distance Matte operation.

Jeroen, I think it's simpler if I go ahead and commit the nodes if I think they are good.
If there are problems it'll be simpler to fix in svn since they should be small.

Modified Paths:
--------------
    branches/tile/source/blender/compositor/CMakeLists.txt
    branches/tile/source/blender/compositor/intern/COM_Converter.cpp

Added Paths:
-----------
    branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp
    branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.h
    branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp
    branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.h

Modified: branches/tile/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-07 21:16:15 UTC (rev 43214)
+++ branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-08 02:11:59 UTC (rev 43215)
@@ -157,6 +157,8 @@
 		nodes/COM_DifferenceMatteNode.h
 		nodes/COM_LuminanceMatteNode.cpp
 		nodes/COM_LuminanceMatteNode.h
+		nodes/COM_DistanceMatteNode.cpp
+		nodes/COM_DistanceMatteNode.h
 		nodes/COM_LensDistortionNode.cpp
 		nodes/COM_LensDistortionNode.h
 
@@ -369,10 +371,12 @@
 	operations/COM_CurveBaseOperation.cpp
 	operations/COM_HueSaturationValueCorrectOperation.cpp
 	operations/COM_HueSaturationValueCorrectOperation.h
+	operations/COM_DifferenceMatteOperation.cpp
 	operations/COM_DifferenceMatteOperation.h
-	operations/COM_DifferenceMatteOperation.cpp
+	operations/COM_LuminanceMatteOperation.cpp
 	operations/COM_LuminanceMatteOperation.h
-	operations/COM_LuminanceMatteOperation.cpp
+	operations/COM_DistanceMatteOperation.cpp
+	operations/COM_DistanceMatteOperation.h
 
 	operations/COM_ReadBufferOperation.cpp
 	operations/COM_ReadBufferOperation.h

Modified: branches/tile/source/blender/compositor/intern/COM_Converter.cpp
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-07 21:16:15 UTC (rev 43214)
+++ branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-08 02:11:59 UTC (rev 43215)
@@ -71,6 +71,7 @@
 #include "COM_ColorRampNode.h"
 #include "COM_DifferenceMatteNode.h"
 #include "COM_LuminanceMatteNode.h"
+#include "COM_DistanceMatteNode.h"
 #include "COM_BlurNode.h"
 #include "COM_BokehBlurNode.h"
 #include "COM_DilateErodeNode.h"
@@ -218,6 +219,9 @@
 	case CMP_NODE_LUMA_MATTE:
 		node = new LuminanceMatteNode(bNode);
 		break;
+	case CMP_NODE_DIST_MATTE:
+		node = new DistanceMatteNode(bNode);
+		break;
 	case CMP_NODE_BLUR:
 		node = new BlurNode(bNode);
 		break;

Added: branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp	2012-01-08 02:11:59 UTC (rev 43215)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor:
+ *		Dalai Felinto
+ */
+
+#include "COM_DistanceMatteNode.h"
+#include "BKE_node.h"
+#include "COM_DistanceMatteOperation.h"
+#include "COM_SeparateChannelOperation.h"
+
+DistanceMatteNode::DistanceMatteNode(bNode *editorNode): Node(editorNode)
+{}
+
+void DistanceMatteNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) {
+	InputSocket *inputSocketImage = this->getInputSocket(0);
+	InputSocket *inputSocketKey = this->getInputSocket(1);
+	OutputSocket *outputSocketImage = this->getOutputSocket(0);
+	OutputSocket *outputSocketMatte = this->getOutputSocket(1);
+
+	DistanceMatteOperation *operation = new DistanceMatteOperation();
+	bNode* editorsnode = getbNode();
+	operation->setSettings((NodeChroma*)editorsnode->storage);
+
+	inputSocketImage->relinkConnections(operation->getInputSocket(0), true, 0, graph);
+	inputSocketKey->relinkConnections(operation->getInputSocket(1), true, 1, graph);
+
+	graph->addOperation(operation);
+	addPreviewOperation(graph, operation->getOutputSocket(), 9);
+
+	if (outputSocketImage->isConnected()) {
+		outputSocketImage->relinkConnections(operation->getOutputSocket());
+	}
+
+	if (outputSocketMatte->isConnected()) {
+		SeparateChannelOperation *operationAlpha = new SeparateChannelOperation();
+		operationAlpha->setChannel(3);
+		addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(0));
+		outputSocketMatte->relinkConnections(operationAlpha->getOutputSocket());
+		graph->addOperation(operationAlpha);
+	}
+}


Property changes on: branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp
___________________________________________________________________
Added: svn:eol
   + native

Added: branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.h
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.h	2012-01-08 02:11:59 UTC (rev 43215)
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor:
+ *		Dalai Felinto
+ */
+
+#ifndef COM_DistanceMatteNODE_H
+#define COM_DistanceMatteNODE_H
+
+#include "COM_Node.h"
+
+/**
+  * @brief DistanceMatteNode
+  * @ingroup Node
+  */
+class DistanceMatteNode : public Node
+{
+public:
+	DistanceMatteNode(bNode *editorNode);
+	void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
+};
+
+#endif // COM_DistanceMatteNODE_H


Property changes on: branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.h
___________________________________________________________________
Added: svn:eol
   + native

Added: branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp	2012-01-08 02:11:59 UTC (rev 43215)
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor:
+ *		Dalai Felinto
+ */
+
+#include "COM_DistanceMatteOperation.h"
+#include "COM_InputSocket.h"
+#include "COM_OutputSocket.h"
+#include "BLI_math.h"
+
+DistanceMatteOperation::DistanceMatteOperation(): NodeOperation() {
+	addInputSocket(COM_DT_COLOR);
+	addInputSocket(COM_DT_COLOR);
+	addOutputSocket(COM_DT_COLOR);
+
+	inputImageProgram = NULL;
+	inputKeyProgram = NULL;
+}
+
+void DistanceMatteOperation::initExecution() {
+	this->inputImageProgram = this->getInputSocketReader(0);
+	this->inputKeyProgram = this->getInputSocketReader(1);
+}
+
+void DistanceMatteOperation::deinitExecution() {
+	this->inputImageProgram= NULL;
+	this->inputKeyProgram= NULL;
+}
+
+void DistanceMatteOperation::executePixel(float* outputValue, float x, float y, MemoryBuffer *inputBuffers[]) {
+	float inKey[4];
+
+	const float tolerence=this->settings->t1;
+	const float falloff=this->settings->t2;
+
+	float distance;
+	float alpha;
+
+	this->inputKeyProgram->read(inKey, x, y, inputBuffers);
+	this->inputImageProgram->read(outputValue, x, y, inputBuffers);
+	
+	distance = sqrt(pow((inKey[0]-outputValue[0]),2)+
+	                pow((inKey[1]-outputValue[1]),2)+
+	                pow((inKey[2]-outputValue[2]),2));
+ 
+	/*make 100% transparent */
+	if(distance < tolerence) {
+		outputValue[3]=0.f;
+	}
+	/*in the falloff region, make partially transparent */
+	else if(distance < falloff+tolerence){
+		distance=distance-tolerence;
+		alpha=distance/falloff;
+		/*only change if more transparent than before */
+		if(alpha < outputValue[3]) {
+			outputValue[3]=alpha;
+		}
+		else { /* leave as before */
+		}
+	}
+	else {
+	/* leave as before */
+	}
+}
+


Property changes on: branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp
___________________________________________________________________
Added: svn:eol
   + native

Added: branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.h
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.h	2012-01-08 02:11:59 UTC (rev 43215)
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2011, Blender Foundation.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list