Integer socket support in Cycles. Int values are already supported natively in OSL...
[blender.git] / intern / cycles / render / nodes.cpp
index 73c4566543153263cfa6b92883483f5521daf1e2..76267e9d014acc9f2fae7be8dffd403941c8e506 100644 (file)
@@ -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)