Cycles: Add dedicated nodes to split/combine vectors.
authorThomas Dinges <blender@dingto.org>
Fri, 13 Jun 2014 19:44:48 +0000 (21:44 +0200)
committerThomas Dinges <blender@dingto.org>
Fri, 13 Jun 2014 19:59:14 +0000 (21:59 +0200)
This was already possible via the RGB nodes, but that seems weird.

18 files changed:
intern/cycles/app/cycles_xml.cpp
intern/cycles/blender/blender_shader.cpp
intern/cycles/kernel/CMakeLists.txt
intern/cycles/kernel/shaders/CMakeLists.txt
intern/cycles/kernel/shaders/node_combine_xyz.osl [new file with mode: 0644]
intern/cycles/kernel/shaders/node_separate_xyz.osl [new file with mode: 0644]
intern/cycles/kernel/svm/svm.h
intern/cycles/kernel/svm/svm_sepcomb_xyz.h [new file with mode: 0644]
intern/cycles/kernel/svm/svm_types.h
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h
release/scripts/startup/nodeitems_builtins.py
source/blender/blenkernel/BKE_node.h
source/blender/blenkernel/intern/node.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_sepcombXYZ.c [new file with mode: 0644]

index de554fba9544ed92d17993c9da54af2044812b5f..f50a952676f0608f59d74178d2224250523054b8 100644 (file)
@@ -633,6 +633,12 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug
                else if(string_iequals(node.name(), "separate_hsv")) {
                        snode = new SeparateHSVNode();
                }
+               else if(string_iequals(node.name(), "combine_xyz")) {
+                       snode = new CombineHSVNode();
+               }
+               else if(string_iequals(node.name(), "separate_xyz")) {
+                       snode = new SeparateHSVNode();
+               }
                else if(string_iequals(node.name(), "hsv")) {
                        snode = new HSVNode();
                }
index 379e27c558ce0658cb2f68d8c4eb56987338f30f..bce236530b93dcc21c2bea6f690bda9f28e8ac6e 100644 (file)
@@ -244,6 +244,12 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
        else if (b_node.is_a(&RNA_ShaderNodeCombineHSV)) {
                node = new CombineHSVNode();
        }
+       else if (b_node.is_a(&RNA_ShaderNodeSeparateXYZ)) {
+               node = new SeparateXYZNode();
+       }
+       else if (b_node.is_a(&RNA_ShaderNodeCombineXYZ)) {
+               node = new CombineXYZNode();
+       }
        else if (b_node.is_a(&RNA_ShaderNodeHueSaturation)) {
                node = new HSVNode();
        }
index 994fba7a1d36e3e444bdb9a516d634ea1458e710..62d56b465091f723530f56aba92e6e6cbc142b47 100644 (file)
@@ -97,6 +97,7 @@ set(SRC_SVM_HEADERS
        svm/svm_ramp.h
        svm/svm_sepcomb_rgb.h
        svm/svm_sepcomb_hsv.h
+       svm/svm_sepcomb_xyz.h
        svm/svm_sky.h
        svm/svm_tex_coord.h
        svm/svm_texture.h
index 5518d652bf95607181c50382199d6874870ae02c..b164c2a03f7b5eb094a458d7bb2fa8624f2705b5 100644 (file)
@@ -13,6 +13,7 @@ set(SRC_OSL
        node_checker_texture.osl
        node_combine_rgb.osl
        node_combine_hsv.osl
+       node_combine_xyz.osl
        node_convert_from_color.osl
        node_convert_from_float.osl
        node_convert_from_int.osl
@@ -57,6 +58,7 @@ set(SRC_OSL
        node_rgb_ramp.osl
        node_separate_rgb.osl
        node_separate_hsv.osl
+       node_separate_xyz.osl
        node_set_normal.osl
        node_sky_texture.osl
        node_subsurface_scattering.osl
diff --git a/intern/cycles/kernel/shaders/node_combine_xyz.osl b/intern/cycles/kernel/shaders/node_combine_xyz.osl
new file mode 100644 (file)
index 0000000..933dee5
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2011-2014 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_combine_xyz(
+       float X = 0.0,
+       float Y = 0.0,
+       float Z = 0.0,
+       output vector Vector = 0.8)
+{
+       Vector = vector(X, Y, Z);
+}
+
diff --git a/intern/cycles/kernel/shaders/node_separate_xyz.osl b/intern/cycles/kernel/shaders/node_separate_xyz.osl
new file mode 100644 (file)
index 0000000..63725cb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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_separate_xyz(
+       vector Vector = 0.8,
+       output float X = 0.0,
+       output float Y = 0.0,
+       output float Z = 0.0)
+{
+       X = Vector[0];
+       Y = Vector[1];
+       Z = Vector[2];
+}
index 6d556a66afa65e3dcd132c4422d1b336df296bf5..acdc5183e185117b71e49fa6b3b4a47e50efd2da 100644 (file)
@@ -169,6 +169,7 @@ CCL_NAMESPACE_END
 #include "svm_ramp.h"
 #include "svm_sepcomb_rgb.h"
 #include "svm_sepcomb_hsv.h"
+#include "svm_sepcomb_xyz.h"
 #include "svm_musgrave.h"
 #include "svm_sky.h"
 #include "svm_tex_coord.h"
@@ -333,6 +334,12 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, Shade
                        case NODE_COMBINE_RGB:
                                svm_node_combine_rgb(sd, stack, node.y, node.z, node.w);
                                break;
+                       case NODE_SEPARATE_XYZ:
+                               svm_node_separate_xyz(sd, stack, node.y, node.z, node.w);
+                               break;
+                       case NODE_COMBINE_XYZ:
+                               svm_node_combine_xyz(sd, stack, node.y, node.z, node.w);
+                               break;
                        case NODE_SEPARATE_HSV:
                                svm_node_separate_hsv(kg, sd, stack, node.y, node.z, node.w, &offset);
                                break;
diff --git a/intern/cycles/kernel/svm/svm_sepcomb_xyz.h b/intern/cycles/kernel/svm/svm_sepcomb_xyz.h
new file mode 100644 (file)
index 0000000..f9f9664
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2011-2014 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
+ */
+
+CCL_NAMESPACE_BEGIN
+
+ccl_device void svm_node_combine_xyz(ShaderData *sd, float *stack, uint in_offset, uint vector_index, uint out_offset)
+{
+       float vector = stack_load_float(stack, in_offset);
+
+       if (stack_valid(out_offset))
+               stack_store_float(stack, out_offset+vector_index, vector);
+}
+
+ccl_device void svm_node_separate_xyz(ShaderData *sd, float *stack, uint ivector_offset, uint vector_index, uint out_offset)
+{
+       float3 vector = stack_load_float3(stack, ivector_offset);
+
+       if (stack_valid(out_offset)) {
+               if (vector_index == 0)
+                       stack_store_float(stack, out_offset, vector.x);
+               else if (vector_index == 1)
+                       stack_store_float(stack, out_offset, vector.y);
+               else
+                       stack_store_float(stack, out_offset, vector.z);
+       }
+}
+
+CCL_NAMESPACE_END
+
index fda035fdbe08e4c84a571b7ff2e9af59990127da..29a0d264237484dd66e239248f4841e5352885a0 100644 (file)
@@ -80,6 +80,8 @@ typedef enum NodeType {
        NODE_CLOSURE_VOLUME,
        NODE_SEPARATE_RGB,
        NODE_COMBINE_RGB,
+       NODE_SEPARATE_XYZ,
+       NODE_COMBINE_XYZ,
        NODE_SEPARATE_HSV,
        NODE_COMBINE_HSV,
        NODE_HSV,
index 2d7f9ea848b0cf2eadfce1e625eab1d864ba03d0..d49a719f4e74144a35a09759ad22765563e1380d 100644 (file)
@@ -3056,6 +3056,40 @@ void CombineRGBNode::compile(OSLCompiler& compiler)
        compiler.add(this, "node_combine_rgb");
 }
 
+/* Combine XYZ */
+CombineXYZNode::CombineXYZNode()
+: ShaderNode("combine_xyz")
+{
+       add_input("X", SHADER_SOCKET_FLOAT);
+       add_input("Y", SHADER_SOCKET_FLOAT);
+       add_input("Z", SHADER_SOCKET_FLOAT);
+       add_output("Vector", SHADER_SOCKET_VECTOR);
+}
+
+void CombineXYZNode::compile(SVMCompiler& compiler)
+{
+       ShaderInput *x_in = input("X");
+       ShaderInput *y_in = input("Y");
+       ShaderInput *z_in = input("Z");
+       ShaderOutput *vector_out = output("Vector");
+
+       compiler.stack_assign(vector_out);
+
+       compiler.stack_assign(x_in);
+       compiler.add_node(NODE_COMBINE_XYZ, x_in->stack_offset, 0, vector_out->stack_offset);
+
+       compiler.stack_assign(y_in);
+       compiler.add_node(NODE_COMBINE_XYZ, y_in->stack_offset, 1, vector_out->stack_offset);
+
+       compiler.stack_assign(z_in);
+       compiler.add_node(NODE_COMBINE_XYZ, z_in->stack_offset, 2, vector_out->stack_offset);
+}
+
+void CombineXYZNode::compile(OSLCompiler& compiler)
+{
+       compiler.add(this, "node_combine_xyz");
+}
+
 /* Combine HSV */
 CombineHSVNode::CombineHSVNode()
 : ShaderNode("combine_hsv")
@@ -3180,6 +3214,40 @@ void SeparateRGBNode::compile(OSLCompiler& compiler)
        compiler.add(this, "node_separate_rgb");
 }
 
+/* Separate XYZ */
+SeparateXYZNode::SeparateXYZNode()
+: ShaderNode("separate_xyz")
+{
+       add_input("Vector", SHADER_SOCKET_VECTOR);
+       add_output("X", SHADER_SOCKET_FLOAT);
+       add_output("Y", SHADER_SOCKET_FLOAT);
+       add_output("Z", SHADER_SOCKET_FLOAT);
+}
+
+void SeparateXYZNode::compile(SVMCompiler& compiler)
+{
+       ShaderInput *vector_in = input("Vector");
+       ShaderOutput *x_out = output("X");
+       ShaderOutput *y_out = output("Y");
+       ShaderOutput *z_out = output("Z");
+
+       compiler.stack_assign(vector_in);
+
+       compiler.stack_assign(x_out);
+       compiler.add_node(NODE_SEPARATE_XYZ, vector_in->stack_offset, 0, x_out->stack_offset);
+
+       compiler.stack_assign(y_out);
+       compiler.add_node(NODE_SEPARATE_XYZ, vector_in->stack_offset, 1, y_out->stack_offset);
+
+       compiler.stack_assign(z_out);
+       compiler.add_node(NODE_SEPARATE_XYZ, vector_in->stack_offset, 2, z_out->stack_offset);
+}
+
+void SeparateXYZNode::compile(OSLCompiler& compiler)
+{
+       compiler.add(this, "node_separate_xyz");
+}
+
 /* Separate HSV */
 SeparateHSVNode::SeparateHSVNode()
 : ShaderNode("separate_hsv")
index 8bdce9901b28142cb81e6d582344aaf4d896c3aa..cf89bdadaa28f20d55aa8e92fba5df75aff0410c 100644 (file)
@@ -451,6 +451,11 @@ public:
        SHADER_NODE_CLASS(CombineHSVNode)
 };
 
+class CombineXYZNode : public ShaderNode {
+public:
+       SHADER_NODE_CLASS(CombineXYZNode)
+};
+
 class GammaNode : public ShaderNode {
 public:
        SHADER_NODE_CLASS(GammaNode)
@@ -471,6 +476,11 @@ public:
        SHADER_NODE_CLASS(SeparateHSVNode)
 };
 
+class SeparateXYZNode : public ShaderNode {
+public:
+       SHADER_NODE_CLASS(SeparateXYZNode)
+};
+
 class HSVNode : public ShaderNode {
 public:
        SHADER_NODE_CLASS(HSVNode)
index 34c0739d50c7e2508a754b555ced9bdc764980bc..55f42ada8c032728ebbdebeb81ee9f0ba1474519 100644 (file)
@@ -234,6 +234,8 @@ shader_node_categories = [
         NodeItem("ShaderNodeVectorMath"),
         NodeItem("ShaderNodeSeparateRGB"),
         NodeItem("ShaderNodeCombineRGB"),
+        NodeItem("ShaderNodeSeparateXYZ"),
+        NodeItem("ShaderNodeCombineXYZ"),
         NodeItem("ShaderNodeSeparateHSV"),
         NodeItem("ShaderNodeCombineHSV"),
         NodeItem("ShaderNodeWavelength"),
index 13a32ee15284595cb6c0efd36bc81b8fbcd6b288..c81133a85fa431c077565e2965012f6f2a01357c 100644 (file)
@@ -727,7 +727,7 @@ struct ShadeResult;
 #define SH_NODE_BRIGHTCONTRAST                 165
 #define SH_NODE_LIGHT_FALLOFF                  166
 #define SH_NODE_OBJECT_INFO                            167
-#define SH_NODE_PARTICLE_INFO           168
+#define SH_NODE_PARTICLE_INFO                  168
 #define SH_NODE_TEX_BRICK                              169
 #define SH_NODE_BUMP                                   170
 #define SH_NODE_SCRIPT                                 171
@@ -746,7 +746,9 @@ struct ShadeResult;
 #define SH_NODE_COMBHSV                                        184
 #define SH_NODE_BSDF_HAIR                              185
 #define SH_NODE_LAMP                                   186
-#define SH_NODE_UVMAP                   187
+#define SH_NODE_UVMAP                                  187
+#define SH_NODE_SEPXYZ                                 188
+#define SH_NODE_COMBXYZ                                        189
 
 /* custom defines options for Material node */
 #define SH_NODE_MAT_DIFF   1
index c11611a1f655e36dab95745d1c241e79f1397623..c8632a40d1a0fa091d5f5caade690e604e390293 100644 (file)
@@ -3495,6 +3495,8 @@ static void registerShaderNodes(void)
        register_node_type_sh_combrgb();
        register_node_type_sh_sephsv();
        register_node_type_sh_combhsv();
+       register_node_type_sh_sepxyz();
+       register_node_type_sh_combxyz();
        register_node_type_sh_hue_sat();
 
        register_node_type_sh_attribute();
index 754a3c11d78bbe531d59b47758d8e64d0c4b7064..6fed0d16848c90e38e77f9f5f3bb9f9f4b7b2ef0 100644 (file)
@@ -144,6 +144,7 @@ set(SRC
        shader/nodes/node_shader_rgb.c
        shader/nodes/node_shader_sepcombRGB.c
        shader/nodes/node_shader_sepcombHSV.c
+       shader/nodes/node_shader_sepcombXYZ.c
        shader/nodes/node_shader_squeeze.c
        shader/nodes/node_shader_texture.c
        shader/nodes/node_shader_valToRgb.c
index 91b103da0e228b73fdaf03cd9803c26c79d6c828..255ad568bad2a01e15b31076a42a17a5fd2b8f7c 100644 (file)
@@ -71,6 +71,8 @@ void register_node_type_sh_seprgb(void);
 void register_node_type_sh_combrgb(void);
 void register_node_type_sh_sephsv(void);
 void register_node_type_sh_combhsv(void);
+void register_node_type_sh_sepxyz(void);
+void register_node_type_sh_combxyz(void);
 void register_node_type_sh_hue_sat(void);
 void register_node_type_sh_tex_brick(void);
 
index 434e737772d9500430a528e3bc44989f19fc6943..3e5de09ff6cc145624ed37d9c23278dd225086c4 100644 (file)
@@ -120,6 +120,8 @@ DefNode( ShaderNode,     SH_NODE_VECT_TRANSFORM,     def_sh_vect_transform,  "VE
 DefNode( ShaderNode,     SH_NODE_SEPHSV,             0,                      "SEPHSV",             SeparateHSV,      "Separate HSV",      ""       )
 DefNode( ShaderNode,     SH_NODE_COMBHSV,            0,                      "COMBHSV",            CombineHSV,       "Combine HSV",       ""       )
 DefNode( ShaderNode,     SH_NODE_UVMAP,              def_sh_uvmap,           "UVMAP",              UVMap,            "UV Map",            ""       )
+DefNode( ShaderNode,     SH_NODE_SEPXYZ,             0,                      "SEPXYZ",             SeparateXYZ,      "Separate XYZ",      ""       )
+DefNode( ShaderNode,     SH_NODE_COMBXYZ,            0,                      "COMBXYZ",            CombineXYZ,       "Combine XYZ",       ""       )
 
 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_sepcombXYZ.c b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c
new file mode 100644 (file)
index 0000000..b02a1a9
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * ***** 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) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Thomas Dinges
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/nodes/shader/nodes/node_shader_sepcombXYZ.c
+ *  \ingroup shdnodes
+ */
+
+
+#include "node_shader_util.h"
+
+/* **************** SEPARATE XYZ ******************** */
+static bNodeSocketTemplate sh_node_sepxyz_in[] = {
+       {       SOCK_VECTOR, 1, N_("Vector"),                   0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f},
+       {       -1, 0, ""       }
+};
+static bNodeSocketTemplate sh_node_sepxyz_out[] = {
+       {       SOCK_FLOAT, 0, N_("X")},
+       {       SOCK_FLOAT, 0, N_("Y")},
+       {       SOCK_FLOAT, 0, N_("Z")},
+       {       -1, 0, ""       }
+};
+
+static int gpu_shader_sep(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+{
+       return GPU_stack_link(mat, "separate_xyz", in, out);
+}
+
+void register_node_type_sh_sepxyz(void)
+{
+       static bNodeType ntype;
+
+       sh_node_type_base(&ntype, SH_NODE_SEPXYZ, "Separate XYZ", NODE_CLASS_CONVERTOR, 0);
+       node_type_compatibility(&ntype, NODE_NEW_SHADING);
+       node_type_socket_templates(&ntype, sh_node_sepxyz_in, sh_node_sepxyz_out);
+
+       nodeRegisterType(&ntype);
+}
+
+
+
+/* **************** COMBINE XYZ ******************** */
+static bNodeSocketTemplate sh_node_combxyz_in[] = {
+       {       SOCK_FLOAT, 1, N_("X"),                 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_UNSIGNED},
+       {       SOCK_FLOAT, 1, N_("Y"),                 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_UNSIGNED},
+       {       SOCK_FLOAT, 1, N_("Z"),                 0.0f, 0.0f, 0.0f, 1.0f, -10000.0f, 10000.0f, PROP_UNSIGNED},
+       {       -1, 0, ""       }
+};
+static bNodeSocketTemplate sh_node_combxyz_out[] = {
+       {       SOCK_VECTOR, 0, N_("Vector")},
+       {       -1, 0, ""       }
+};
+
+void register_node_type_sh_combxyz(void)
+{
+       static bNodeType ntype;
+
+       sh_node_type_base(&ntype, SH_NODE_COMBXYZ, "Combine XYZ", NODE_CLASS_CONVERTOR, 0);
+       node_type_compatibility(&ntype, NODE_NEW_SHADING);
+       node_type_socket_templates(&ntype, sh_node_combxyz_in, sh_node_combxyz_out);
+
+       nodeRegisterType(&ntype);
+}