[Bf-blender-cvs] [e15cdec] master: New compositor node "Sun Beams"

Lukas Tönne noreply at git.blender.org
Sat Jul 26 13:04:38 CEST 2014


Commit: e15cdec2d49ee47a85897db9838578a298146513
Author: Lukas Tönne
Date:   Sat Jul 26 12:59:29 2014 +0200
Branches: master
https://developer.blender.org/rBe15cdec2d49ee47a85897db9838578a298146513

New compositor node "Sun Beams"

This allows adding a "fake" sun beam effect, simulating crepuscular rays
from light being scattered in a medium like the atmosphere or deep water.
Such effects can be created also by renderers using volumetric lighting,
but the compositor feature is a lot cheaper and is independent from 3D
rendering. This makes it ideally suited for motion graphics.

The implementation uses am optimized accumulation method for gathering
color values along a line segment. The inner buffer loop uses fixed
offset increments to avoid unnecessary multiplications and avoids
variables by using compile-time specialization (see inline comments
for further details).

===================================================================

M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.c
M	source/blender/compositor/CMakeLists.txt
M	source/blender/compositor/intern/COM_Converter.cpp
A	source/blender/compositor/nodes/COM_SunBeamsNode.cpp
A	source/blender/compositor/nodes/COM_SunBeamsNode.h
A	source/blender/compositor/operations/COM_SunBeamsOperation.cpp
A	source/blender/compositor/operations/COM_SunBeamsOperation.h
M	source/blender/editors/space_node/drawnode.c
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/CMakeLists.txt
M	source/blender/nodes/NOD_composite.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/composite/nodes/node_composite_sunbeams.c

===================================================================

diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index 0a90b9f..14680ae 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -318,6 +318,7 @@ compositor_node_categories = [
         NodeItem("CompositorNodeInpaint"),
         NodeItem("CompositorNodeDBlur"),
         NodeItem("CompositorNodePixelate"),
+        NodeItem("CompositorNodeSunBeams"),
         ]),
     CompositorNodeCategory("CMP_OP_VECTOR", "Vector", items=[
         NodeItem("CompositorNodeNormal"),
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 15e7efe..5e786cb 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -894,6 +894,7 @@ void            ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMateria
 #define CMP_NODE_GLARE		301
 #define CMP_NODE_TONEMAP	302
 #define CMP_NODE_LENSDIST	303
+#define CMP_NODE_SUNBEAMS	304
 
 #define CMP_NODE_COLORCORRECTION 312
 #define CMP_NODE_MASK_BOX       313
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 56a76a5..0dee80e 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -3406,6 +3406,7 @@ static void registerCompositNodes(void)
 	register_node_type_cmp_inpaint();
 	register_node_type_cmp_despeckle();
 	register_node_type_cmp_defocus();
+	register_node_type_cmp_sunbeams();
 	
 	register_node_type_cmp_valtorgb();
 	register_node_type_cmp_rgbtobw();
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index a194334..9c539e2 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -175,6 +175,11 @@ set(SRC
 	nodes/COM_GlareNode.cpp
 	nodes/COM_GlareNode.h
 
+	nodes/COM_SunBeamsNode.cpp
+	nodes/COM_SunBeamsNode.h
+	operations/COM_SunBeamsOperation.cpp
+	operations/COM_SunBeamsOperation.h
+
 	nodes/COM_CornerPinNode.cpp
 	nodes/COM_CornerPinNode.h
 	nodes/COM_PlaneTrackDeformNode.cpp
diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp
index 9251e16..99f66bc 100644
--- a/source/blender/compositor/intern/COM_Converter.cpp
+++ b/source/blender/compositor/intern/COM_Converter.cpp
@@ -99,6 +99,7 @@ extern "C" {
 #include "COM_SetValueOperation.h"
 #include "COM_SplitViewerNode.h"
 #include "COM_Stabilize2dNode.h"
+#include "COM_SunBeamsNode.h"
 #include "COM_SwitchNode.h"
 #include "COM_TextureNode.h"
 #include "COM_TimeNode.h"
@@ -394,6 +395,9 @@ Node *Converter::convert(bNode *b_node)
 		case CMP_NODE_CORNERPIN:
 			node = new CornerPinNode(b_node);
 			break;
+		case CMP_NODE_SUNBEAMS:
+			node = new SunBeamsNode(b_node);
+			break;
 	}
 	return node;
 }
diff --git a/source/blender/compositor/nodes/COM_SunBeamsNode.cpp b/source/blender/compositor/nodes/COM_SunBeamsNode.cpp
new file mode 100644
index 0000000..ed14aca
--- /dev/null
+++ b/source/blender/compositor/nodes/COM_SunBeamsNode.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2014, 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:
+ *		Lukas Toenne
+ */
+
+#include "COM_SunBeamsNode.h"
+#include "COM_SunBeamsOperation.h"
+
+SunBeamsNode::SunBeamsNode(bNode *editorNode) : Node(editorNode)
+{
+	/* pass */
+}
+
+void SunBeamsNode::convertToOperations(NodeConverter &converter, const CompositorContext &context) const
+{
+	NodeInput *inputSocket = this->getInputSocket(0);
+	NodeOutput *outputSocket = this->getOutputSocket(0);
+	NodeSunBeams *data = (NodeSunBeams *)getbNode()->storage;
+
+	SunBeamsOperation *operation = new SunBeamsOperation();
+	operation->setData(*data);
+	converter.addOperation(operation);
+
+	converter.mapInputSocket(inputSocket, operation->getInputSocket(0));
+	converter.mapOutputSocket(outputSocket, operation->getOutputSocket(0));
+}
diff --git a/source/blender/compositor/nodes/COM_SunBeamsNode.h b/source/blender/compositor/nodes/COM_SunBeamsNode.h
new file mode 100644
index 0000000..4024eb2
--- /dev/null
+++ b/source/blender/compositor/nodes/COM_SunBeamsNode.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2014, 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:
+ *		Lukas Toenne
+ */
+
+#ifndef _COM_SunBeamsNode_h_
+#define _COM_SunBeamsNode_h_
+
+#include "COM_Node.h"
+
+/**
+ * @brief SunBeamsNode
+ * @ingroup Node
+ */
+class SunBeamsNode : public Node {
+public:
+	SunBeamsNode(bNode *editorNode);
+	void convertToOperations(NodeConverter &converter, const CompositorContext &context) const;
+};
+
+#endif
diff --git a/source/blender/compositor/operations/COM_SunBeamsOperation.cpp b/source/blender/compositor/operations/COM_SunBeamsOperation.cpp
new file mode 100644
index 0000000..a267a1f
--- /dev/null
+++ b/source/blender/compositor/operations/COM_SunBeamsOperation.cpp
@@ -0,0 +1,303 @@
+/*
+ * Copyright 2014, 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:
+ *		Lukas Toenne
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "COM_SunBeamsOperation.h"
+
+SunBeamsOperation::SunBeamsOperation() : NodeOperation()
+{
+	this->addInputSocket(COM_DT_COLOR);
+	this->addOutputSocket(COM_DT_COLOR);
+	this->setResolutionInputSocketIndex(0);
+
+	this->setComplex(true);
+}
+
+void SunBeamsOperation::initExecution()
+{
+	/* convert to pixels */
+	this->m_source_px[0] = this->m_data.source[0] * this->getWidth();
+	this->m_source_px[1] = this->m_data.source[1] * this->getHeight();
+	this->m_ray_length_px = this->m_data.ray_length * max(this->getWidth(), this->getHeight());
+}
+
+/**
+ * Defines a line accumulator for a specific sector,
+ * given by the four matrix entries that rotate from buffer space into the sector
+ *
+ * (x,y) is used to designate buffer space coordinates
+ * (u,v) is used to designate sector space coordinates
+ *
+ * For a target point (x,y) the sector should be chosen such that
+ *   ``u >= v >= 0``
+ * This removes the need to handle all sorts of special cases.
+ */
+template <int fxx, int fxy, int fyx, int fyy>
+struct BufferLineAccumulator {
+
+	/* utility functions implementing the matrix transform to/from sector space */
+
+	static inline void buffer_to_sector(int x, int y, int &u, int &v)
+	{
+		u = x * fxx + y * fyx;
+		v = x * fxy + y * fyy;
+	}
+
+	static inline void buffer_to_sector(float x, float y, float &u, float &v)
+	{
+		u = x * fxx + y * fyx;
+		v = x * fxy + y * fyy;
+	}
+
+	static inline void sector_to_buffer(int u, int v, int &x, int &y)
+	{
+		x = u * fxx + v * fxy;
+		y = u * fyx + v * fyy;
+	}
+
+	static inline void sector_to_buffer(float u, float v, float &x, float &y)
+	{
+		x = u * fxx + v * fxy;
+		y = u * fyx + v * fyy;
+	}
+
+	/**
+	 * Set up the initial buffer pointer and calculate necessary variables for looping.
+	 *
+	 * Note that sector space is centered around the "source" point while the loop starts
+	 * at dist_min from the target pt. This way the loop can be cancelled as soon as it runs
+	 * out of the buffer rect, because no pixels further along the line can contribute.
+	 *
+	 * \param x, y  Start location in the buffer
+	 * \param num  Total steps in the loop
+	 * \param v, dv  Vertical offset in sector space, for line offset perpendicular to the loop axis
+	 */
+	static float *init_buffer_iterator(MemoryBuffer *input, const float source[2], const float pt_ofs[2],
+	                                   float dist_min, float dist_max,
+	                                   int &x, int &y, int &num, float &v, float &dv)
+	{
+		float pu, pv;
+		buffer_to_sector(pt_ofs[0], pt_ofs[1], pu, pv);
+
+		/* line angle */
+		float tan_phi = pv / pu;
+		float cos_phi = 1.0f / sqrtf(tan_phi * tan_phi + 1.0f);
+
+		float umin = pu - cos_phi * dist_min;
+		float umax = pu - cos_phi * dist_max;
+		v = umin * tan_phi;
+		dv = tan_phi;
+
+		sector_to_buffer(umin, v, x, y);
+		x += source[0];
+		y += source[1];
+
+		num = (int)ceilf(umin) - max_ii((int)floorf(umax), 1);
+
+		float *iter = input->getBuffer() + COM_NUMBER_OF_CHANNELS * (x + input->getWidth() * y);
+		retu

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list