Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2011-12-02 01:46:10 +0400
committerDalai Felinto <dfelinto@gmail.com>2011-12-02 01:46:10 +0400
commit4db4a0933f8cef74a27561fa26e79ceab9021d67 (patch)
treedc641c5e8b4ab74fbdd51b13d6b115be2b7d5142 /intern
parentb7db2587fb839ff8586ca377c8cc93175e38f470 (diff)
SeparateRGB and CombineRGB nodes for Cycles materials
reviewed and approved by Brecht my first OpenCL code \o/
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/app/cycles_xml.cpp6
-rw-r--r--intern/cycles/blender/blender_shader.cpp10
-rw-r--r--intern/cycles/kernel/CMakeLists.txt1
-rw-r--r--intern/cycles/kernel/osl/nodes/CMakeLists.txt1
-rw-r--r--intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl40
-rw-r--r--intern/cycles/kernel/svm/svm.h7
-rw-r--r--intern/cycles/kernel/svm/svm_sepcomb_rgb.h38
-rw-r--r--intern/cycles/kernel/svm/svm_types.h4
-rw-r--r--intern/cycles/render/nodes.cpp68
-rw-r--r--intern/cycles/render/nodes.h10
10 files changed, 182 insertions, 3 deletions
diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp
index 5f9e1d7a5ff..d89c30619b6 100644
--- a/intern/cycles/app/cycles_xml.cpp
+++ b/intern/cycles/app/cycles_xml.cpp
@@ -471,6 +471,12 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug
xml_read_enum(&mix->type, MixNode::type_enum, node, "type");
snode = mix;
}
+ else if(string_iequals(node.name(), "combine_rgb")) {
+ snode = new CombineRGBNode();
+ }
+ else if(string_iequals(node.name(), "separate_rgb")) {
+ snode = new SeparateRGBNode();
+ }
else if(string_iequals(node.name(), "attribute")) {
AttributeNode *attr = new AttributeNode();
xml_read_ustring(&attr->attribute, node, "attribute");
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index cf8527b9760..dfca9d7173a 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -128,7 +128,6 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node *
switch(b_node.type()) {
/* not supported */
case BL::ShaderNode::type_CAMERA: break;
- case BL::ShaderNode::type_COMBRGB: break;
case BL::ShaderNode::type_CURVE_RGB: break;
case BL::ShaderNode::type_CURVE_VEC: break;
case BL::ShaderNode::type_GEOMETRY: break;
@@ -139,7 +138,6 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node *
case BL::ShaderNode::type_NORMAL: break;
case BL::ShaderNode::type_OUTPUT: break;
case BL::ShaderNode::type_SCRIPT: break;
- case BL::ShaderNode::type_SEPRGB: break;
case BL::ShaderNode::type_SQUEEZE: break;
case BL::ShaderNode::type_TEXTURE: break;
case BL::ShaderNode::type_VALTORGB: break;
@@ -165,6 +163,14 @@ static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node *
node = mix;
break;
}
+ case BL::ShaderNode::type_SEPRGB: {
+ node = new SeparateRGBNode();
+ break;
+ }
+ case BL::ShaderNode::type_COMBRGB: {
+ node = new CombineRGBNode();
+ break;
+ }
case BL::ShaderNode::type_RGBTOBW: {
node = new ConvertNode(SHADER_SOCKET_COLOR, SHADER_SOCKET_FLOAT);
break;
diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt
index 73425486be1..abe81103d80 100644
--- a/intern/cycles/kernel/CMakeLists.txt
+++ b/intern/cycles/kernel/CMakeLists.txt
@@ -69,6 +69,7 @@ set(SRC_SVM_HEADERS
svm/svm_musgrave.h
svm/svm_noise.h
svm/svm_noisetex.h
+ svm/svm_sepcomb_rgb.h
svm/svm_sky.h
svm/svm_tex_coord.h
svm/svm_texture.h
diff --git a/intern/cycles/kernel/osl/nodes/CMakeLists.txt b/intern/cycles/kernel/osl/nodes/CMakeLists.txt
index 1b8b81eb6f6..34729145f28 100644
--- a/intern/cycles/kernel/osl/nodes/CMakeLists.txt
+++ b/intern/cycles/kernel/osl/nodes/CMakeLists.txt
@@ -35,6 +35,7 @@ set(SRC_OSL
node_output_displacement.osl
node_output_surface.osl
node_output_volume.osl
+ node_sepcomb_rgb.osl
node_sky_texture.osl
node_stucci_texture.osl
node_texture_coordinate.osl
diff --git a/intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl b/intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl
new file mode 100644
index 00000000000..a02f31f4b07
--- /dev/null
+++ b/intern/cycles/kernel/osl/nodes/node_sepcomb_rgb.osl
@@ -0,0 +1,40 @@
+/*
+ * 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_separate_rgb(
+ color Image = color(0.8, 0.8, 0.8),
+ output float R = 0.0,
+ output float G = 0.0,
+ output float B = 0.0)
+{
+ R = Image[0];
+ G = Image[1];
+ B = Image[2];
+}
+
+shader node_combine_rgb(
+ float R = 0.0,
+ float G = 0.0,
+ float B = 0.0,
+ output color Image = color(0.8, 0.8, 0.8)
+{
+ Image = color(R, G, B)
+}
+
diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h
index 2615272691c..3073aefc272 100644
--- a/intern/cycles/kernel/svm/svm.h
+++ b/intern/cycles/kernel/svm/svm.h
@@ -134,6 +134,7 @@ CCL_NAMESPACE_END
#include "svm_wave.h"
#include "svm_math.h"
#include "svm_mix.h"
+#include "svm_sepcomb_rgb.h"
#include "svm_musgrave.h"
#include "svm_sky.h"
#include "svm_tex_coord.h"
@@ -254,6 +255,12 @@ __device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ShaderT
case NODE_MIX:
svm_node_mix(kg, sd, stack, node.y, node.z, node.w, &offset);
break;
+ case NODE_SEPARATE_RGB:
+ svm_node_separate_rgb(sd, stack, node.y, node.z, node.w);
+ break;
+ case NODE_COMBINE_RGB:
+ svm_node_combine_rgb(sd, stack, node.y, node.z, node.w);
+ break;
case NODE_ATTR:
svm_node_attr(kg, sd, stack, node);
break;
diff --git a/intern/cycles/kernel/svm/svm_sepcomb_rgb.h b/intern/cycles/kernel/svm/svm_sepcomb_rgb.h
new file mode 100644
index 00000000000..5d3afef5566
--- /dev/null
+++ b/intern/cycles/kernel/svm/svm_sepcomb_rgb.h
@@ -0,0 +1,38 @@
+/*
+ * 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_combine_rgb(ShaderData *sd, float *stack, uint in_offset, uint color_index, uint out_offset)
+{
+ float color = stack_load_float(stack, in_offset);
+
+ if (stack_valid(out_offset))
+ stack_store_float(stack, out_offset+color_index, color);
+}
+
+__device void svm_node_separate_rgb(ShaderData *sd, float *stack, uint icolor_offset, uint color_index, uint out_offset)
+{
+ float3 color = stack_load_float3(stack, icolor_offset);
+
+ if (stack_valid(out_offset))
+ stack_store_float(stack, out_offset, color[color_index]);
+}
+
+CCL_NAMESPACE_END
+
diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h
index 071477a83c7..cde5e662fa7 100644
--- a/intern/cycles/kernel/svm/svm_types.h
+++ b/intern/cycles/kernel/svm/svm_types.h
@@ -79,7 +79,9 @@ typedef enum NodeType {
NODE_TEX_ENVIRONMENT = 4600,
NODE_CLOSURE_HOLDOUT = 4700,
NODE_LAYER_WEIGHT = 4800,
- NODE_CLOSURE_VOLUME = 4900
+ NODE_CLOSURE_VOLUME = 4900,
+ NODE_SEPARATE_RGB = 5000,
+ NODE_COMBINE_RGB = 5100
} NodeType;
typedef enum NodeAttributeType {
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index d7bd74c9ec7..0020a3c5d1b 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -1629,6 +1629,74 @@ void MixNode::compile(OSLCompiler& compiler)
compiler.add(this, "node_mix");
}
+/* Combine RGB */
+CombineRGBNode::CombineRGBNode()
+: ShaderNode("combine_rgb")
+{
+ add_input("R", SHADER_SOCKET_FLOAT);
+ add_input("G", SHADER_SOCKET_FLOAT);
+ add_input("B", SHADER_SOCKET_FLOAT);
+ add_output("Image", SHADER_SOCKET_COLOR);
+}
+
+void CombineRGBNode::compile(SVMCompiler& compiler)
+{
+ ShaderInput *red_in = input("R");
+ ShaderInput *green_in = input("G");
+ ShaderInput *blue_in = input("B");
+ ShaderOutput *color_out = output("Image");
+
+ compiler.stack_assign(color_out);
+
+ compiler.stack_assign(red_in);
+ compiler.add_node(NODE_COMBINE_RGB, red_in->stack_offset, 0, color_out->stack_offset);
+
+ compiler.stack_assign(green_in);
+ compiler.add_node(NODE_COMBINE_RGB, green_in->stack_offset, 1, color_out->stack_offset);
+
+ compiler.stack_assign(blue_in);
+ compiler.add_node(NODE_COMBINE_RGB, blue_in->stack_offset, 2, color_out->stack_offset);
+}
+
+void CombineRGBNode::compile(OSLCompiler& compiler)
+{
+ compiler.add(this, "node_combine_rgb");
+}
+
+/* Separate RGB */
+SeparateRGBNode::SeparateRGBNode()
+: ShaderNode("separate_rgb")
+{
+ add_input("Image", SHADER_SOCKET_COLOR);
+ add_output("R", SHADER_SOCKET_FLOAT);
+ add_output("G", SHADER_SOCKET_FLOAT);
+ add_output("B", SHADER_SOCKET_FLOAT);
+}
+
+void SeparateRGBNode::compile(SVMCompiler& compiler)
+{
+ ShaderInput *color_in = input("Image");
+ ShaderOutput *red_out = output("R");
+ ShaderOutput *green_out = output("G");
+ ShaderOutput *blue_out = output("B");
+
+ compiler.stack_assign(color_in);
+
+ compiler.stack_assign(red_out);
+ compiler.add_node(NODE_SEPARATE_RGB, color_in->stack_offset, 0, red_out->stack_offset);
+
+ compiler.stack_assign(green_out);
+ compiler.add_node(NODE_SEPARATE_RGB, color_in->stack_offset, 1, green_out->stack_offset);
+
+ compiler.stack_assign(blue_out);
+ compiler.add_node(NODE_SEPARATE_RGB, color_in->stack_offset, 2, blue_out->stack_offset);
+}
+
+void SeparateRGBNode::compile(OSLCompiler& compiler)
+{
+ compiler.add(this, "node_separate_rgb");
+}
+
/* Attribute */
AttributeNode::AttributeNode()
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index d9cbd7ff589..4cc76b0f71e 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -292,6 +292,16 @@ public:
static ShaderEnum type_enum;
};
+class CombineRGBNode : public ShaderNode {
+public:
+ SHADER_NODE_CLASS(CombineRGBNode)
+};
+
+class SeparateRGBNode : public ShaderNode {
+public:
+ SHADER_NODE_CLASS(SeparateRGBNode)
+};
+
class AttributeNode : public ShaderNode {
public:
SHADER_NODE_CLASS(AttributeNode)