[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43225] branches/tile/source/blender/ compositor: Refactor of Distance Matte Node/Operation

Dalai Felinto dfelinto at gmail.com
Sun Jan 8 21:30:24 CET 2012


Revision: 43225
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43225
Author:   dfelinto
Date:     2012-01-08 20:30:12 +0000 (Sun, 08 Jan 2012)
Log Message:
-----------
Refactor of Distance Matte Node/Operation
reinforcing that all Matte operations should output the alpha channel (VALUE).
thus it needs the SetAlpha operation (instead of the split Alpha)

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

Modified: branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp	2012-01-08 19:51:14 UTC (rev 43224)
+++ branches/tile/source/blender/compositor/nodes/COM_DistanceMatteNode.cpp	2012-01-08 20:30:12 UTC (rev 43225)
@@ -22,7 +22,7 @@
 #include "COM_DistanceMatteNode.h"
 #include "BKE_node.h"
 #include "COM_DistanceMatteOperation.h"
-#include "COM_SeparateChannelOperation.h"
+#include "COM_SetAlphaOperation.h"
 
 DistanceMatteNode::DistanceMatteNode(bNode *editorNode): Node(editorNode)
 {}
@@ -40,18 +40,20 @@
 	inputSocketImage->relinkConnections(operation->getInputSocket(0), true, 0, graph);
 	inputSocketKey->relinkConnections(operation->getInputSocket(1), true, 1, graph);
 
+	if (outputSocketMatte->isConnected()) {
+		outputSocketMatte->relinkConnections(operation->getOutputSocket());
+	}
+
 	graph->addOperation(operation);
-	addPreviewOperation(graph, operation->getOutputSocket(), 9);
 
+	SetAlphaOperation *operationAlpha = new SetAlphaOperation();
+	addLink(graph, operation->getInputSocket(0)->getConnection()->getFromSocket(), operationAlpha->getInputSocket(0));
+	addLink(graph, operation->getOutputSocket(), operationAlpha->getInputSocket(1));
+
+	graph->addOperation(operationAlpha);
+	addPreviewOperation(graph, operationAlpha->getOutputSocket(), 9);
+
 	if (outputSocketImage->isConnected()) {
-		outputSocketImage->relinkConnections(operation->getOutputSocket());
+		outputSocketImage->relinkConnections(operationAlpha->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);
-	}
 }

Modified: branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp	2012-01-08 19:51:14 UTC (rev 43224)
+++ branches/tile/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp	2012-01-08 20:30:12 UTC (rev 43225)
@@ -27,7 +27,7 @@
 DistanceMatteOperation::DistanceMatteOperation(): NodeOperation() {
 	addInputSocket(COM_DT_COLOR);
 	addInputSocket(COM_DT_COLOR);
-	addOutputSocket(COM_DT_COLOR);
+	addOutputSocket(COM_DT_VALUE);
 
 	inputImageProgram = NULL;
 	inputKeyProgram = NULL;
@@ -45,6 +45,7 @@
 
 void DistanceMatteOperation::executePixel(float* outputValue, float x, float y, MemoryBuffer *inputBuffers[]) {
 	float inKey[4];
+	float inImage[4];
 
 	const float tolerence=this->settings->t1;
 	const float falloff=this->settings->t2;
@@ -53,29 +54,35 @@
 	float alpha;
 
 	this->inputKeyProgram->read(inKey, x, y, inputBuffers);
-	this->inputImageProgram->read(outputValue, x, y, inputBuffers);
+	this->inputImageProgram->read(inImage, x, y, inputBuffers);
 	
-	distance = sqrt(pow((inKey[0]-outputValue[0]),2)+
-	                pow((inKey[1]-outputValue[1]),2)+
-	                pow((inKey[2]-outputValue[2]),2));
+	distance = sqrt(pow((inKey[0]-inImage[0]),2)+
+	                pow((inKey[1]-inImage[1]),2)+
+	                pow((inKey[2]-inImage[2]),2));
+
+	/* store matte(alpha) value in [0] to go with
+	 * COM_SetAlphaOperation and the Value output
+	 */
  
 	/*make 100% transparent */
 	if(distance < tolerence) {
-		outputValue[3]=0.f;
+		outputValue[0]=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;
+		if(alpha < inImage[3]) {
+			outputValue[0]=alpha;
 		}
 		else { /* leave as before */
+			outputValue[0]=inImage[3];
 		}
 	}
 	else {
 	/* leave as before */
+		outputValue[0]=inImage[3];
 	}
 }
 



More information about the Bf-blender-cvs mailing list