[Bf-blender-cvs] [cb7cfd3] master: Cycles: add dedicated UV Map node, easier to find and has convenient auto complete.

Kevin Dietrich noreply at git.blender.org
Wed Apr 2 11:54:29 CEST 2014


Commit: cb7cfd3ab6be1cfba96cb2070ac60d224126f1ea
Author: Kevin Dietrich
Date:   Wed Apr 2 11:40:29 2014 +0200
https://developer.blender.org/rBcb7cfd3ab6be1cfba96cb2070ac60d224126f1ea

Cycles: add dedicated UV Map node, easier to find and has convenient auto complete.

Fixes T37954.

Reviewed By: brecht, dingto

Differential Revision: https://developer.blender.org/D230

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

M	intern/cycles/app/cycles_xml.cpp
M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/kernel/shaders/CMakeLists.txt
A	intern/cycles/kernel/shaders/node_uv_map.osl
M	intern/cycles/kernel/svm/svm_types.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/nodes.h
M	release/scripts/startup/nodeitems_builtins.py
M	source/blender/blenkernel/BKE_node.h
M	source/blender/blenkernel/intern/node.c
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_shader.h
M	source/blender/nodes/NOD_static_types.h
A	source/blender/nodes/shader/nodes/node_shader_uvmap.c

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

diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index 04408eb..1faf290 100644
--- a/intern/cycles/app/cycles_xml.cpp
+++ b/intern/cycles/app/cycles_xml.cpp
@@ -649,6 +649,11 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug
 			xml_read_ustring(&attr->attribute, node, "attribute");
 			snode = attr;
 		}
+		else if(string_iequals(node.name(), "uv_map")) {
+			UVMapNode *uvm = new UVMapNode();
+			xml_read_ustring(&uvm->attribute, node, "uv_map");
+			snode = uvm;
+		}
 		else if(string_iequals(node.name(), "camera")) {
 			snode = new CameraNode();
 		}
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 1559a96..2eafcec 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -668,6 +668,13 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
 		tangent->attribute = b_tangent_node.uv_map();
 		node = tangent;
 	}
+	else if (b_node.is_a(&RNA_ShaderNodeUVMap)) {
+		BL::ShaderNodeUVMap b_uvmap_node(b_node);
+		UVMapNode *uvm = new UVMapNode();
+		uvm->attribute = b_uvmap_node.uv_map();
+		uvm->from_dupli = b_uvmap_node.from_dupli();
+		node = uvm;
+	}
 
 	if(node)
 		graph->add(node);
diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt
index 045abdb..5518d65 100644
--- a/intern/cycles/kernel/shaders/CMakeLists.txt
+++ b/intern/cycles/kernel/shaders/CMakeLists.txt
@@ -77,6 +77,7 @@ set(SRC_OSL
 	node_wave_texture.osl
 	node_wireframe.osl
 	node_hair_bsdf.osl
+	node_uv_map.osl
 )
 
 set(SRC_OSL_HEADERS
diff --git a/intern/cycles/kernel/shaders/node_uv_map.osl b/intern/cycles/kernel/shaders/node_uv_map.osl
new file mode 100644
index 0000000..fd039be
--- /dev/null
+++ b/intern/cycles/kernel/shaders/node_uv_map.osl
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2011-2013 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+#include "stdosl.h"
+
+shader node_uv_map(
+	string name = "",
+	int from_dupli = 0,
+	output point UV = point(0.0, 0.0, 0.0))
+
+{
+	if (from_dupli) {
+		getattribute("geom:dupli_uv", UV);
+	}
+	else {
+        if (name == "") 
+		    getattribute("geom:uv", UV);        
+        else 
+            getattribute(name, UV);        
+	}
+}
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index ad5e1ea..3285ea5 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -102,7 +102,8 @@ typedef enum NodeType {
 	NODE_CLOSURE_AMBIENT_OCCLUSION,
 	NODE_TANGENT,
 	NODE_NORMAL_MAP,
-	NODE_HAIR_INFO
+	NODE_HAIR_INFO,
+	NODE_UVMAP
 } NodeType;
 
 typedef enum NodeAttributeType {
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index f10b956..908acb3 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -2328,6 +2328,62 @@ void TextureCoordinateNode::compile(OSLCompiler& compiler)
 	compiler.add(this, "node_texture_coordinate");
 }
 
+UVMapNode::UVMapNode()
+: ShaderNode("uvmap")
+{
+	attribute = "";
+	from_dupli = false;
+
+	add_output("UV", SHADER_SOCKET_POINT);
+}
+
+void UVMapNode::attributes(Shader *shader, AttributeRequestSet *attributes)
+{
+	if(shader->has_surface) {
+		if(!from_dupli) {
+			if(!output("UV")->links.empty()) {
+				if (attribute != "")
+					attributes->add(attribute);
+				else
+					attributes->add(ATTR_STD_UV);
+			}
+		}
+	}
+
+	ShaderNode::attributes(shader, attributes);
+}
+
+void UVMapNode::compile(SVMCompiler& compiler)
+{
+	ShaderOutput *out = output("UV");
+	NodeType texco_node = NODE_TEX_COORD;
+	NodeType attr_node = NODE_ATTR;
+	int attr;
+
+	if(!out->links.empty()) {
+		if(from_dupli) {
+			compiler.stack_assign(out);
+			compiler.add_node(texco_node, NODE_TEXCO_DUPLI_UV, out->stack_offset);
+		}
+		else {
+			if (attribute != "")
+				attr = compiler.attribute(attribute);
+			else
+				attr = compiler.attribute(ATTR_STD_UV);
+
+			compiler.stack_assign(out);
+			compiler.add_node(attr_node, attr, out->stack_offset, NODE_ATTR_FLOAT3);
+		}
+	}
+}
+
+void UVMapNode::compile(OSLCompiler& compiler)
+{
+	compiler.parameter("from_dupli", from_dupli);
+	compiler.parameter("name", attribute.c_str());
+	compiler.add(this, "node_uv_map");
+}
+
 /* Light Path */
 
 LightPathNode::LightPathNode()
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 497a367..31caf95 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -350,6 +350,15 @@ public:
 	bool from_dupli;
 };
 
+class UVMapNode : public ShaderNode {
+public:
+	SHADER_NODE_CLASS(UVMapNode)
+	void attributes(Shader *shader, AttributeRequestSet *attributes);
+
+	ustring attribute;
+	bool from_dupli;
+};
+
 class LightPathNode : public ShaderNode {
 public:
 	SHADER_NODE_CLASS(LightPathNode)
diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py
index be989f0..34c0739 100644
--- a/release/scripts/startup/nodeitems_builtins.py
+++ b/release/scripts/startup/nodeitems_builtins.py
@@ -167,6 +167,7 @@ shader_node_categories = [
         NodeItem("ShaderNodeHairInfo"),
         NodeItem("ShaderNodeParticleInfo"),
         NodeItem("ShaderNodeCameraData"),
+        NodeItem("ShaderNodeUVMap"),
         NodeItem("NodeGroupInput", poll=group_input_output_item_poll),
         ]),
     ShaderNewNodeCategory("SH_NEW_OUTPUT", "Output", items=[
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 09c5776..1d76cab 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -744,6 +744,7 @@ struct ShadeResult;
 #define SH_NODE_COMBHSV					184
 #define SH_NODE_BSDF_HAIR				185
 #define SH_NODE_LAMP					186
+#define SH_NODE_UVMAP                   187
 
 /* custom defines options for Material node */
 #define SH_NODE_MAT_DIFF   1
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 2122526..47ef030 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -3520,6 +3520,7 @@ static void registerShaderNodes(void)
 	register_node_type_sh_subsurface_scattering();
 	register_node_type_sh_mix_shader();
 	register_node_type_sh_add_shader();
+	register_node_type_sh_uvmap();
 
 	register_node_type_sh_output_lamp();
 	register_node_type_sh_output_material();
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 5e3ac42..d64607c 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -873,6 +873,20 @@ static void node_shader_buts_bump(uiLayout *layout, bContext *UNUSED(C), Pointer
 	uiItemR(layout, ptr, "invert", 0, NULL, 0);
 }
 
+static void node_shader_buts_uvmap(uiLayout *layout, bContext *C, PointerRNA *ptr)
+{
+	uiItemR(layout, ptr, "from_dupli", 0, NULL, 0);
+
+	if(!RNA_boolean_get(ptr, "from_dupli")) {
+		PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
+
+		if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
+			PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
+			uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_textures", "", ICON_NONE);
+		}
+	}
+}
+
 static void node_shader_buts_normal_map(uiLayout *layout, bContext *C, PointerRNA *ptr)
 {
 	uiItemR(layout, ptr, "space", 0, "", 0);
@@ -1103,6 +1117,9 @@ static void node_shader_set_butfunc(bNodeType *ntype)
 			ntype->draw_buttons = node_shader_buts_script;
 			ntype->draw_buttons_ex = node_shader_buts_script_ex;
 			break;
+		case SH_NODE_UVMAP:
+			ntype->draw_buttons = node_shader_buts_uvmap;
+			break;
 	}
 }
 
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 2d3a0fa..967ec8d 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -847,6 +847,10 @@ typedef struct NodeShaderNormalMap {
 	char uv_map[64];
 } NodeShaderNormalMap;
 
+typedef struct NodeShaderUVMap {
+	char uv_map[64];
+} NodeShaderUVMap;
+
 /* script node mode */
 #define NODE_SCRIPT_INTERNAL		0
 #define NODE_SCRIPT_EXTERNAL		1
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 0664ecf..0f2380c 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -3730,6 +3730,24 @@ static void def_hair(StructRNA *srna)
 	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_sh_uvmap(StructRNA *srna)
+{
+	PropertyRNA *prop;
+
+	prop = RNA_def_property(srna, "from_dupli", PROP_BOOLEAN, PROP_NONE);
+	RNA_def_property_boolean_sdna(prop, NULL, "custom1", 1);
+	RNA_def_property_ui_text(prop, "From Dupli", "Use the parent of the dupli object if possible");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+	RNA_def_struct_sdna_from(srna, "NodeShaderUVMap", "storage");
+
+	prop = RNA_def_property(srna, "uv_map", PROP_STRING, PROP_NONE);
+	RNA_def_property_ui_text(prop, "UV Map", "UV coordinates to be used for mapping");
+	RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+
+	RNA_def_struct_sdna_from(srna, "bNode", NULL);
+}
+
 static void def_sh_normal_map(StructRNA *srna)
 {
 	static EnumPropertyItem prop_space_items[] = {
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index fef6762..754a3c1 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -200,6 +200,7 @@ set(SRC
 	shader/nodes/node_shader_tex_wave.c


@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list