[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43667] branches/tile/source/blender/ compositor: Displace Node - Tile

Dalai Felinto dfelinto at gmail.com
Tue Jan 24 17:45:53 CET 2012


Revision: 43667
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43667
Author:   dfelinto
Date:     2012-01-24 16:45:42 +0000 (Tue, 24 Jan 2012)
Log Message:
-----------
Displace Node - Tile
--------------------
I had to make it into a Complex node to allow the readEWA to be used.
(the other alternative is to expose readEWA to all node types when dx and dy are
passed as parameter to read).

This node also uses the readEWA. It's the last one that needs that (from trunk nodes at least)

Thanks for Jeroen Bakker for the help in the determineDependingAreaOfInterest. Using +1 as max for the uv was producing precision problems resulting in a strange artifact (a vertical and a horizontal line from the origin (0,0))

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_DisplaceNode.cpp
    branches/tile/source/blender/compositor/nodes/COM_DisplaceNode.h
    branches/tile/source/blender/compositor/operations/COM_DisplaceOperation.cpp
    branches/tile/source/blender/compositor/operations/COM_DisplaceOperation.h

Modified: branches/tile/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-24 16:32:31 UTC (rev 43666)
+++ branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-24 16:45:42 UTC (rev 43667)
@@ -152,6 +152,8 @@
 
 		nodes/COM_MapUVNode.cpp
 		nodes/COM_MapUVNode.h
+		nodes/COM_DisplaceNode.cpp
+		nodes/COM_DisplaceNode.h
 
 		nodes/COM_DifferenceMatteNode.cpp
 		nodes/COM_DifferenceMatteNode.h
@@ -478,6 +480,8 @@
 		operations/COM_ScaleOperation.cpp
 		operations/COM_MapUVOperation.h
 		operations/COM_MapUVOperation.cpp
+		operations/COM_DisplaceOperation.h
+		operations/COM_DisplaceOperation.cpp
 		operations/COM_FlipOperation.h
 		operations/COM_FlipOperation.cpp
 		operations/COM_ProjectorLensDistortionOperation.cpp

Modified: branches/tile/source/blender/compositor/intern/COM_Converter.cpp
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-24 16:32:31 UTC (rev 43666)
+++ branches/tile/source/blender/compositor/intern/COM_Converter.cpp	2012-01-24 16:45:42 UTC (rev 43667)
@@ -65,6 +65,7 @@
 #include "COM_DilateErode2Node.h"
 #include "COM_SetAlphaNode.h"
 #include "COM_MapUVNode.h"
+#include "COM_DisplaceNode.h"
 #include "COM_MathNode.h"
 #include "COM_HueSaturationValueNode.h"
 #include "COM_HueSaturationValueCorrectNode.h"
@@ -225,9 +226,12 @@
 	case CMP_NODE_HUECORRECT:
 		node = new HueSaturationValueCorrectNode(bNode);
 		break;
-    case CMP_NODE_MAP_UV:
-        node = new MapUVNode(bNode);
-        break;
+	case CMP_NODE_MAP_UV:
+		node = new MapUVNode(bNode);
+		break;
+	case CMP_NODE_DISPLACE:
+		node = new DisplaceNode(bNode);
+		break;
 	case CMP_NODE_VALTORGB:
 		node = new ColorRampNode(bNode);
 		break;
@@ -300,7 +304,6 @@
 	case CMP_NODE_CHANNEL_MATTE:
 //	case CMP_NODE_DOUBLEEDGEMASK: // to be re-enabled with next merge from trunk
 	case CMP_NODE_DEFOCUS:
-	case CMP_NODE_DISPLACE:
 	case CMP_NODE_NORMALIZE:
 	case CMP_NODE_CROP:
 	case CMP_NODE_BILATERALBLUR:

Added: branches/tile/source/blender/compositor/nodes/COM_DisplaceNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_DisplaceNode.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_DisplaceNode.cpp	2012-01-24 16:45:42 UTC (rev 43667)
@@ -0,0 +1,39 @@
+/*
+ * 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_DisplaceNode.h"
+#include "COM_DisplaceOperation.h"
+#include "COM_ExecutionSystem.h"
+
+DisplaceNode::DisplaceNode(bNode *editorNode): Node(editorNode) {
+}
+
+void DisplaceNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context) {
+	DisplaceOperation *operation = new DisplaceOperation();
+
+	this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), true, 0, graph);
+	this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), true, 1, graph);
+	this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), true, 2, graph);
+	this->getInputSocket(3)->relinkConnections(operation->getInputSocket(3), true, 3, graph);
+	this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
+
+	graph->addOperation(operation);
+}


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

Added: branches/tile/source/blender/compositor/nodes/COM_DisplaceNode.h
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_DisplaceNode.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/nodes/COM_DisplaceNode.h	2012-01-24 16:45:42 UTC (rev 43667)
@@ -0,0 +1,36 @@
+/*
+ * 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_DisplaceNode_h
+#define _COM_DisplaceNode_h
+
+#include "COM_Node.h"
+
+/**
+ * @brief DisplaceNode
+ * @ingroup Node
+ */
+class DisplaceNode : public Node {
+public:
+	DisplaceNode(bNode *editorNode);
+	void convertToOperations(ExecutionSystem *graph, CompositorContext * context);
+};
+#endif


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

Added: branches/tile/source/blender/compositor/operations/COM_DisplaceOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_DisplaceOperation.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_DisplaceOperation.cpp	2012-01-24 16:45:42 UTC (rev 43667)
@@ -0,0 +1,152 @@
+/*
+ * 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_DisplaceOperation.h"
+#include "BLI_math.h"
+
+DisplaceOperation::DisplaceOperation(): NodeOperation() {
+	this->addInputSocket(COM_DT_COLOR);
+	this->addInputSocket(COM_DT_VECTOR);
+	this->addInputSocket(COM_DT_VALUE);
+	this->addInputSocket(COM_DT_VALUE);
+	this->addOutputSocket(COM_DT_COLOR);
+	this->setComplex(true);
+
+	this->inputColorProgram = NULL;
+	this->inputVectorProgram = NULL;
+	this->inputScaleXProgram = NULL;
+	this->inputScaleYProgram = NULL;
+}
+
+void DisplaceOperation::initExecution() {
+	this->inputColorProgram = this->getInputSocketReader(0);
+	this->inputVectorProgram = this->getInputSocketReader(1);
+	this->inputScaleXProgram = this->getInputSocketReader(2);
+	this->inputScaleYProgram = this->getInputSocketReader(3);
+
+	width_x4 = this->width * 4;
+	height_x4 = this->height * 4;
+}
+
+
+/* minimum distance (in pixels) a pixel has to be displaced
+ * in order to take effect */
+#define DISPLACE_EPSILON	0.01f
+
+void DisplaceOperation::executePixel(float* color, int x, int y, MemoryBuffer *inputBuffers[], void* data)
+{
+	float inVector[4];
+	float inScale[4];
+
+	float p_dx, p_dy;	/* main displacement in pixel space */
+	float d_dx, d_dy;
+	float dxt, dyt;
+	float u, v;
+
+	this->inputScaleXProgram->read(inScale, x, y, inputBuffers);
+	float xs = inScale[0];
+	this->inputScaleYProgram->read(inScale, x, y, inputBuffers);
+	float ys = inScale[0];
+
+	/* clamp x and y displacement to triple image resolution - 
+	 * to prevent hangs from huge values mistakenly plugged in eg. z buffers */
+	xs = min(width_x4, max(-width_x4, xs));
+	ys = min(height_x4, max(-height_x4, ys));
+
+	this->inputVectorProgram->read(inVector, x, y, inputBuffers);
+	p_dx = inVector[0] * xs;
+	p_dy = inVector[1] * ys;
+
+	/* if no displacement, then just copy this pixel */
+	if (fabsf(p_dx) < DISPLACE_EPSILON && fabsf(p_dy) < DISPLACE_EPSILON) {
+		this->inputColorProgram->read(color, x, y, inputBuffers);
+		return;
+	}
+
+	/* displaced pixel in uv coords, for image sampling */
+	u = x - p_dx + 0.5f;
+	v = y - p_dy + 0.5f;
+
+	/* calc derivatives */
+	this->inputVectorProgram->read(inVector, x+1, y, inputBuffers);
+	d_dx = inVector[0] * xs;
+	this->inputVectorProgram->read(inVector, x, y+1, inputBuffers);
+	d_dy = inVector[0] * ys;
+
+	/* clamp derivatives to minimum displacement distance in UV space */
+	dxt = p_dx - d_dx;
+	dyt = p_dy - d_dy;
+
+	dxt = signf(dxt)*maxf(fabsf(dxt), DISPLACE_EPSILON)/this->width;
+	dyt = signf(dyt)*maxf(fabsf(dyt), DISPLACE_EPSILON)/this->height;
+
+	/* EWA filtering */
+	this->inputColorProgram->read(color, u, v, dxt, dyt, inputBuffers);
+}
+
+void DisplaceOperation::deinitExecution() {
+	this->inputColorProgram = NULL;
+	this->inputVectorProgram = NULL;
+	this->inputScaleXProgram = NULL;
+	this->inputScaleYProgram = NULL;
+}
+
+bool DisplaceOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) {
+	rcti colorInput;
+	rcti vectorInput;
+	NodeOperation *operation=NULL;
+
+	/* the vector buffer only needs a 2x2 buffer. The image needs whole buffer */
+	/* image */
+	operation = getInputOperation(0);
+	colorInput.xmax = operation->getWidth();
+	colorInput.xmin = 0;
+	colorInput.ymax = operation->getHeight();
+	colorInput.ymin = 0;

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list