Cycles / Vector Transform Node:
authorThomas Dinges <blender@dingto.org>
Thu, 20 Jun 2013 08:20:30 +0000 (08:20 +0000)
committerThomas Dinges <blender@dingto.org>
Thu, 20 Jun 2013 08:20:30 +0000 (08:20 +0000)
* First step towards a new vector transform node, to convert Points/Vectors between World/Object/Camera space.
This only contains the Blender UI, RNA... code, no Cycles integration yet.

release/scripts/startup/nodeitems_builtins.py
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.c
source/blender/editors/space_node/drawnode.c
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c
source/blender/nodes/CMakeLists.txt
source/blender/nodes/NOD_shader.h
source/blender/nodes/NOD_static_types.h
source/blender/nodes/shader/nodes/node_shader_vectTransform.c [new file with mode: 0644]

index 96cba2243ec3ed4f646e46e25e21d3b1bbb50838..8bf7cbf2696062fb9dc017e3c8e00f0d05711a50 100644 (file)
@@ -210,6 +210,7 @@ shader_node_categories = [
         NodeItem("ShaderNodeNormalMap"),
         NodeItem("ShaderNodeNormal"),
         NodeItem("ShaderNodeVectorCurve"),
+        NodeItem("ShaderNodeVectorTransform"),
         ]),
     ShaderNewNodeCategory("SH_NEW_CONVERTOR", "Converter", items=[
         NodeItem("ShaderNodeMath"),
index bc1ef7ac5c928d63888dd27367d7a5186082f87b..5f84450045f051a5a4e4e5d806b6c9775065f57d 100644 (file)
@@ -743,6 +743,7 @@ struct ShadeResult;
 #define SH_NODE_BSDF_TOON                              179
 #define SH_NODE_WAVELENGTH                             180
 #define SH_NODE_BLACKBODY                              181
+#define SH_NODE_VECT_TRANSFORM                 182
 
 /* custom defines options for Material node */
 #define SH_NODE_MAT_DIFF   1
index 66b77c4334e552aedf058098ea44933633b63b5c..14be1cef8cc6f9103b8354a1b19864cd85e0eaa2 100644 (file)
@@ -3419,6 +3419,7 @@ static void registerShaderNodes(void)
        register_node_type_sh_curve_rgb();
        register_node_type_sh_math();
        register_node_type_sh_vect_math();
+       register_node_type_sh_vect_transform();
        register_node_type_sh_squeeze();
        register_node_type_sh_material_ext();
        register_node_type_sh_invert();
index d39695f54b7e4b93e64a7c8c300cf7ed2e755e66..82104d2c83792ee40922d1a117528eb8e51d3177 100644 (file)
@@ -735,6 +735,13 @@ static void node_shader_buts_vect_math(uiLayout *layout, bContext *UNUSED(C), Po
        uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
 }
 
+static void node_shader_buts_vect_transform(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+{ 
+       uiItemR(layout, ptr, "type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
+       uiItemR(layout, ptr, "convert_from", 0, "", ICON_NONE);
+       uiItemR(layout, ptr, "convert_to", 0, "", ICON_NONE);
+}
+
 static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr)
 {
        PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
@@ -969,6 +976,9 @@ static void node_shader_set_butfunc(bNodeType *ntype)
                case SH_NODE_VECT_MATH: 
                        ntype->uifunc = node_shader_buts_vect_math;
                        break; 
+               case SH_NODE_VECT_TRANSFORM: 
+                       ntype->uifunc = node_shader_buts_vect_transform;
+                       break; 
                case SH_NODE_GEOMETRY:
                        ntype->uifunc = node_shader_buts_geometry;
                        break;
index 8a9a95a9935f4cf7cb2c7aae9c00d71fef081e19..780cc3718656dcb2205eab57146800b30211b351 100644 (file)
@@ -788,6 +788,12 @@ typedef struct NodeShaderAttribute {
        char name[64];
 } NodeShaderAttribute;
 
+typedef struct NodeShaderVectTransform {
+       int type;
+       int convert_from, convert_to;
+       int pad;
+} NodeShaderVectTransform;
+
 /* TEX_output */
 typedef struct TexNodeOutput {
        char name[64];
@@ -869,6 +875,18 @@ typedef struct NodeShaderNormalMap {
 #define SHD_GLOSSY_SHARP       1
 #define SHD_GLOSSY_GGX         2
 
+/* vector transform */
+#define SHD_VECT_TRANSFORM_TYPE_VECTOR 0
+#define SHD_VECT_TRANSFORM_TYPE_POINT  1
+
+#define SHD_VECT_TRANSFORM_FROM_WORLD  0
+#define SHD_VECT_TRANSFORM_FROM_OBJECT 1
+#define SHD_VECT_TRANSFORM_FROM_CAMERA 2
+
+#define SHD_VECT_TRANSFORM_TO_WORLD            0
+#define SHD_VECT_TRANSFORM_TO_OBJECT   1
+#define SHD_VECT_TRANSFORM_TO_CAMERA   2
+
 /* toon modes */
 #define SHD_TOON_DIFFUSE       0
 #define SHD_TOON_GLOSSY                1
index bc3984e2a0d3bdd4a2fe8ab6642e3a60b995b93f..5d77f7d13904604acd851619ada28a2f14ea12cc 100644 (file)
@@ -3482,6 +3482,48 @@ static void def_sh_tex_coord(StructRNA *srna)
        RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
+static void def_sh_vect_transform(StructRNA *srna)
+{
+       static EnumPropertyItem prop_vect_type_items[] = {
+               {SHD_VECT_TRANSFORM_TYPE_VECTOR, "VECTOR",  0, "Vector",   ""},
+               {SHD_VECT_TRANSFORM_TYPE_POINT,  "POINT",   0, "Point",    ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       static EnumPropertyItem prop_vect_from_items[] = {
+               {SHD_VECT_TRANSFORM_FROM_WORLD,  "WORLD",   0, "World",    ""},
+               {SHD_VECT_TRANSFORM_FROM_OBJECT, "OBJECT",  0, "Object",   ""},
+               {SHD_VECT_TRANSFORM_FROM_CAMERA, "CAMERA",  0, "Camera",   ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       static EnumPropertyItem prop_vect_to_items[] = {
+               {SHD_VECT_TRANSFORM_TO_WORLD,  "WORLD",   0, "World",    ""},
+               {SHD_VECT_TRANSFORM_TO_OBJECT, "OBJECT",  0, "Object",   ""},
+               {SHD_VECT_TRANSFORM_TO_CAMERA, "CAMERA",  0, "Camera",   ""},
+               {0, NULL, 0, NULL, NULL}
+       };
+
+       PropertyRNA *prop;
+       
+       RNA_def_struct_sdna_from(srna, "NodeShaderVectTransform", "storage");
+       
+       prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, prop_vect_type_items);
+       RNA_def_property_ui_text(prop, "Type", "");
+       RNA_def_property_update(prop, 0, "rna_Node_update");
+       
+       prop = RNA_def_property(srna, "convert_from", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, prop_vect_from_items);
+       RNA_def_property_ui_text(prop, "Convert From", "Space to convert from");
+       RNA_def_property_update(prop, 0, "rna_Node_update");
+       
+       prop = RNA_def_property(srna, "convert_to", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_items(prop, prop_vect_to_items);
+       RNA_def_property_ui_text(prop, "Convert To", "Space to convert to");
+       RNA_def_property_update(prop, 0, "rna_Node_update");
+}
+
 static void def_sh_tex_wireframe(StructRNA *srna)
 {
        PropertyRNA *prop;
index 4b7ee2aed511746cfaaace2c09cee0534bc67794..3241f98ad1eda396174a6dab9de8399747a0f47b 100644 (file)
@@ -148,6 +148,7 @@ set(SRC
        shader/nodes/node_shader_wavelength.c
        shader/nodes/node_shader_blackbody.c
        shader/nodes/node_shader_vectMath.c
+       shader/nodes/node_shader_vectTransform.c
        shader/nodes/node_shader_add_shader.c
        shader/nodes/node_shader_ambient_occlusion.c
        shader/nodes/node_shader_attribute.c
index a56d78af309430303225a85d40e5fc5bc8b10c0d..a8c77a9baed54ba6408a8f1b8f1d41c89729ce94 100644 (file)
@@ -89,6 +89,7 @@ void register_node_type_sh_hair_info(void);
 void register_node_type_sh_script(void);
 void register_node_type_sh_normal_map(void);
 void register_node_type_sh_tangent(void);
+void register_node_type_sh_vect_transform(void);
 
 void register_node_type_sh_ambient_occlusion(void);
 void register_node_type_sh_background(void);
index 6d950d2a469a106fbb39d52d627afd40e741cefb..f94e6fc9f5271b9bc380b33a2a6c0f52e067d3ee 100644 (file)
@@ -114,6 +114,7 @@ DefNode( ShaderNode,     SH_NODE_TEX_VORONOI,        def_sh_tex_voronoi,     "TE
 DefNode( ShaderNode,     SH_NODE_TEX_CHECKER,        def_sh_tex_checker,     "TEX_CHECKER",        TexChecker,       "Checker Texture",   ""       )
 DefNode( ShaderNode,     SH_NODE_TEX_BRICK,          def_sh_tex_brick,       "TEX_BRICK",          TexBrick,         "Brick Texture",     ""       )
 DefNode( ShaderNode,     SH_NODE_TEX_COORD,          def_sh_tex_coord,       "TEX_COORD",          TexCoord,         "Texture Coordinate",""       )
+DefNode( ShaderNode,     SH_NODE_VECT_TRANSFORM,     def_sh_vect_transform,  "VECT_TRANSFORM",     VectorTransform,  "Vector Transform",  ""       )
 
 DefNode( CompositorNode, CMP_NODE_VIEWER,         def_cmp_viewer,         "VIEWER",         Viewer,           "Viewer",            ""              )
 DefNode( CompositorNode, CMP_NODE_RGB,            0,                      "RGB",            RGB,              "RGB",               ""              )
diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c
new file mode 100644 (file)
index 0000000..40c70b9
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2013 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/shader/nodes/node_shader_vectTransform.c
+ *  \ingroup shdnodes
+ */
+ #include "../node_shader_util.h"
+
+/* **************** Vector Transform ******************** */ 
+static bNodeSocketTemplate sh_node_vect_transform_in[] = {
+       { SOCK_VECTOR, 1, N_("Vector"), 0.5f, 0.5f, 0.5f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
+       { -1, 0, "" }
+};
+
+static bNodeSocketTemplate sh_node_vect_transform_out[] = {
+       { SOCK_VECTOR, 0, N_("Vector")},
+       { -1, 0, "" }
+};
+
+static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *node)
+{
+       NodeShaderVectTransform *vect = MEM_callocN(sizeof(NodeShaderVectTransform), "NodeShaderVectTransform");
+       
+       /* Convert World into Object Space per default */
+       vect->convert_to = 1;
+       
+       node->storage = vect;
+}
+
+void register_node_type_sh_vect_transform(void)
+{
+       static bNodeType ntype;
+
+       sh_node_type_base(&ntype, SH_NODE_VECT_TRANSFORM, "Vector Transform", NODE_CLASS_CONVERTOR, 0);
+       node_type_compatibility(&ntype, NODE_NEW_SHADING);
+       node_type_init(&ntype, node_shader_init_vect_transform);
+       node_type_socket_templates(&ntype, sh_node_vect_transform_in, sh_node_vect_transform_out);
+       node_type_storage(&ntype, "NodeShaderVectTransform", node_free_standard_storage, node_copy_standard_storage);
+
+       nodeRegisterType(&ntype);
+}