Commit: 059b7a81e2a1ce19ac3c4262bd86eb8d961d5582 Author: Thomas Dinges Date: Wed Dec 23 21:41:59 2015 +0100 Branches: master https://developer.blender.org/rB059b7a81e2a1ce19ac3c4262bd86eb8d961d5582
Cycles: Implement constant fold for the ConvertNode. This way socket type conversions (such as color to float, or float to vector) do not stop the folding process. Example: http://www.pasteall.org/pic/show.php?id=96803 (selected nodes are folded). =================================================================== M intern/cycles/render/nodes.cpp M intern/cycles/render/nodes.h =================================================================== diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 74a0d20..870efda 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -1621,6 +1621,56 @@ ConvertNode::ConvertNode(ShaderSocketType from_, ShaderSocketType to_, bool auto assert(0); } +bool ConvertNode::constant_fold(ShaderOutput *socket, float3 *optimized_value) +{ + ShaderInput *in = inputs[0]; + float3 value = in->value; + + /* TODO(DingTo): conversion from/to int is not supported yet, don't fold in that case */ + + if(socket == outputs[0] && in->link == NULL) { + if(from == SHADER_SOCKET_FLOAT) { + if(to == SHADER_SOCKET_INT) + /* float to int */ + return false; + else + /* float to float3 */ + *optimized_value = make_float3(value.x, value.x, value.x); + } + else if(from == SHADER_SOCKET_INT) { + if(to == SHADER_SOCKET_FLOAT) + /* int to float */ + return false; + else + /* int to vector/point/normal */ + return false; + } + else if(to == SHADER_SOCKET_FLOAT) { + if(from == SHADER_SOCKET_COLOR) + /* color to float */ + optimized_value->x = linear_rgb_to_gray(value); + else + /* vector/point/normal to float */ + optimized_value->x = average(value); + } + else if(to == SHADER_SOCKET_INT) { + if(from == SHADER_SOCKET_COLOR) + /* color to int */ + return false; + else + /* vector/point/normal to int */ + return false; + } + else { + *optimized_value = value; + } + + return true; + } + + return false; +} + void ConvertNode::compile(SVMCompiler& compiler) { ShaderInput *in = inputs[0]; diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 8c5f665..5d0a9eb 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -252,6 +252,8 @@ public: ConvertNode(ShaderSocketType from, ShaderSocketType to, bool autoconvert = false); SHADER_NODE_BASE_CLASS(ConvertNode) + bool constant_fold(ShaderOutput *socket, float3 *optimized_value); + ShaderSocketType from, to; }; _______________________________________________ Bf-blender-cvs mailing list [email protected] http://lists.blender.org/mailman/listinfo/bf-blender-cvs
