Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/nodes.cpp
| Show First 20 Lines • Show All 5,416 Lines • ▼ Show 20 Lines | NODE_DEFINE(MathNode) | ||||
| type_enum.insert("round", NODE_MATH_ROUND); | type_enum.insert("round", NODE_MATH_ROUND); | ||||
| type_enum.insert("less_than", NODE_MATH_LESS_THAN); | type_enum.insert("less_than", NODE_MATH_LESS_THAN); | ||||
| type_enum.insert("greater_than", NODE_MATH_GREATER_THAN); | type_enum.insert("greater_than", NODE_MATH_GREATER_THAN); | ||||
| type_enum.insert("modulo", NODE_MATH_MODULO); | type_enum.insert("modulo", NODE_MATH_MODULO); | ||||
| type_enum.insert("absolute", NODE_MATH_ABSOLUTE); | type_enum.insert("absolute", NODE_MATH_ABSOLUTE); | ||||
| type_enum.insert("arctan2", NODE_MATH_ARCTAN2); | type_enum.insert("arctan2", NODE_MATH_ARCTAN2); | ||||
| type_enum.insert("floor", NODE_MATH_FLOOR); | type_enum.insert("floor", NODE_MATH_FLOOR); | ||||
| type_enum.insert("ceil", NODE_MATH_CEIL); | type_enum.insert("ceil", NODE_MATH_CEIL); | ||||
| type_enum.insert("fract", NODE_MATH_FRACT); | type_enum.insert("fract", NODE_MATH_FRACTION); | ||||
| type_enum.insert("sqrt", NODE_MATH_SQRT); | type_enum.insert("sqrt", NODE_MATH_SQRT); | ||||
| SOCKET_ENUM(type, "Type", type_enum, NODE_MATH_ADD); | SOCKET_ENUM(type, "Type", type_enum, NODE_MATH_ADD); | ||||
| SOCKET_BOOLEAN(use_clamp, "Use Clamp", false); | SOCKET_IN_FLOAT(value1, "Value1", 0.5f); | ||||
| SOCKET_IN_FLOAT(value2, "Value2", 0.5f); | |||||
| SOCKET_IN_FLOAT(value1, "Value1", 0.0f); | |||||
| SOCKET_IN_FLOAT(value2, "Value2", 0.0f); | |||||
| SOCKET_OUT_FLOAT(value, "Value"); | SOCKET_OUT_FLOAT(value, "Value"); | ||||
| return type; | return type; | ||||
| } | } | ||||
| MathNode::MathNode() : ShaderNode(node_type) | MathNode::MathNode() : ShaderNode(node_type) | ||||
| { | { | ||||
| } | } | ||||
| void MathNode::expand(ShaderGraph *graph) | |||||
| { | |||||
| if (use_clamp) { | |||||
| ShaderOutput *result_out = output("Value"); | |||||
| if (!result_out->links.empty()) { | |||||
| ClampNode *clamp_node = new ClampNode(); | |||||
| clamp_node->min = 0.0f; | |||||
| clamp_node->max = 1.0f; | |||||
| graph->add(clamp_node); | |||||
| graph->relink(result_out, clamp_node->output("Result")); | |||||
| graph->connect(result_out, clamp_node->input("Value")); | |||||
| } | |||||
| } | |||||
| } | |||||
| void MathNode::constant_fold(const ConstantFolder &folder) | void MathNode::constant_fold(const ConstantFolder &folder) | ||||
| { | { | ||||
| if (folder.all_inputs_constant()) { | if (folder.all_inputs_constant()) { | ||||
| folder.make_constant_clamp(svm_math(type, value1, value2), use_clamp); | folder.make_constant(svm_math(type, value1, value2)); | ||||
| } | } | ||||
| else { | else { | ||||
| folder.fold_math(type, use_clamp); | folder.fold_math(type); | ||||
| } | } | ||||
| } | } | ||||
| void MathNode::compile(SVMCompiler &compiler) | void MathNode::compile(SVMCompiler &compiler) | ||||
| { | { | ||||
| ShaderInput *value1_in = input("Value1"); | ShaderInput *a_in = input("Value1"); | ||||
| ShaderInput *value2_in = input("Value2"); | ShaderInput *b_in = input("Value2"); | ||||
| ShaderOutput *value_out = output("Value"); | ShaderOutput *result_out = output("Value"); | ||||
| compiler.add_node( | int a_stack_offset = compiler.stack_assign(a_in); | ||||
| NODE_MATH, type, compiler.stack_assign(value1_in), compiler.stack_assign(value2_in)); | int b_stack_offset = compiler.stack_assign(b_in); | ||||
| compiler.add_node(NODE_MATH, compiler.stack_assign(value_out)); | int result_stack_offset = compiler.stack_assign(result_out); | ||||
| if (use_clamp) { | compiler.add_node(NODE_MATH, | ||||
| compiler.add_node(NODE_MATH, NODE_MATH_CLAMP, compiler.stack_assign(value_out)); | type, | ||||
| compiler.add_node(NODE_MATH, compiler.stack_assign(value_out)); | compiler.encode_uchar4(a_stack_offset, b_stack_offset), | ||||
| } | result_stack_offset); | ||||
| } | } | ||||
| void MathNode::compile(OSLCompiler &compiler) | void MathNode::compile(OSLCompiler &compiler) | ||||
| { | { | ||||
| compiler.parameter(this, "type"); | compiler.parameter(this, "type"); | ||||
| compiler.parameter(this, "use_clamp"); | |||||
| compiler.add(this, "node_math"); | compiler.add(this, "node_math"); | ||||
| } | } | ||||
| /* VectorMath */ | /* VectorMath */ | ||||
| NODE_DEFINE(VectorMathNode) | NODE_DEFINE(VectorMathNode) | ||||
| { | { | ||||
| NodeType *type = NodeType::add("vector_math", create, NodeType::SHADER); | NodeType *type = NodeType::add("vector_math", create, NodeType::SHADER); | ||||
| ▲ Show 20 Lines • Show All 903 Lines • Show Last 20 Lines | |||||