diff options
author | Lukas Stockner <lukas.stockner@freenet.de> | 2016-06-21 01:19:51 +0300 |
---|---|---|
committer | Lukas Stockner <lukas.stockner@freenet.de> | 2016-06-21 01:19:51 +0300 |
commit | 93c6cf496edff358c919d62295c031fc5eebb155 (patch) | |
tree | 28fc7eba70a7c7f08e57aad8221ee2a454d9c498 /intern/cycles/render/nodes.cpp | |
parent | a170607578b8911df30039dacf7399506476be87 (diff) |
Cycles: Deduplicate Vector and RGB Curve nodes
Since most of the code for these two nodes was identical, this commit
now instead uses a common base class that implements all the functionality.
Diffstat (limited to 'intern/cycles/render/nodes.cpp')
-rw-r--r-- | intern/cycles/render/nodes.cpp | 108 |
1 files changed, 56 insertions, 52 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 5efbf65a198..1a9adb08194 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -4885,42 +4885,25 @@ bool BumpNode::constant_fold(ShaderGraph *graph, ShaderOutput *, ShaderInput *) return false; } -/* RGBCurvesNode */ - -NODE_DEFINE(RGBCurvesNode) -{ - NodeType* type = NodeType::add("rgb_curves", create, NodeType::SHADER); - - SOCKET_COLOR_ARRAY(curves, "Curves", array<float3>()); - SOCKET_FLOAT(min_x, "Min X", 0.0f); - SOCKET_FLOAT(max_x, "Max X", 1.0f); - - SOCKET_IN_FLOAT(fac, "Fac", 0.0f); - SOCKET_IN_COLOR(color, "Color", make_float3(0.0f, 0.0f, 0.0f)); - SOCKET_OUT_COLOR(color, "Color"); - - return type; -} +/* Curve node */ -RGBCurvesNode::RGBCurvesNode() +CurvesNode::CurvesNode(const NodeType *node_type) : ShaderNode(node_type) { } -void RGBCurvesNode::compile(SVMCompiler& compiler) +void CurvesNode::compile(SVMCompiler& compiler, int type, ShaderInput *value_in, ShaderOutput *value_out) { if(curves.size() == 0) return; ShaderInput *fac_in = input("Fac"); - ShaderInput *color_in = input("Color"); - ShaderOutput *color_out = output("Color"); - compiler.add_node(NODE_RGB_CURVES, + compiler.add_node(type, compiler.encode_uchar4(compiler.stack_assign(fac_in), - compiler.stack_assign(color_in), - compiler.stack_assign(color_out)), + compiler.stack_assign(value_in), + compiler.stack_assign(value_out)), __float_as_int(min_x), __float_as_int(max_x)); @@ -4929,7 +4912,7 @@ void RGBCurvesNode::compile(SVMCompiler& compiler) compiler.add_node(float3_to_float4(curves[i])); } -void RGBCurvesNode::compile(OSLCompiler& compiler) +void CurvesNode::compile(OSLCompiler& compiler, const char* name) { if(curves.size() == 0) return; @@ -4937,7 +4920,50 @@ void RGBCurvesNode::compile(OSLCompiler& compiler) compiler.parameter_color_array("ramp", curves); compiler.parameter(this, "min_x"); compiler.parameter(this, "max_x"); - compiler.add(this, "node_rgb_curves"); + compiler.add(this, name); +} + +void CurvesNode::compile(SVMCompiler& /*compiler*/) +{ + assert(0); +} + +void CurvesNode::compile(OSLCompiler& /*compiler*/) +{ + assert(0); +} + +/* RGBCurvesNode */ + +NODE_DEFINE(RGBCurvesNode) +{ + NodeType* type = NodeType::add("rgb_curves", create, NodeType::SHADER); + + SOCKET_COLOR_ARRAY(curves, "Curves", array<float3>()); + SOCKET_FLOAT(min_x, "Min X", 0.0f); + SOCKET_FLOAT(max_x, "Max X", 1.0f); + + SOCKET_IN_FLOAT(fac, "Fac", 0.0f); + SOCKET_IN_COLOR(value, "Color", make_float3(0.0f, 0.0f, 0.0f)); + + SOCKET_OUT_COLOR(value, "Color"); + + return type; +} + +RGBCurvesNode::RGBCurvesNode() +: CurvesNode(node_type) +{ +} + +void RGBCurvesNode::compile(SVMCompiler& compiler) +{ + CurvesNode::compile(compiler, NODE_RGB_CURVES, input("Color"), output("Color")); +} + +void RGBCurvesNode::compile(OSLCompiler& compiler) +{ + CurvesNode::compile(compiler, "node_rgb_curves"); } /* VectorCurvesNode */ @@ -4951,48 +4977,26 @@ NODE_DEFINE(VectorCurvesNode) SOCKET_FLOAT(max_x, "Max X", 1.0f); SOCKET_IN_FLOAT(fac, "Fac", 0.0f); - SOCKET_IN_VECTOR(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f)); + SOCKET_IN_VECTOR(value, "Vector", make_float3(0.0f, 0.0f, 0.0f)); - SOCKET_OUT_VECTOR(vector, "Vector"); + SOCKET_OUT_VECTOR(value, "Vector"); return type; } VectorCurvesNode::VectorCurvesNode() -: ShaderNode(node_type) +: CurvesNode(node_type) { } void VectorCurvesNode::compile(SVMCompiler& compiler) { - if(curves.size() == 0) - return; - - ShaderInput *fac_in = input("Fac"); - ShaderInput *vector_in = input("Vector"); - ShaderOutput *vector_out = output("Vector"); - - compiler.add_node(NODE_VECTOR_CURVES, - compiler.encode_uchar4(compiler.stack_assign(fac_in), - compiler.stack_assign(vector_in), - compiler.stack_assign(vector_out)), - __float_as_int(min_x), - __float_as_int(max_x)); - - compiler.add_node(curves.size()); - for(int i = 0; i < curves.size(); i++) - compiler.add_node(float3_to_float4(curves[i])); + CurvesNode::compile(compiler, NODE_VECTOR_CURVES, input("Vector"), output("Vector")); } void VectorCurvesNode::compile(OSLCompiler& compiler) { - if(curves.size() == 0) - return; - - compiler.parameter_color_array("ramp", curves); - compiler.parameter(this, "min_x"); - compiler.parameter(this, "max_x"); - compiler.add(this, "node_vector_curves"); + CurvesNode::compile(compiler, "node_vector_curves"); } /* RGBRampNode */ |