Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/nodes.cpp
| Show First 20 Lines • Show All 5,398 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| NodeType *type = NodeType::add("math", create, NodeType::SHADER); | NodeType *type = NodeType::add("math", create, NodeType::SHADER); | ||||
| static NodeEnum type_enum; | static NodeEnum type_enum; | ||||
| type_enum.insert("add", NODE_MATH_ADD); | type_enum.insert("add", NODE_MATH_ADD); | ||||
| type_enum.insert("subtract", NODE_MATH_SUBTRACT); | type_enum.insert("subtract", NODE_MATH_SUBTRACT); | ||||
| type_enum.insert("multiply", NODE_MATH_MULTIPLY); | type_enum.insert("multiply", NODE_MATH_MULTIPLY); | ||||
| type_enum.insert("divide", NODE_MATH_DIVIDE); | type_enum.insert("divide", NODE_MATH_DIVIDE); | ||||
| type_enum.insert("sine", NODE_MATH_SINE); | |||||
| type_enum.insert("cosine", NODE_MATH_COSINE); | |||||
| type_enum.insert("tangent", NODE_MATH_TANGENT); | |||||
| type_enum.insert("arcsine", NODE_MATH_ARCSINE); | |||||
| type_enum.insert("arccosine", NODE_MATH_ARCCOSINE); | |||||
| type_enum.insert("arctangent", NODE_MATH_ARCTANGENT); | |||||
| type_enum.insert("power", NODE_MATH_POWER); | type_enum.insert("power", NODE_MATH_POWER); | ||||
| type_enum.insert("logarithm", NODE_MATH_LOGARITHM); | type_enum.insert("logarithm", NODE_MATH_LOGARITHM); | ||||
| type_enum.insert("sqrt", NODE_MATH_SQRT); | |||||
| type_enum.insert("absolute", NODE_MATH_ABSOLUTE); | |||||
| type_enum.insert("minimum", NODE_MATH_MINIMUM); | type_enum.insert("minimum", NODE_MATH_MINIMUM); | ||||
| type_enum.insert("maximum", NODE_MATH_MAXIMUM); | type_enum.insert("maximum", NODE_MATH_MAXIMUM); | ||||
| 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("absolute", NODE_MATH_ABSOLUTE); | type_enum.insert("round", NODE_MATH_ROUND); | ||||
| 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("fraction", NODE_MATH_FRACTION); | ||||
| type_enum.insert("sqrt", NODE_MATH_SQRT); | type_enum.insert("modulo", NODE_MATH_MODULO); | ||||
| SOCKET_ENUM(type, "Type", type_enum, NODE_MATH_ADD); | |||||
| SOCKET_BOOLEAN(use_clamp, "Use Clamp", false); | type_enum.insert("sine", NODE_MATH_SINE); | ||||
| type_enum.insert("cosine", NODE_MATH_COSINE); | |||||
| type_enum.insert("tangent", NODE_MATH_TANGENT); | |||||
| type_enum.insert("arcsine", NODE_MATH_ARCSINE); | |||||
| type_enum.insert("arccosine", NODE_MATH_ARCCOSINE); | |||||
| type_enum.insert("arctangent", NODE_MATH_ARCTANGENT); | |||||
| type_enum.insert("arctan2", NODE_MATH_ARCTAN2); | |||||
| SOCKET_ENUM(type, "Type", type_enum, NODE_MATH_ADD); | |||||
| SOCKET_IN_FLOAT(value1, "Value1", 0.0f); | SOCKET_IN_FLOAT(a, "A", 0.5f); | ||||
| SOCKET_IN_FLOAT(value2, "Value2", 0.0f); | SOCKET_IN_FLOAT(b, "B", 0.5f); | ||||
| SOCKET_OUT_FLOAT(value, "Value"); | SOCKET_OUT_FLOAT(result, "Result"); | ||||
| return type; | return type; | ||||
| } | } | ||||
| MathNode::MathNode() : ShaderNode(node_type) | MathNode::MathNode() : ShaderNode(node_type) | ||||
| { | { | ||||
| } | } | ||||
| 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, a, b)); | ||||
| } | } | ||||
| 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("A"); | ||||
| ShaderInput *value2_in = input("Value2"); | ShaderInput *b_in = input("B"); | ||||
| ShaderOutput *value_out = output("Value"); | ShaderOutput *result_out = output("Result"); | ||||
| 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 | |||||