diff options
-rw-r--r-- | intern/cycles/app/cycles_xml.cpp | 1 | ||||
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 8 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/node_convert_from_color.osl | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/node_convert_from_float.osl | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/node_convert_from_int.osl | 36 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/node_convert_from_point.osl | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm.h | 19 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_convert.h | 28 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_types.h | 7 | ||||
-rw-r--r-- | intern/cycles/render/graph.h | 1 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 40 | ||||
-rw-r--r-- | intern/cycles/render/osl.cpp | 3 | ||||
-rw-r--r-- | intern/cycles/render/svm.cpp | 11 |
16 files changed, 152 insertions, 13 deletions
diff --git a/intern/cycles/app/cycles_xml.cpp b/intern/cycles/app/cycles_xml.cpp index 87a238e508c..5de9d71b8cc 100644 --- a/intern/cycles/app/cycles_xml.cpp +++ b/intern/cycles/app/cycles_xml.cpp @@ -591,6 +591,7 @@ static void xml_read_shader_graph(const XMLReadState& state, Shader *shader, pug if(string_iequals(in->name, attr.name())) { switch(in->type) { case SHADER_SOCKET_FLOAT: + case SHADER_SOCKET_INT: xml_read_float(&in->value.x, node, attr.name()); break; case SHADER_SOCKET_COLOR: diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 98ac8692f36..db34a9fe9aa 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -80,6 +80,8 @@ static ShaderSocketType convert_socket_type(BL::NodeSocket::type_enum b_type) switch (b_type) { case BL::NodeSocket::type_VALUE: return SHADER_SOCKET_FLOAT; + case BL::NodeSocket::type_INT: + return SHADER_SOCKET_INT; case BL::NodeSocket::type_VECTOR: return SHADER_SOCKET_VECTOR; case BL::NodeSocket::type_RGBA: @@ -89,7 +91,6 @@ static ShaderSocketType convert_socket_type(BL::NodeSocket::type_enum b_type) case BL::NodeSocket::type_BOOLEAN: case BL::NodeSocket::type_MESH: - case BL::NodeSocket::type_INT: default: return SHADER_SOCKET_FLOAT; } @@ -104,6 +105,11 @@ static void set_default_value(ShaderInput *input, BL::NodeSocket sock) input->set(value_sock.default_value()); break; } + case SHADER_SOCKET_INT: { + BL::NodeSocketIntNone value_sock(sock); + input->set((float)value_sock.default_value()); + break; + } case SHADER_SOCKET_COLOR: { BL::NodeSocketRGBA rgba_sock(sock); input->set(get_float3(rgba_sock.default_value())); diff --git a/intern/cycles/kernel/osl/nodes/CMakeLists.txt b/intern/cycles/kernel/osl/nodes/CMakeLists.txt index faf7941ee5e..2c459fd714b 100644 --- a/intern/cycles/kernel/osl/nodes/CMakeLists.txt +++ b/intern/cycles/kernel/osl/nodes/CMakeLists.txt @@ -12,6 +12,7 @@ set(SRC_OSL node_combine_rgb.osl node_convert_from_color.osl node_convert_from_float.osl + node_convert_from_int.osl node_convert_from_normal.osl node_convert_from_point.osl node_convert_from_vector.osl diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_color.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_color.osl index c55b0f811ff..2884c772414 100644 --- a/intern/cycles/kernel/osl/nodes/node_convert_from_color.osl +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_color.osl @@ -21,11 +21,13 @@ shader node_convert_from_color( color Color = color(0.0, 0.0, 0.0), output float Val = 0.0, + output int ValInt = 0, output vector Vector = vector(0.0, 0.0, 0.0), output point Point = point(0.0, 0.0, 0.0), output normal Normal = normal(0.0, 0.0, 0.0)) { Val = Color[0] * 0.2126 + Color[1] * 0.7152 + Color[2] * 0.0722; + ValInt = (int)(Color[0]*0.2126 + Color[1]*0.7152 + Color[2]*0.0722); Vector = vector(Color[0], Color[1], Color[2]); Point = point(Color[0], Color[1], Color[2]); Normal = normal(Color[0], Color[1], Color[2]); diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_float.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_float.osl index 00e78f3bab4..4466fbae3a6 100644 --- a/intern/cycles/kernel/osl/nodes/node_convert_from_float.osl +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_float.osl @@ -20,11 +20,13 @@ shader node_convert_from_float( float Val = 0.0, + output int ValInt = 0, output color Color = color(0.0, 0.0, 0.0), output vector Vector = vector(0.0, 0.0, 0.0), output point Point = point(0.0, 0.0, 0.0), output normal Normal = normal(0.0, 0.0, 0.0)) { + ValInt = (int)Val; Color = color(Val, Val, Val); Vector = vector(Val, Val, Val); Point = point(Val, Val, Val); diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_int.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_int.osl new file mode 100644 index 00000000000..060d4184fa6 --- /dev/null +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_int.osl @@ -0,0 +1,36 @@ +/* + * 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_convert_from_int( + int ValInt = 0, + output float Val = 0.0, + output color Color = color(0.0, 0.0, 0.0), + output vector Vector = vector(0.0, 0.0, 0.0), + output point Point = point(0.0, 0.0, 0.0), + output normal Normal = normal(0.0, 0.0, 0.0)) +{ + float f = (float)ValInt; + Val = f; + Color = color(f, f, f); + Vector = vector(f, f, f); + Point = point(f, f, f); + Normal = normal(f, f, f); +} + diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl index b2c6c76661c..419e93e1518 100644 --- a/intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_normal.osl @@ -21,11 +21,13 @@ shader node_convert_from_normal( normal Normal = normal(0.0, 0.0, 0.0), output float Val = 0.0, + output int ValInt = 0, output vector Vector = vector(0.0, 0.0, 0.0), output color Color = color(0.0, 0.0, 0.0), output point Point = point(0.0, 0.0, 0.0)) { Val = (Normal[0] + Normal[1] + Normal[2]) * (1.0 / 3.0); + ValInt = (int)((Normal[0] + Normal[1] + Normal[2])*(1.0/3.0)); Vector = vector(Normal[0], Normal[1], Normal[2]); Color = color(Normal[0], Normal[1], Normal[2]); Point = point(Normal[0], Normal[1], Normal[2]); diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_point.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_point.osl index ae9a17dbc80..cedd200f088 100644 --- a/intern/cycles/kernel/osl/nodes/node_convert_from_point.osl +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_point.osl @@ -21,11 +21,13 @@ shader node_convert_from_point( point Point = point(0.0, 0.0, 0.0), output float Val = 0.0, + output int ValInt = 0, output vector Vector = vector(0.0, 0.0, 0.0), output color Color = color(0.0, 0.0, 0.0), output normal Normal = normal(0.0, 0.0, 0.0)) { Val = (Point[0] + Point[1] + Point[2]) * (1.0 / 3.0); + ValInt = (int)((Normal[0] + Normal[1] + Normal[2])*(1.0/3.0)); Vector = vector(Point[0], Point[1], Point[2]); Color = color(Point[0], Point[1], Point[2]); Normal = normal(Point[0], Point[1], Point[2]); diff --git a/intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl b/intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl index 19ef9331c0c..a9f43a40074 100644 --- a/intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl +++ b/intern/cycles/kernel/osl/nodes/node_convert_from_vector.osl @@ -21,11 +21,13 @@ shader node_convert_from_vector( vector Vector = vector(0.0, 0.0, 0.0), output float Val = 0.0, + output int ValInt = 0, output color Color = color(0.0, 0.0, 0.0), output point Point = point(0.0, 0.0, 0.0), output normal Normal = normal(0.0, 0.0, 0.0)) { Val = (Vector[0] + Vector[1] + Vector[2]) * (1.0 / 3.0); + ValInt = (int)((Normal[0] + Normal[1] + Normal[2])*(1.0/3.0)); Color = color(Vector[0], Vector[1], Vector[2]); Point = point(Vector[0], Vector[1], Vector[2]); Normal = normal(Vector[0], Vector[1], Vector[2]); diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index 421eb146f88..698ef5016f0 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -82,6 +82,25 @@ __device_inline void stack_store_float(float *stack, uint a, float f) stack[a] = f; } +__device_inline int stack_load_int(float *stack, uint a) +{ + kernel_assert(a < SVM_STACK_SIZE); + + return __float_as_int(stack[a]); +} + +__device_inline float stack_load_int_default(float *stack, uint a, uint value) +{ + return (a == (uint)SVM_STACK_INVALID)? (int)value: stack_load_int(stack, a); +} + +__device_inline void stack_store_int(float *stack, uint a, int i) +{ + kernel_assert(a < SVM_STACK_SIZE); + + stack[a] = __int_as_float(i); +} + __device_inline bool stack_valid(uint a) { return a != (uint)SVM_STACK_INVALID; diff --git a/intern/cycles/kernel/svm/svm_convert.h b/intern/cycles/kernel/svm/svm_convert.h index 188b0489d9e..f74915a4bc9 100644 --- a/intern/cycles/kernel/svm/svm_convert.h +++ b/intern/cycles/kernel/svm/svm_convert.h @@ -23,6 +23,11 @@ CCL_NAMESPACE_BEGIN __device void svm_node_convert(ShaderData *sd, float *stack, uint type, uint from, uint to) { switch(type) { + case NODE_CONVERT_FI: { + float f = stack_load_float(stack, from); + stack_store_int(stack, to, (int)f); + break; + } case NODE_CONVERT_FV: { float f = stack_load_float(stack, from); stack_store_float3(stack, to, make_float3(f, f, f)); @@ -34,13 +39,34 @@ __device void svm_node_convert(ShaderData *sd, float *stack, uint type, uint fro stack_store_float(stack, to, g); break; } + case NODE_CONVERT_CI: { + float3 f = stack_load_float3(stack, from); + int i = (int)linear_rgb_to_gray(f); + stack_store_int(stack, to, i); + break; + } case NODE_CONVERT_VF: { float3 f = stack_load_float3(stack, from); float g = (f.x + f.y + f.z)*(1.0f/3.0f); stack_store_float(stack, to, g); break; } - + case NODE_CONVERT_VI: { + float3 f = stack_load_float3(stack, from); + int i = (f.x + f.y + f.z)*(1.0f/3.0f); + stack_store_int(stack, to, i); + break; + } + case NODE_CONVERT_IF: { + float f = (float)stack_load_int(stack, from); + stack_store_float(stack, to, f); + break; + } + case NODE_CONVERT_IV: { + float f = (float)stack_load_int(stack, from); + stack_store_float3(stack, to, make_float3(f, f, f)); + break; + } } } diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 487876ed417..77df373a159 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -210,8 +210,13 @@ typedef enum NodeVectorMath { typedef enum NodeConvert { NODE_CONVERT_FV, + NODE_CONVERT_FI, NODE_CONVERT_CF, - NODE_CONVERT_VF + NODE_CONVERT_CI, + NODE_CONVERT_VF, + NODE_CONVERT_VI, + NODE_CONVERT_IF, + NODE_CONVERT_IV } NodeConvert; typedef enum NodeDistanceMetric { diff --git a/intern/cycles/render/graph.h b/intern/cycles/render/graph.h index acafe1d5278..b339c3c3847 100644 --- a/intern/cycles/render/graph.h +++ b/intern/cycles/render/graph.h @@ -44,6 +44,7 @@ class OSLCompiler; enum ShaderSocketType { SHADER_SOCKET_FLOAT, + SHADER_SOCKET_INT, SHADER_SOCKET_COLOR, SHADER_SOCKET_VECTOR, SHADER_SOCKET_POINT, diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 73c45665431..76267e9d014 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -1065,6 +1065,8 @@ ConvertNode::ConvertNode(ShaderSocketType from_, ShaderSocketType to_) if(from == SHADER_SOCKET_FLOAT) add_input("Val", SHADER_SOCKET_FLOAT); + else if(from == SHADER_SOCKET_INT) + add_input("ValInt", SHADER_SOCKET_INT); else if(from == SHADER_SOCKET_COLOR) add_input("Color", SHADER_SOCKET_COLOR); else if(from == SHADER_SOCKET_VECTOR) @@ -1078,6 +1080,8 @@ ConvertNode::ConvertNode(ShaderSocketType from_, ShaderSocketType to_) if(to == SHADER_SOCKET_FLOAT) add_output("Val", SHADER_SOCKET_FLOAT); + else if(to == SHADER_SOCKET_INT) + add_output("ValInt", SHADER_SOCKET_INT); else if(to == SHADER_SOCKET_COLOR) add_output("Color", SHADER_SOCKET_COLOR); else if(to == SHADER_SOCKET_VECTOR) @@ -1095,10 +1099,29 @@ void ConvertNode::compile(SVMCompiler& compiler) ShaderInput *in = inputs[0]; ShaderOutput *out = outputs[0]; - if(to == SHADER_SOCKET_FLOAT) { + if(from == SHADER_SOCKET_FLOAT) { compiler.stack_assign(in); compiler.stack_assign(out); + if(to == SHADER_SOCKET_INT) + /* float to int */ + compiler.add_node(NODE_CONVERT, NODE_CONVERT_FI, in->stack_offset, out->stack_offset); + else + /* float to float3 */ + compiler.add_node(NODE_CONVERT, NODE_CONVERT_FV, in->stack_offset, out->stack_offset); + } + else if(from == SHADER_SOCKET_INT) { + compiler.stack_assign(in); + compiler.stack_assign(out); + + if(to == SHADER_SOCKET_FLOAT) + /* int to float */ + compiler.add_node(NODE_CONVERT, NODE_CONVERT_IF, in->stack_offset, out->stack_offset); + else + /* int to vector/point/normal */ + compiler.add_node(NODE_CONVERT, NODE_CONVERT_IV, in->stack_offset, out->stack_offset); + } + else if(to == SHADER_SOCKET_FLOAT) { if(from == SHADER_SOCKET_COLOR) /* color to float */ compiler.add_node(NODE_CONVERT, NODE_CONVERT_CF, in->stack_offset, out->stack_offset); @@ -1106,12 +1129,13 @@ void ConvertNode::compile(SVMCompiler& compiler) /* vector/point/normal to float */ compiler.add_node(NODE_CONVERT, NODE_CONVERT_VF, in->stack_offset, out->stack_offset); } - else if(from == SHADER_SOCKET_FLOAT) { - compiler.stack_assign(in); - compiler.stack_assign(out); - - /* float to float3 */ - compiler.add_node(NODE_CONVERT, NODE_CONVERT_FV, in->stack_offset, out->stack_offset); + else if(to == SHADER_SOCKET_INT) { + if(from == SHADER_SOCKET_COLOR) + /* color to int */ + compiler.add_node(NODE_CONVERT, NODE_CONVERT_CI, in->stack_offset, out->stack_offset); + else + /* vector/point/normal to int */ + compiler.add_node(NODE_CONVERT, NODE_CONVERT_VI, in->stack_offset, out->stack_offset); } else { /* float3 to float3 */ @@ -1134,6 +1158,8 @@ void ConvertNode::compile(OSLCompiler& compiler) { if(from == SHADER_SOCKET_FLOAT) compiler.add(this, "node_convert_from_float"); + else if(from == SHADER_SOCKET_INT) + compiler.add(this, "node_convert_from_int"); else if(from == SHADER_SOCKET_COLOR) compiler.add(this, "node_convert_from_color"); else if(from == SHADER_SOCKET_VECTOR) diff --git a/intern/cycles/render/osl.cpp b/intern/cycles/render/osl.cpp index 7fe7001ab51..21e6c7749b8 100644 --- a/intern/cycles/render/osl.cpp +++ b/intern/cycles/render/osl.cpp @@ -246,6 +246,9 @@ void OSLCompiler::add(ShaderNode *node, const char *name) case SHADER_SOCKET_FLOAT: parameter(param_name.c_str(), input->value.x); break; + case SHADER_SOCKET_INT: + parameter(param_name.c_str(), (int)input->value.x); + break; case SHADER_SOCKET_CLOSURE: break; } diff --git a/intern/cycles/render/svm.cpp b/intern/cycles/render/svm.cpp index 844ce01569f..c41d503b217 100644 --- a/intern/cycles/render/svm.cpp +++ b/intern/cycles/render/svm.cpp @@ -119,6 +119,8 @@ int SVMCompiler::stack_size(ShaderSocketType type) { if(type == SHADER_SOCKET_FLOAT) return 1; + else if(type == SHADER_SOCKET_INT) + return 1; else if(type == SHADER_SOCKET_COLOR) return 3; else if(type == SHADER_SOCKET_VECTOR) @@ -212,10 +214,13 @@ void SVMCompiler::stack_assign(ShaderInput *input) if(input->type == SHADER_SOCKET_FLOAT) { add_node(NODE_VALUE_F, __float_as_int(input->value.x), input->stack_offset); } + else if(input->type == SHADER_SOCKET_INT) { + add_node(NODE_VALUE_F, (int)input->value.x, input->stack_offset); + } else if(input->type == SHADER_SOCKET_VECTOR || - input->type == SHADER_SOCKET_NORMAL || - input->type == SHADER_SOCKET_POINT || - input->type == SHADER_SOCKET_COLOR) { + input->type == SHADER_SOCKET_NORMAL || + input->type == SHADER_SOCKET_POINT || + input->type == SHADER_SOCKET_COLOR) { add_node(NODE_VALUE_V, input->stack_offset); add_node(NODE_VALUE_V, input->value); |