[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43717] branches/tile/source/blender/ compositor: Tile branch

Jeroen Bakker j.bakker at atmind.nl
Thu Jan 26 11:42:19 CET 2012


Revision: 43717
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43717
Author:   jbakker
Date:     2012-01-26 10:42:15 +0000 (Thu, 26 Jan 2012)
Log Message:
-----------
Tile branch
 * Added the Glare streaks operation
 * Added a clear method to the MemoryBuffer

Jeroen Bakker
 - At Mind - 

Modified Paths:
--------------
    branches/tile/source/blender/compositor/CMakeLists.txt
    branches/tile/source/blender/compositor/intern/COM_MemoryBuffer.cpp
    branches/tile/source/blender/compositor/intern/COM_MemoryBuffer.h
    branches/tile/source/blender/compositor/nodes/COM_GlareNode.cpp

Added Paths:
-----------
    branches/tile/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp
    branches/tile/source/blender/compositor/operations/COM_GlareStreaksOperation.h

Modified: branches/tile/source/blender/compositor/CMakeLists.txt
===================================================================
--- branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-26 10:36:36 UTC (rev 43716)
+++ branches/tile/source/blender/compositor/CMakeLists.txt	2012-01-26 10:42:15 UTC (rev 43717)
@@ -506,6 +506,8 @@
 	operations/COM_GlareBaseOperation.h
 	operations/COM_GlareSimpleStarOperation.cpp
 	operations/COM_GlareSimpleStarOperation.h
+	operations/COM_GlareStreaksOperation.cpp
+	operations/COM_GlareStreaksOperation.h
 
 
 #Convert operations

Modified: branches/tile/source/blender/compositor/intern/COM_MemoryBuffer.cpp
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_MemoryBuffer.cpp	2012-01-26 10:36:36 UTC (rev 43716)
+++ branches/tile/source/blender/compositor/intern/COM_MemoryBuffer.cpp	2012-01-26 10:42:15 UTC (rev 43717)
@@ -61,6 +61,9 @@
 	memcpy(result->buffer, this->buffer, this->determineBufferSize()*4*sizeof(float));
 	return result;
 }
+void MemoryBuffer::clear() {
+	memset(this->buffer, 0, this->determineBufferSize()*4*sizeof(float));
+}
 
 MemoryBuffer::~MemoryBuffer() {
 	if (this->buffer) {

Modified: branches/tile/source/blender/compositor/intern/COM_MemoryBuffer.h
===================================================================
--- branches/tile/source/blender/compositor/intern/COM_MemoryBuffer.h	2012-01-26 10:36:36 UTC (rev 43716)
+++ branches/tile/source/blender/compositor/intern/COM_MemoryBuffer.h	2012-01-26 10:42:15 UTC (rev 43717)
@@ -154,7 +154,12 @@
 	  * @brief get the height of this MemoryBuffer
 	  */
 	int getHeight() const;
-
+	
+	/**
+	  * @brief clear the buffer. Make all pixels black transparant.
+	  */
+	void clear();
+	
 	MemoryBuffer* duplicate();
 private:
     unsigned int determineBufferSize();

Modified: branches/tile/source/blender/compositor/nodes/COM_GlareNode.cpp
===================================================================
--- branches/tile/source/blender/compositor/nodes/COM_GlareNode.cpp	2012-01-26 10:36:36 UTC (rev 43716)
+++ branches/tile/source/blender/compositor/nodes/COM_GlareNode.cpp	2012-01-26 10:42:15 UTC (rev 43717)
@@ -26,6 +26,7 @@
 #include "COM_BokehBlurOperation.h"
 #include "COM_GlareThresholdOperation.h"
 #include "COM_GlareSimpleStarOperation.h"
+#include "COM_GlareStreaksOperation.h"
 #include "COM_SetValueOperation.h"
 #include "COM_MixBlendOperation.h"
 
@@ -39,6 +40,31 @@
 	switch (glare->type) {
 	
 	default:
+	case 2: // streaks
+		{
+			GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();
+			GlareStreaksOperation * glareoperation = new GlareStreaksOperation();
+			SetValueOperation * mixvalueoperation = new SetValueOperation();
+			MixBlendOperation * mixoperation = new MixBlendOperation();
+	
+			this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), true, 0, system);
+			addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0));
+			addLink(system, mixvalueoperation->getOutputSocket(), mixoperation->getInputSocket(0));
+			addLink(system, glareoperation->getOutputSocket(), mixoperation->getInputSocket(2));
+			addLink(system, thresholdOperation->getInputSocket(0)->getConnection()->getFromSocket(), mixoperation->getInputSocket(1));
+			this->getOutputSocket()->relinkConnections(mixoperation->getOutputSocket());
+	
+			thresholdOperation->setThreshold(glare->threshold);
+			glareoperation->setGlareSettings(glare);
+			mixvalueoperation->setValue(0.5f+glare->mix*0.5f);
+			mixoperation->setResolutionInputSocketIndex(1);
+	
+			system->addOperation(glareoperation);
+			system->addOperation(thresholdOperation);
+			system->addOperation(mixvalueoperation);
+			system->addOperation(mixoperation);
+		}	
+		break;
 	case 1: // fog glow
 		{
 			GlareThresholdOperation *thresholdOperation = new GlareThresholdOperation();

Added: branches/tile/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_GlareStreaksOperation.cpp	2012-01-26 10:42:15 UTC (rev 43717)
@@ -0,0 +1,94 @@
+/*
+ * 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: 
+ *		Jeroen Bakker 
+ *		Monique Dewanchand
+ */
+
+#include "COM_GlareStreaksOperation.h"
+#include "BLI_math.h"
+
+void GlareStreaksOperation::generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings) {
+	int x, y, n;
+	unsigned int nump=0;
+	float c1[4], c2[4], c3[4], c4[4];
+	float a, ang = DEG2RADF(360.0f)/(float)settings->angle;
+	
+	int size = inputTile->getWidth()*inputTile->getHeight();
+	int size4 = size*4;
+
+	
+	MemoryBuffer* tsrc = inputTile->duplicate();
+	MemoryBuffer* tdst = new MemoryBuffer(NULL, inputTile->getRect());
+	tdst->clear();
+	memset(data, 0, size4*sizeof(float));
+	
+	for (a=0.f; a<DEG2RADF(360.0f); a+=ang) {
+		const float an = a + settings->angle_ofs;
+		const float vx = cos((double)an), vy = sin((double)an);
+		for (n=0; n<settings->iter; ++n) {
+			const float p4 = pow(4.0, (double)n);
+			const float vxp = vx*p4, vyp = vy*p4;
+			const float wt = pow((double)settings->fade, (double)p4);
+			const float cmo = 1.f - (float)pow((double)settings->colmod, (double)n+1);	// colormodulation amount relative to current pass
+			float* tdstcol = tdst->getBuffer();
+			for (y=0; y<tsrc->getHeight(); ++y) {
+				for (x=0; x<tsrc->getWidth(); ++x, tdstcol+=4) {
+					// first pass no offset, always same for every pass, exact copy,
+					// otherwise results in uneven brightness, only need once
+					if (n==0) tsrc->read(c1, x, y); else c1[0]=c1[1]=c1[2]=0;
+					tsrc->readCubic(c2, x + vxp, y + vyp);
+					tsrc->readCubic(c3, x + vxp*2.f, y + vyp*2.f);
+					tsrc->readCubic(c4, x + vxp*3.f, y + vyp*3.f);
+					// modulate color to look vaguely similar to a color spectrum
+					c2[1] *= cmo;
+					c2[2] *= cmo;
+
+					c3[0] *= cmo;
+					c3[1] *= cmo;
+					
+					c4[0] *= cmo;
+					c4[2] *= cmo;
+
+					tdstcol[0] = 0.5f*(tdstcol[0] + c1[0] + wt*(c2[0] + wt*(c3[0] + wt*c4[0])));
+					tdstcol[1] = 0.5f*(tdstcol[1] + c1[1] + wt*(c2[1] + wt*(c3[1] + wt*c4[1])));
+					tdstcol[2] = 0.5f*(tdstcol[2] + c1[2] + wt*(c2[2] + wt*(c3[2] + wt*c4[2])));
+					tdstcol[3] = 1.0f;
+				}
+			}
+			memcpy(tsrc->getBuffer(), tdst->getBuffer(), sizeof(float)*size4);
+		}
+
+//		addImage(sbuf, tsrc, 1.f/(float)(6 - ndg->iter)); // add result to data @todo
+		float* sourcebuffer = tsrc->getBuffer();
+		float factor = 1.f/(float)(6 - settings->iter);
+		for (int i = 0 ; i < size4; i ++) {
+			data[i] += sourcebuffer[i] * factor;
+		}
+		for (int i = 0 ; i < size; i ++) {
+			data[i*4+3] = 1.0f;
+		}
+		
+		tdst->clear();
+		memcpy(tsrc->getBuffer(), inputTile->getBuffer(), sizeof(float)*size4);
+		nump++;
+	}
+	
+	delete tsrc;
+	delete tdst;
+}

Added: branches/tile/source/blender/compositor/operations/COM_GlareStreaksOperation.h
===================================================================
--- branches/tile/source/blender/compositor/operations/COM_GlareStreaksOperation.h	                        (rev 0)
+++ branches/tile/source/blender/compositor/operations/COM_GlareStreaksOperation.h	2012-01-26 10:42:15 UTC (rev 43717)
@@ -0,0 +1,35 @@
+/*
+ * 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: 
+ *		Jeroen Bakker 
+ *		Monique Dewanchand
+ */
+
+#ifndef _COM_GlareStreaksOperation_h
+#define _COM_GlareStreaksOperation_h
+#include "COM_NodeOperation.h"
+#include "DNA_node_types.h"
+#include "COM_GlareBaseOperation.h"
+
+class GlareStreaksOperation : public GlareBaseOperation {
+public:
+	GlareStreaksOperation() : GlareBaseOperation() {}
+protected:
+	void generateGlare(float *data, MemoryBuffer *inputTile, NodeGlare *settings);
+};
+#endif



More information about the Bf-blender-cvs mailing list