Cycles bugfix: [32431] Cycles Math Node : Clamp does not work

the OSL solution is slightly different than the svm, but I think it's fine.

thanks Lukas Toenne for helping with a fix on the original patch
This commit is contained in:
Dalai Felinto
2012-08-29 17:30:14 +00:00
parent 7a13bc2196
commit c052ebda8e
6 changed files with 19 additions and 1 deletions

View File

@@ -244,6 +244,7 @@ static ShaderNode *add_node(BL::BlendData b_data, BL::Scene b_scene, ShaderGraph
BL::ShaderNodeMath b_math_node(b_node);
MathNode *math = new MathNode();
math->type = MathNode::type_enum[b_math_node.operation()];
math->use_clamp = b_math_node.use_clamp();
node = math;
break;
}

View File

@@ -40,6 +40,7 @@ float safe_log(float a, float b)
shader node_math(
string type = "Add",
int Clamp = false,
float Value1 = 0.0,
float Value2 = 0.0,
output float Value = 0.0)
@@ -80,5 +81,8 @@ shader node_math(
Value = Value1 < Value2;
if(type == "Greater Than")
Value = Value1 > Value2;
if(Clamp)
Value = clamp(Value1, 0.0, 1.0);
}

View File

@@ -108,6 +108,8 @@ __device float svm_math(NodeMath type, float Fac1, float Fac2)
Fac = Fac1 < Fac2;
else if(type == NODE_MATH_GREATER_THAN)
Fac = Fac1 > Fac2;
else if(type == NODE_MATH_CLAMP)
Fac = clamp(Fac1, 0.0f, 1.0f);
else
Fac = 0.0f;

View File

@@ -183,7 +183,8 @@ typedef enum NodeMath {
NODE_MATH_MAXIMUM,
NODE_MATH_ROUND,
NODE_MATH_LESS_THAN,
NODE_MATH_GREATER_THAN
NODE_MATH_GREATER_THAN,
NODE_MATH_CLAMP /* used for the clamp UI option */
} NodeMath;
typedef enum NodeVectorMath {

View File

@@ -2391,6 +2391,8 @@ MathNode::MathNode()
{
type = ustring("Add");
use_clamp = false;
add_input("Value1", SHADER_SOCKET_FLOAT);
add_input("Value2", SHADER_SOCKET_FLOAT);
add_output("Value", SHADER_SOCKET_FLOAT);
@@ -2435,11 +2437,17 @@ void MathNode::compile(SVMCompiler& compiler)
compiler.add_node(NODE_MATH, type_enum[type], value1_in->stack_offset, value2_in->stack_offset);
compiler.add_node(NODE_MATH, value_out->stack_offset);
if(use_clamp) {
compiler.add_node(NODE_MATH, NODE_MATH_CLAMP, value_out->stack_offset);
compiler.add_node(NODE_MATH, value_out->stack_offset);
}
}
void MathNode::compile(OSLCompiler& compiler)
{
compiler.parameter("type", type);
compiler.parameter("Clamp", use_clamp);
compiler.add(this, "node_math");
}

View File

@@ -385,6 +385,8 @@ class MathNode : public ShaderNode {
public:
SHADER_NODE_CLASS(MathNode)
bool use_clamp;
ustring type;
static ShaderEnum type_enum;
};