[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [49357] trunk/blender/source/blender/ compositor: Support for depth buffers in compositor and viewer node

Jeroen Bakker j.bakker at atmind.nl
Sun Jul 29 17:06:51 CEST 2012


Revision: 49357
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=49357
Author:   jbakker
Date:     2012-07-29 15:06:50 +0000 (Sun, 29 Jul 2012)
Log Message:
-----------
Support for depth buffers in compositor and viewer node
Support for only alpha images in compositor and viewer node

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp
    trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp
    trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h
    trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h
    trunk/blender/source/blender/compositor/operations/COM_ViewerOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_ViewerOperation.h

Modified: trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp	2012-07-29 14:07:57 UTC (rev 49356)
+++ trunk/blender/source/blender/compositor/nodes/COM_CompositorNode.cpp	2012-07-29 15:06:50 UTC (rev 49357)
@@ -33,13 +33,14 @@
 {
 	InputSocket *imageSocket = this->getInputSocket(0);
 	InputSocket *alphaSocket = this->getInputSocket(1);
-	if (imageSocket->isConnected()) {
-		CompositorOperation *colorAlphaProg = new CompositorOperation();
-		colorAlphaProg->setRenderData(context->getRenderData());
-		colorAlphaProg->setbNodeTree(context->getbNodeTree());
-		imageSocket->relinkConnections(colorAlphaProg->getInputSocket(0));
-		alphaSocket->relinkConnections(colorAlphaProg->getInputSocket(1));
-		graph->addOperation(colorAlphaProg);
-		addPreviewOperation(graph, colorAlphaProg->getInputSocket(0));
-	}
+	InputSocket *depthSocket = this->getInputSocket(2);
+
+	CompositorOperation *compositorOperation = new CompositorOperation();
+	compositorOperation->setRenderData(context->getRenderData());
+	compositorOperation->setbNodeTree(context->getbNodeTree());
+	imageSocket->relinkConnections(compositorOperation->getInputSocket(0), 0, graph);
+	alphaSocket->relinkConnections(compositorOperation->getInputSocket(1));
+	depthSocket->relinkConnections(compositorOperation->getInputSocket(2));
+	graph->addOperation(compositorOperation);
+	addPreviewOperation(graph, compositorOperation->getInputSocket(0));
 }

Modified: trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp	2012-07-29 14:07:57 UTC (rev 49356)
+++ trunk/blender/source/blender/compositor/nodes/COM_ViewerNode.cpp	2012-07-29 15:06:50 UTC (rev 49357)
@@ -35,23 +35,32 @@
 {
 	InputSocket *imageSocket = this->getInputSocket(0);
 	InputSocket *alphaSocket = this->getInputSocket(1);
+	InputSocket *depthSocket = this->getInputSocket(2);
 	Image *image = (Image *)this->getbNode()->id;
 	ImageUser *imageUser = (ImageUser *) this->getbNode()->storage;
 	bNode *editorNode = this->getbNode();
-	if (imageSocket->isConnected()) {
-		ViewerOperation *viewerOperation = new ViewerOperation();
-		viewerOperation->setColorManagement(context->getRenderData()->color_mgt_flag & R_COLOR_MANAGEMENT);
-		viewerOperation->setColorPredivide(context->getRenderData()->color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE);
-		viewerOperation->setbNodeTree(context->getbNodeTree());
-		viewerOperation->setImage(image);
-		viewerOperation->setImageUser(imageUser);
-		viewerOperation->setActive((editorNode->flag & NODE_DO_OUTPUT) && this->isInActiveGroup());
-		viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1);
-		viewerOperation->setCenterX(editorNode->custom3);
-		viewerOperation->setCenterY(editorNode->custom4);
-		imageSocket->relinkConnections(viewerOperation->getInputSocket(0), 0, graph);
-		alphaSocket->relinkConnections(viewerOperation->getInputSocket(1));
-		graph->addOperation(viewerOperation);
-		addPreviewOperation(graph, viewerOperation->getInputSocket(0));
+	ViewerOperation *viewerOperation = new ViewerOperation();
+	viewerOperation->setColorManagement(context->getRenderData()->color_mgt_flag & R_COLOR_MANAGEMENT);
+	viewerOperation->setColorPredivide(context->getRenderData()->color_mgt_flag & R_COLOR_MANAGEMENT_PREDIVIDE);
+	viewerOperation->setbNodeTree(context->getbNodeTree());
+	viewerOperation->setImage(image);
+	viewerOperation->setImageUser(imageUser);
+	viewerOperation->setActive((editorNode->flag & NODE_DO_OUTPUT) && this->isInActiveGroup());
+	viewerOperation->setChunkOrder((OrderOfChunks)editorNode->custom1);
+	viewerOperation->setCenterX(editorNode->custom3);
+	viewerOperation->setCenterY(editorNode->custom4);
+
+	viewerOperation->setResolutionInputSocketIndex(0);
+	if (!imageSocket->isConnected())
+	{
+		if (alphaSocket->isConnected()) {
+			viewerOperation->setResolutionInputSocketIndex(1);
+		}
 	}
+
+	imageSocket->relinkConnections(viewerOperation->getInputSocket(0), 0, graph);
+	alphaSocket->relinkConnections(viewerOperation->getInputSocket(1));
+	depthSocket->relinkConnections(viewerOperation->getInputSocket(2));
+	graph->addOperation(viewerOperation);
+	addPreviewOperation(graph, viewerOperation->getInputSocket(0));
 }

Modified: trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp	2012-07-29 14:07:57 UTC (rev 49356)
+++ trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.cpp	2012-07-29 15:06:50 UTC (rev 49357)
@@ -41,11 +41,14 @@
 {
 	this->addInputSocket(COM_DT_COLOR);
 	this->addInputSocket(COM_DT_VALUE);
+	this->addInputSocket(COM_DT_VALUE);
 
 	this->setRenderData(NULL);
 	this->m_outputBuffer = NULL;
+	this->m_depthBuffer = NULL;
 	this->m_imageInput = NULL;
 	this->m_alphaInput = NULL;
+	this->m_depthInput = NULL;
 }
 
 void CompositorOperation::initExecution()
@@ -53,9 +56,13 @@
 	// When initializing the tree during initial load the width and height can be zero.
 	this->m_imageInput = getInputSocketReader(0);
 	this->m_alphaInput = getInputSocketReader(1);
+	this->m_depthInput = getInputSocketReader(2);
 	if (this->getWidth() * this->getHeight() != 0) {
 		this->m_outputBuffer = (float *) MEM_callocN(this->getWidth() * this->getHeight() * 4 * sizeof(float), "CompositorOperation");
 	}
+	if (this->m_depthInput != NULL) {
+		this->m_depthBuffer = (float *) MEM_callocN(this->getWidth() * this->getHeight() * sizeof(float), "CompositorOperation");
+	}
 }
 
 void CompositorOperation::deinitExecution()
@@ -70,11 +77,18 @@
 				MEM_freeN(rr->rectf);
 			}
 			rr->rectf = this->m_outputBuffer;
+			if (rr->rectz != NULL) {
+				MEM_freeN(rr->rectz);
+			}
+			rr->rectz = this->m_depthBuffer;
 		}
 		else {
 			if (this->m_outputBuffer) {
 				MEM_freeN(this->m_outputBuffer);
 			}
+			if (this->m_depthBuffer) {
+				MEM_freeN(this->m_depthBuffer);
+			}
 		}
 
 		BLI_lock_thread(LOCK_DRAW_IMAGE);
@@ -90,11 +104,16 @@
 		if (this->m_outputBuffer) {
 			MEM_freeN(this->m_outputBuffer);
 		}
+		if (this->m_depthBuffer) {
+			MEM_freeN(this->m_depthBuffer);
+		}
 	}
 
 	this->m_outputBuffer = NULL;
+	this->m_depthBuffer = NULL;
 	this->m_imageInput = NULL;
 	this->m_alphaInput = NULL;
+	this->m_depthInput = NULL;
 }
 
 
@@ -102,13 +121,16 @@
 {
 	float color[8]; // 7 is enough
 	float *buffer = this->m_outputBuffer;
+	float *zbuffer = this->m_depthBuffer;
 
 	if (!buffer) return;
 	int x1 = rect->xmin;
 	int y1 = rect->ymin;
 	int x2 = rect->xmax;
 	int y2 = rect->ymax;
-	int offset = (y1 * this->getWidth() + x1) * COM_NUMBER_OF_CHANNELS;
+	int offset = (y1 * this->getWidth() + x1);
+	int add = (this->getWidth() - (x2 - x1));
+	int offset4 = offset * COM_NUMBER_OF_CHANNELS;
 	int x;
 	int y;
 	bool breaked = false;
@@ -119,13 +141,20 @@
 			if (this->m_alphaInput != NULL) {
 				this->m_alphaInput->read(&(color[3]), x, y, COM_PS_NEAREST);
 			}
-			copy_v4_v4(buffer + offset, color);
-			offset += COM_NUMBER_OF_CHANNELS;
+			copy_v4_v4(buffer + offset4, color);
+
+			if (this->m_depthInput != NULL) {
+				this->m_depthInput->read(color, x, y, COM_PS_NEAREST);
+				zbuffer[offset] = color[0];
+			}
+			offset4 += COM_NUMBER_OF_CHANNELS;
+			offset++;
 			if (isBreaked()) {
 				breaked = true;
 			}
 		}
-		offset += (this->getWidth() - (x2 - x1)) * COM_NUMBER_OF_CHANNELS;
+		offset += add;
+		offset4 += add * COM_NUMBER_OF_CHANNELS;
 	}
 }
 

Modified: trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h	2012-07-29 14:07:57 UTC (rev 49356)
+++ trunk/blender/source/blender/compositor/operations/COM_CompositorOperation.h	2012-07-29 15:06:50 UTC (rev 49357)
@@ -42,6 +42,11 @@
 	float *m_outputBuffer;
 
 	/**
+	 * @brief reference to the output depth float buffer
+	 */
+	float *m_depthBuffer;
+
+	/**
 	 * @brief local reference to the input image operation
 	 */
 	SocketReader *m_imageInput;
@@ -50,6 +55,11 @@
 	 * @brief local reference to the input alpha operation
 	 */
 	SocketReader *m_alphaInput;
+
+	/**
+	 * @brief local reference to the depth operation
+	 */
+	SocketReader *m_depthInput;
 public:
 	CompositorOperation();
 	void executeRegion(rcti *rect, unsigned int tileNumber);

Modified: trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp	2012-07-29 14:07:57 UTC (rev 49356)
+++ trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp	2012-07-29 15:06:50 UTC (rev 49357)
@@ -43,9 +43,11 @@
 	this->setImage(NULL);
 	this->setImageUser(NULL);
 	this->m_outputBuffer = NULL;
+	this->m_depthBuffer = NULL;
 	this->m_outputBufferDisplay = NULL;
 	this->m_active = false;
 	this->m_doColorManagement = true;
+	this->m_doDepthBuffer = false;
 }
 
 void ViewerBaseOperation::initExecution()
@@ -61,8 +63,8 @@
 	ImBuf *ibuf = BKE_image_acquire_ibuf(anImage, this->m_imageUser, &this->m_lock);
 	
 	if (!ibuf) return;
+	BLI_lock_thread(LOCK_DRAW_IMAGE);
 	if (ibuf->x != (int)getWidth() || ibuf->y != (int)getHeight()) {
-		BLI_lock_thread(LOCK_DRAW_IMAGE);
 
 		imb_freerectImBuf(ibuf);
 		imb_freerectfloatImBuf(ibuf);
@@ -73,12 +75,21 @@
 		imb_addrectfloatImBuf(ibuf);
 		anImage->ok = IMA_OK_LOADED;
 
-		BLI_unlock_thread(LOCK_DRAW_IMAGE);
 	}
+	if (m_doDepthBuffer) 
+	{
+		addzbuffloatImBuf(ibuf);
+	}
+	BLI_unlock_thread(LOCK_DRAW_IMAGE);
 	
+	
 	/* now we combine the input with ibuf */
 	this->m_outputBuffer = ibuf->rect_float;
 	this->m_outputBufferDisplay = (unsigned char *)ibuf->rect;
+	if (m_doDepthBuffer)
+	{
+		this->m_depthBuffer = ibuf->zbuf_float;
+	}
 	
 	BKE_image_release_ibuf(this->m_image, this->m_lock);
 }

Modified: trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ViewerBaseOperation.h	2012-07-29 14:07:57 UTC (rev 49356)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list