Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/nodes.cpp
| Show First 20 Lines • Show All 3,695 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| compiler.parameter(this, "type"); | compiler.parameter(this, "type"); | ||||
| compiler.parameter(this, "use_clamp"); | compiler.parameter(this, "use_clamp"); | ||||
| compiler.add(this, "node_mix"); | compiler.add(this, "node_mix"); | ||||
| } | } | ||||
| void MixNode::constant_fold(const ConstantFolder& folder) | void MixNode::constant_fold(const ConstantFolder& folder) | ||||
| { | { | ||||
| ShaderInput *fac_in = input("Fac"); | |||||
| ShaderInput *color1_in = input("Color1"); | |||||
| ShaderInput *color2_in = input("Color2"); | |||||
| /* evaluate fully constant node */ | |||||
| if(folder.all_inputs_constant()) { | if(folder.all_inputs_constant()) { | ||||
| folder.make_constant_clamp(svm_mix(type, fac, color1, color2), use_clamp); | folder.make_constant_clamp(svm_mix(type, fac, color1, color2), use_clamp); | ||||
brecht: No need to mark these static. | |||||
Not Done Inline ActionsThe idea of static was to make these actual constants. An even better thing would be to have it at the start of the file, or in some header perhaps. angavrilov: The idea of static was to make these actual constants. An even better thing would be to have it… | |||||
| return; | |||||
| } | |||||
| /* remove no-op node when factor is 0.0 */ | |||||
| if(!fac_in->link && fac <= 0.0f) { | |||||
| /* note that some of the modes will clamp out of bounds values even without use_clamp */ | |||||
| if(type == NODE_MIX_LIGHT || type == NODE_MIX_DODGE || type == NODE_MIX_BURN) { | |||||
| if(!color1_in->link) { | |||||
| folder.make_constant_clamp(svm_mix(type, 0.0f, color1, color1), use_clamp); | |||||
| return; | |||||
| } | |||||
| } | |||||
| else if(folder.try_bypass_or_make_constant(color1_in, color1, use_clamp)) { | |||||
| return; | |||||
| } | |||||
| } | |||||
| if(type == NODE_MIX_BLEND) { | |||||
| /* remove useless mix colors nodes */ | |||||
| if(color1_in->link ? (color1_in->link == color2_in->link) : (!color2_in->link && color1 == color2)) { | |||||
| if(folder.try_bypass_or_make_constant(color1_in, color1, use_clamp)) { | |||||
| return; | |||||
| } | |||||
| } | |||||
| /* remove no-op mix color node when factor is 1.0 */ | |||||
| if(!fac_in->link && fac >= 1.0f) { | |||||
| if(folder.try_bypass_or_make_constant(color2_in, color2, use_clamp)) { | |||||
| return; | |||||
| } | |||||
| } | } | ||||
| else { | |||||
| folder.fold_mix(type, use_clamp); | |||||
Not Done Inline ActionsThis doesn't follow code convention. There should be no space between keyword and brace in Cycles. sergey: This doesn't follow code convention. There should be no space between keyword and brace in… | |||||
| } | } | ||||
| } | } | ||||
Not Done Inline ActionsI'm tempting to ask to always use parenthesis in new code. There are various advantages to that. sergey: I'm tempting to ask to always use parenthesis in new code. There are various advantages to that. | |||||
| /* Combine RGB */ | /* Combine RGB */ | ||||
| NODE_DEFINE(CombineRGBNode) | NODE_DEFINE(CombineRGBNode) | ||||
| { | { | ||||
| NodeType* type = NodeType::add("combine_rgb", create, NodeType::SHADER); | NodeType* type = NodeType::add("combine_rgb", create, NodeType::SHADER); | ||||
| SOCKET_IN_FLOAT(r, "R", 0.0f); | SOCKET_IN_FLOAT(r, "R", 0.0f); | ||||
| SOCKET_IN_FLOAT(g, "G", 0.0f); | SOCKET_IN_FLOAT(g, "G", 0.0f); | ||||
| ▲ Show 20 Lines • Show All 866 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| } | } | ||||
| 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_clamp(svm_math(type, value1, value2), use_clamp); | ||||
| } | } | ||||
| else { | |||||
Not Done Inline ActionsComment is a full sentence, starting with capital and ending up with fullstop, sergey: Comment is a full sentence, starting with capital and ending up with fullstop, | |||||
| folder.fold_math(type, use_clamp); | |||||
| } | |||||
| } | } | ||||
| void MathNode::compile(SVMCompiler& compiler) | void MathNode::compile(SVMCompiler& compiler) | ||||
| { | { | ||||
| ShaderInput *value1_in = input("Value1"); | ShaderInput *value1_in = input("Value1"); | ||||
| ShaderInput *value2_in = input("Value2"); | ShaderInput *value2_in = input("Value2"); | ||||
| ShaderOutput *value_out = output("Value"); | ShaderOutput *value_out = output("Value"); | ||||
| ▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | if(folder.all_inputs_constant()) { | ||||
| if(folder.output == output("Value")) { | if(folder.output == output("Value")) { | ||||
| folder.make_constant(value); | folder.make_constant(value); | ||||
| } | } | ||||
| else if(folder.output == output("Vector")) { | else if(folder.output == output("Vector")) { | ||||
| folder.make_constant(vector); | folder.make_constant(vector); | ||||
| } | } | ||||
| } | } | ||||
| else { | |||||
| folder.fold_vector_math(type); | |||||
| } | |||||
| } | } | ||||
| void VectorMathNode::compile(SVMCompiler& compiler) | void VectorMathNode::compile(SVMCompiler& compiler) | ||||
| { | { | ||||
| ShaderInput *vector1_in = input("Vector1"); | ShaderInput *vector1_in = input("Vector1"); | ||||
| ShaderInput *vector2_in = input("Vector2"); | ShaderInput *vector2_in = input("Vector2"); | ||||
| ShaderOutput *value_out = output("Value"); | ShaderOutput *value_out = output("Value"); | ||||
| ShaderOutput *vector_out = output("Vector"); | ShaderOutput *vector_out = output("Vector"); | ||||
| ▲ Show 20 Lines • Show All 653 Lines • Show Last 20 Lines | |||||
No need to mark these static.