[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [55093] trunk/blender: Border for compositor viewer node feature

Sergey Sharybin sergey.vfx at gmail.com
Thu Mar 7 18:47:30 CET 2013


Revision: 55093
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=55093
Author:   nazgul
Date:     2013-03-07 17:47:30 +0000 (Thu, 07 Mar 2013)
Log Message:
-----------
Border for compositor viewer node feature

This adds border option to compositor, which affects on
a backdrop and viewer nodes, which is useful for faster
previews and tweaks.

Final compositing still happens for the whole frame, but
if it'll be needed it's not so difficult to support it
as well.

To use border there's Ctrl-B shortcut in the compositor
editor, which i used to define region you want to restrict
compositing to. There's also "Viewer Border" option in
the N-panel in case you'll want to disable border
compositing.

Some areas could be cleaned a bit, like ideally it shall
not be viewer image clearing in viewer_border_update RNA
callback, but currently it's not so much clear how to
make it the same fast as simple memset and glue it
somehow to compositor. Will think of nicer solution a
bit later.

Modified Paths:
--------------
    trunk/blender/release/scripts/startup/bl_ui/space_node.py
    trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp
    trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h
    trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
    trunk/blender/source/blender/editors/space_node/drawnode.c
    trunk/blender/source/blender/editors/space_node/node_edit.c
    trunk/blender/source/blender/editors/space_node/node_intern.h
    trunk/blender/source/blender/editors/space_node/node_ops.c
    trunk/blender/source/blender/makesdna/DNA_node_types.h
    trunk/blender/source/blender/makesrna/intern/rna_nodetree.c
    trunk/blender/source/blender/windowmanager/intern/wm_operators.c

Modified: trunk/blender/release/scripts/startup/bl_ui/space_node.py
===================================================================
--- trunk/blender/release/scripts/startup/bl_ui/space_node.py	2013-03-07 16:57:53 UTC (rev 55092)
+++ trunk/blender/release/scripts/startup/bl_ui/space_node.py	2013-03-07 17:47:30 UTC (rev 55093)
@@ -254,6 +254,7 @@
         col.prop(tree, "use_opencl")
         col.prop(tree, "use_groupnode_buffer")
         col.prop(tree, "two_pass")
+        col.prop(tree, "use_viewer_border")
         col.prop(snode, "show_highlight")
         col.prop(snode, "use_hidden_preview")
 

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp	2013-03-07 16:57:53 UTC (rev 55092)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.cpp	2013-03-07 17:47:30 UTC (rev 55093)
@@ -60,6 +60,7 @@
 	this->m_openCL = false;
 	this->m_singleThreaded = false;
 	this->m_chunksFinished = 0;
+	BLI_rcti_init(&this->m_viewerBorder, 0, 0, 0, 0);
 }
 
 CompositorPriority ExecutionGroup::getRenderPriotrity()
@@ -196,6 +197,7 @@
 	resolution[0] = operation->getWidth();
 	resolution[1] = operation->getHeight();
 	this->setResolution(resolution);
+	BLI_rcti_init(&this->m_viewerBorder, 0, this->m_width, 0, this->m_height);
 }
 
 void ExecutionGroup::determineNumberOfChunks()
@@ -207,8 +209,10 @@
 	}
 	else {
 		const float chunkSizef = this->m_chunkSize;
-		this->m_numberOfXChunks = ceil(this->m_width / chunkSizef);
-		this->m_numberOfYChunks = ceil(this->m_height / chunkSizef);
+		const int border_width = BLI_rcti_size_x(&this->m_viewerBorder);
+		const int border_height = BLI_rcti_size_y(&this->m_viewerBorder);
+		this->m_numberOfXChunks = ceil(border_width / chunkSizef);
+		this->m_numberOfYChunks = ceil(border_height / chunkSizef);
 		this->m_numberOfChunks = this->m_numberOfXChunks * this->m_numberOfYChunks;
 	}
 }
@@ -245,6 +249,9 @@
 		chunkorder = viewer->getChunkOrder();
 	}
 
+	const int border_width = BLI_rcti_size_x(&this->m_viewerBorder);
+	const int border_height = BLI_rcti_size_y(&this->m_viewerBorder);
+
 	switch (chunkorder) {
 		case COM_TO_RANDOM:
 			for (index = 0; index < 2 * this->m_numberOfChunks; index++) {
@@ -258,14 +265,14 @@
 		case COM_TO_CENTER_OUT:
 		{
 			ChunkOrderHotspot *hotspots[1];
-			hotspots[0] = new ChunkOrderHotspot(this->m_width * centerX, this->m_height * centerY, 0.0f);
+			hotspots[0] = new ChunkOrderHotspot(border_width * centerX, border_height * centerY, 0.0f);
 			rcti rect;
 			ChunkOrder *chunkOrders = (ChunkOrder *)MEM_mallocN(sizeof(ChunkOrder) * this->m_numberOfChunks, __func__);
 			for (index = 0; index < this->m_numberOfChunks; index++) {
 				determineChunkRect(&rect, index);
 				chunkOrders[index].setChunkNumber(index);
-				chunkOrders[index].setX(rect.xmin);
-				chunkOrders[index].setY(rect.ymin);
+				chunkOrders[index].setX(rect.xmin - this->m_viewerBorder.xmin);
+				chunkOrders[index].setY(rect.ymin - this->m_viewerBorder.ymin);
 				chunkOrders[index].determineDistance(hotspots, 1);
 			}
 
@@ -281,10 +288,10 @@
 		case COM_TO_RULE_OF_THIRDS:
 		{
 			ChunkOrderHotspot *hotspots[9];
-			unsigned int tx = this->m_width / 6;
-			unsigned int ty = this->m_height / 6;
-			unsigned int mx = this->m_width / 2;
-			unsigned int my = this->m_height / 2;
+			unsigned int tx = border_width / 6;
+			unsigned int ty = border_height / 6;
+			unsigned int mx = border_width / 2;
+			unsigned int my = border_height / 2;
 			unsigned int bx = mx + 2 * tx;
 			unsigned int by = my + 2 * ty;
 
@@ -303,8 +310,8 @@
 			for (index = 0; index < this->m_numberOfChunks; index++) {
 				determineChunkRect(&rect, index);
 				chunkOrders[index].setChunkNumber(index);
-				chunkOrders[index].setX(rect.xmin);
-				chunkOrders[index].setY(rect.ymin);
+				chunkOrders[index].setX(rect.xmin - this->m_viewerBorder.xmin);
+				chunkOrders[index].setY(rect.ymin - this->m_viewerBorder.ymin);
 				chunkOrders[index].determineDistance(hotspots, 9);
 			}
 
@@ -431,13 +438,18 @@
 
 inline void ExecutionGroup::determineChunkRect(rcti *rect, const unsigned int xChunk, const unsigned int yChunk) const
 {
+	const int border_width = BLI_rcti_size_x(&this->m_viewerBorder);
+	const int border_height = BLI_rcti_size_y(&this->m_viewerBorder);
+
 	if (this->m_singleThreaded) {
-		BLI_rcti_init(rect, 0, this->m_width, 0, this->m_height);
+		BLI_rcti_init(rect, this->m_viewerBorder.xmin, border_width, this->m_viewerBorder.ymin, border_height);
 	}
 	else {
-		const unsigned int minx = xChunk * this->m_chunkSize;
-		const unsigned int miny = yChunk * this->m_chunkSize;
-		BLI_rcti_init(rect, minx, min(minx + this->m_chunkSize, this->m_width), miny, min(miny + this->m_chunkSize, this->m_height));
+		const unsigned int minx = xChunk * this->m_chunkSize + this->m_viewerBorder.xmin;
+		const unsigned int miny = yChunk * this->m_chunkSize + this->m_viewerBorder.ymin;
+		const unsigned int width = min((unsigned int) this->m_viewerBorder.xmax, this->m_width);
+		const unsigned int height = min((unsigned int) this->m_viewerBorder.ymax, this->m_height);
+		BLI_rcti_init(rect, min(minx, this->m_width), min(minx + this->m_chunkSize, width), min(miny, this->m_height), min(miny + this->m_chunkSize, height));
 	}
 }
 
@@ -472,9 +484,9 @@
 	float chunkSizef = this->m_chunkSize;
 
 	int indexx, indexy;
-	int minxchunk = floor(area->xmin / chunkSizef);
+	int minxchunk = floor((area->xmin - this->m_viewerBorder.xmin) / chunkSizef);
 	int maxxchunk = ceil((area->xmax - 1) / chunkSizef);
-	int minychunk = floor(area->ymin / chunkSizef);
+	int minychunk = floor((area->ymin - this->m_viewerBorder.ymin) / chunkSizef);
 	int maxychunk = ceil((area->ymax - 1) / chunkSizef);
 	minxchunk = max(minxchunk, 0);
 	minychunk = max(minychunk, 0);
@@ -574,3 +586,13 @@
 {
 	return this->m_openCL;
 }
+
+void ExecutionGroup::setViewerBorder(float xmin, float xmax, float ymin, float ymax)
+{
+	NodeOperation *operation = this->getOutputNodeOperation();
+
+	if (operation->isViewerOperation()) {
+		BLI_rcti_init(&this->m_viewerBorder, xmin * this->m_width, xmax * this->m_width,
+		              ymin * this->m_height, ymax * this->m_height);
+	}
+}

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h	2013-03-07 16:57:53 UTC (rev 55092)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionGroup.h	2013-03-07 17:47:30 UTC (rev 55093)
@@ -161,6 +161,12 @@
 	 * @see openCL
 	 */
 	bool m_initialized;
+
+	/**
+	 * @brief denotes boundary for border compositing
+	 * @note measured in pixel space
+	 */
+	rcti m_viewerBorder;
 	
 	// methods
 	/**
@@ -395,6 +401,12 @@
 	 */
 	CompositorPriority getRenderPriotrity();
 
+	/**
+	 * @brief set border for viewer operation
+	 * @note all the coordinates are assumed to be in normalized space
+	 */
+	void setViewerBorder(float xmin, float xmax, float ymin, float ymax);
+
 #ifdef WITH_CXX_GUARDEDALLOC
 	MEM_CXX_CLASS_ALLOC_FUNCS("COM:ExecutionGroup")
 #endif

Modified: trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp
===================================================================
--- trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2013-03-07 16:57:53 UTC (rev 55092)
+++ trunk/blender/source/blender/compositor/intern/COM_ExecutionSystem.cpp	2013-03-07 17:47:30 UTC (rev 55093)
@@ -78,11 +78,22 @@
 	this->groupOperations(); /* group operations in ExecutionGroups */
 	unsigned int index;
 	unsigned int resolution[2];
+
+	rctf *viewer_border = &editingtree->viewer_border;
+	bool use_viewer_border = (editingtree->flag & NTREE_VIEWER_BORDER) &&
+	                         viewer_border->xmin < viewer_border->xmax &&
+	                         viewer_border->ymin < viewer_border->ymax;
+
 	for (index = 0; index < this->m_groups.size(); index++) {
 		resolution[0] = 0;
 		resolution[1] = 0;
 		ExecutionGroup *executionGroup = this->m_groups[index];
 		executionGroup->determineResolution(resolution);
+
+		if (use_viewer_border) {
+			executionGroup->setViewerBorder(viewer_border->xmin, viewer_border->xmax,
+			                                viewer_border->ymin, viewer_border->ymax);
+		}
 	}
 
 #ifdef COM_DEBUG

Modified: trunk/blender/source/blender/editors/space_node/drawnode.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/drawnode.c	2013-03-07 16:57:53 UTC (rev 55092)
+++ trunk/blender/source/blender/editors/space_node/drawnode.c	2013-03-07 17:47:30 UTC (rev 55093)
@@ -3320,6 +3320,7 @@
 			/** @note draw selected info on backdrop */
 			if (snode->edittree) {
 				bNode *node = snode->edittree->nodes.first;
+				rctf *viewer_border = &snode->edittree->viewer_border;
 				while (node) {
 					if (node->flag & NODE_SELECT) {
 						if (node->typeinfo->uibackdropfunc) {
@@ -3328,6 +3329,23 @@
 					}
 					node = node->next;
 				}
+
+				if ((snode->edittree->flag & NTREE_VIEWER_BORDER) &&
+					viewer_border->xmin < viewer_border->xmax &&
+				    viewer_border->ymin < viewer_border->ymax)
+				{
+					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+					setlinestyle(3);
+					cpack(0x4040FF);
+
+					glRectf(x + snode->zoom * viewer_border->xmin * ibuf->x,
+							y + snode->zoom * viewer_border->ymin * ibuf->y,
+					        x + snode->zoom * viewer_border->xmax * ibuf->x,
+							y + snode->zoom * viewer_border->ymax * ibuf->y);
+
+					setlinestyle(0);
+					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+				}
 			}
 			
 			glMatrixMode(GL_PROJECTION);

Modified: trunk/blender/source/blender/editors/space_node/node_edit.c
===================================================================
--- trunk/blender/source/blender/editors/space_node/node_edit.c	2013-03-07 16:57:53 UTC (rev 55092)
+++ trunk/blender/source/blender/editors/space_node/node_edit.c	2013-03-07 17:47:30 UTC (rev 55093)
@@ -73,6 +73,8 @@
 
 #include "GPU_material.h"
 
+#include "IMB_imbuf_types.h"
+
 #include "node_intern.h"  /* own include */
 
 #define USE_ESC_COMPO
@@ -2281,3 +2283,105 @@
 	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 }
 
+/* ********************** Viewer border ******************/
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list