[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [42669] trunk/blender: Normal Node - Cycles

Dalai Felinto dfelinto at gmail.com
Fri Dec 16 19:15:27 CET 2011


Revision: 42669
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=42669
Author:   dfelinto
Date:     2011-12-16 18:15:07 +0000 (Fri, 16 Dec 2011)
Log Message:
-----------
Normal Node - Cycles
reviewed by Brecht, with help from Lukas.

Note: dot is reversed compared to Blender.
In Blender Normals point outside, while in Cycles they point inside.
If you use your own custom vector with the Normal Node you will see a difference.
If you feed it with object normals it should work just as good.

Modified Paths:
--------------
    trunk/blender/intern/cycles/app/cycles_xml.cpp
    trunk/blender/intern/cycles/blender/blender_shader.cpp
    trunk/blender/intern/cycles/kernel/CMakeLists.txt
    trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt
    trunk/blender/intern/cycles/kernel/svm/svm.h
    trunk/blender/intern/cycles/kernel/svm/svm_types.h
    trunk/blender/intern/cycles/render/nodes.cpp
    trunk/blender/intern/cycles/render/nodes.h
    trunk/blender/source/blender/nodes/shader/nodes/node_shader_normal.c

Added Paths:
-----------
    trunk/blender/intern/cycles/kernel/osl/nodes/node_normal.osl
    trunk/blender/intern/cycles/kernel/svm/svm_normal.h

Modified: trunk/blender/intern/cycles/app/cycles_xml.cpp
===================================================================
--- trunk/blender/intern/cycles/app/cycles_xml.cpp	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/intern/cycles/app/cycles_xml.cpp	2011-12-16 18:15:07 UTC (rev 42669)
@@ -368,6 +368,9 @@
 			xml_read_enum(&wood->type, WaveTextureNode::type_enum, node, "type");
 			snode = wood;
 		}
+		else if(string_iequals(node.name(), "normal")) {
+			snode = new NormalNode();
+		}
 		else if(string_iequals(node.name(), "mapping")) {
 			snode = new MappingNode();
 		}

Modified: trunk/blender/intern/cycles/blender/blender_shader.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_shader.cpp	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/intern/cycles/blender/blender_shader.cpp	2011-12-16 18:15:07 UTC (rev 42669)
@@ -132,7 +132,6 @@
 		case BL::ShaderNode::type_GEOMETRY: break;
 		case BL::ShaderNode::type_MATERIAL: break;
 		case BL::ShaderNode::type_MATERIAL_EXT: break;
-		case BL::ShaderNode::type_NORMAL: break;
 		case BL::ShaderNode::type_OUTPUT: break;
 		case BL::ShaderNode::type_SCRIPT: break;
 		case BL::ShaderNode::type_SQUEEZE: break;
@@ -198,6 +197,17 @@
 			node = vmath;
 			break;
 		}
+		case BL::ShaderNode::type_NORMAL: {
+			BL::Node::outputs_iterator out_it;
+			b_node.outputs.begin(out_it);
+			BL::NodeSocketVectorNone vec_sock(*out_it);
+
+			NormalNode *norm = new NormalNode();
+			norm->direction = get_float3(vec_sock.default_value());
+
+			node = norm;
+			break;
+		}
 		case BL::ShaderNode::type_MAPPING: {
 			BL::ShaderNodeMapping b_mapping_node(b_node);
 			MappingNode *mapping = new MappingNode();

Modified: trunk/blender/intern/cycles/kernel/CMakeLists.txt
===================================================================
--- trunk/blender/intern/cycles/kernel/CMakeLists.txt	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/intern/cycles/kernel/CMakeLists.txt	2011-12-16 18:15:07 UTC (rev 42669)
@@ -72,6 +72,7 @@
 	svm/svm_musgrave.h
 	svm/svm_noise.h
 	svm/svm_noisetex.h
+	svm/svm_normal.h
 	svm/svm_sepcomb_rgb.h
 	svm/svm_sky.h
 	svm/svm_tex_coord.h

Modified: trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/CMakeLists.txt	2011-12-16 18:15:07 UTC (rev 42669)
@@ -33,6 +33,7 @@
 	node_mix.osl
 	node_mix_closure.osl
 	node_musgrave_texture.osl
+	node_normal.osl
 	node_blend_weight_texture.osl
 	node_noise_texture.osl
 	node_output_displacement.osl

Added: trunk/blender/intern/cycles/kernel/osl/nodes/node_normal.osl
===================================================================
--- trunk/blender/intern/cycles/kernel/osl/nodes/node_normal.osl	                        (rev 0)
+++ trunk/blender/intern/cycles/kernel/osl/nodes/node_normal.osl	2011-12-16 18:15:07 UTC (rev 42669)
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+#include "stdosl.h"
+
+shader node_normal(
+	normal Direction = normal(0.0, 0.0, 0.0),
+	normal NormalIn = normal(0.0, 0.0, 0.0),
+	output normal NormalOut = normal(0.0, 0.0, 0.0),
+	output float Dot = 1.0
+{
+	Direction = normalize(Direction);
+	NormalOut = Direction;
+	Dot = dot(Direction, NormalIn);
+}
+


Property changes on: trunk/blender/intern/cycles/kernel/osl/nodes/node_normal.osl
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/blender/intern/cycles/kernel/svm/svm.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm.h	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/intern/cycles/kernel/svm/svm.h	2011-12-16 18:15:07 UTC (rev 42669)
@@ -134,6 +134,7 @@
 #include "svm_light_path.h"
 #include "svm_magic.h"
 #include "svm_mapping.h"
+#include "svm_normal.h"
 #include "svm_wave.h"
 #include "svm_math.h"
 #include "svm_mix.h"
@@ -300,6 +301,9 @@
 			case NODE_VECTOR_MATH:
 				svm_node_vector_math(kg, sd, stack, node.y, node.z, node.w, &offset);
 				break;
+			case NODE_NORMAL:
+				svm_node_normal(kg, sd, stack, node.y, node.z, node.w, &offset);
+				break;
 			case NODE_MAPPING:
 				svm_node_mapping(kg, sd, stack, node.y, node.z, &offset);
 				break;

Added: trunk/blender/intern/cycles/kernel/svm/svm_normal.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm_normal.h	                        (rev 0)
+++ trunk/blender/intern/cycles/kernel/svm/svm_normal.h	2011-12-16 18:15:07 UTC (rev 42669)
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+CCL_NAMESPACE_BEGIN
+
+__device void svm_node_normal(KernelGlobals *kg, ShaderData *sd, float *stack, uint in_normal_offset, uint out_normal_offset, uint out_dot_offset, int *offset)
+{
+	/* read extra data */
+	uint4 node1 = read_node(kg, offset);
+	float3 normal = stack_load_float3(stack, in_normal_offset);
+
+	float3 direction;
+	direction.x = node1.x;
+	direction.y = node1.y;
+	direction.z = node1.z;
+	direction = normalize(direction);
+
+	if (stack_valid(out_normal_offset))
+		stack_store_float3(stack, out_normal_offset, direction);
+
+	if (stack_valid(out_dot_offset))
+		stack_store_float(stack, out_dot_offset, dot(direction, normalize(normal)));
+}
+
+CCL_NAMESPACE_END
+


Property changes on: trunk/blender/intern/cycles/kernel/svm/svm_normal.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: trunk/blender/intern/cycles/kernel/svm/svm_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/svm/svm_types.h	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/intern/cycles/kernel/svm/svm_types.h	2011-12-16 18:15:07 UTC (rev 42669)
@@ -84,7 +84,8 @@
 	NODE_COMBINE_RGB = 5100,
 	NODE_HSV = 5200,
 	NODE_CAMERA = 5300,
-	NODE_INVERT = 5400
+	NODE_INVERT = 5400,
+	NODE_NORMAL = 5500
 } NodeType;
 
 typedef enum NodeAttributeType {

Modified: trunk/blender/intern/cycles/render/nodes.cpp
===================================================================
--- trunk/blender/intern/cycles/render/nodes.cpp	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/intern/cycles/render/nodes.cpp	2011-12-16 18:15:07 UTC (rev 42669)
@@ -713,6 +713,41 @@
 	compiler.add(this, "node_magic_texture");
 }
 
+/* Normal */
+
+NormalNode::NormalNode()
+: ShaderNode("normal")
+{
+	direction = make_float3(0.0f, 0.0f, 1.0f);
+
+	add_input("Normal", SHADER_SOCKET_NORMAL);
+	add_output("Normal", SHADER_SOCKET_NORMAL);
+	add_output("Dot",  SHADER_SOCKET_FLOAT);
+}
+
+void NormalNode::compile(SVMCompiler& compiler)
+{
+	ShaderInput *normal_in = input("Normal");
+	ShaderOutput *normal_out = output("Normal");
+	ShaderOutput *dot_out = output("Dot");
+
+	compiler.stack_assign(normal_in);
+	compiler.stack_assign(normal_out);
+	compiler.stack_assign(dot_out);
+
+	compiler.add_node(NODE_NORMAL, normal_in->stack_offset, normal_out->stack_offset, dot_out->stack_offset);
+	compiler.add_node(
+		__float_as_int(direction.x),
+		__float_as_int(direction.y),
+		__float_as_int(direction.z));
+}
+
+void NormalNode::compile(OSLCompiler& compiler)
+{
+	compiler.parameter_vector("Direction", direction);
+	compiler.add(this, "node_normal");
+}
+
 /* Mapping */
 
 MappingNode::MappingNode()

Modified: trunk/blender/intern/cycles/render/nodes.h
===================================================================
--- trunk/blender/intern/cycles/render/nodes.h	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/intern/cycles/render/nodes.h	2011-12-16 18:15:07 UTC (rev 42669)
@@ -343,6 +343,13 @@
 	static ShaderEnum type_enum;
 };
 
+class NormalNode : public ShaderNode {
+public:
+	SHADER_NODE_CLASS(NormalNode)
+
+	float3 direction;
+};
+
 class VectorMathNode : public ShaderNode {
 public:
 	SHADER_NODE_CLASS(VectorMathNode)

Modified: trunk/blender/source/blender/nodes/shader/nodes/node_shader_normal.c
===================================================================
--- trunk/blender/source/blender/nodes/shader/nodes/node_shader_normal.c	2011-12-16 17:04:44 UTC (rev 42668)
+++ trunk/blender/source/blender/nodes/shader/nodes/node_shader_normal.c	2011-12-16 18:15:07 UTC (rev 42669)
@@ -84,7 +84,7 @@
 	static bNodeType ntype;
 	
 	node_type_base(ttype, &ntype, SH_NODE_NORMAL, "Normal", NODE_CLASS_OP_VECTOR, NODE_OPTIONS);
-	node_type_compatibility(&ntype, NODE_OLD_SHADING);
+	node_type_compatibility(&ntype, NODE_OLD_SHADING|NODE_NEW_SHADING);
 	node_type_socket_templates(&ntype, sh_node_normal_in, sh_node_normal_out);
 	node_type_init(&ntype, node_shader_init_normal);
 	node_type_exec(&ntype, node_shader_exec_normal);




More information about the Bf-blender-cvs mailing list