Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/scene/shader_nodes.cpp
| Show First 20 Lines • Show All 6,523 Lines • ▼ Show 20 Lines | void CurvesNode::constant_fold(const ConstantFolder &folder, ShaderInput *value_in) | ||||
| if (folder.all_inputs_constant()) { | if (folder.all_inputs_constant()) { | ||||
| if (curves.size() == 0) { | if (curves.size() == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| float3 pos = (value - make_float3(min_x, min_x, min_x)) / (max_x - min_x); | float3 pos = (value - make_float3(min_x, min_x, min_x)) / (max_x - min_x); | ||||
| float3 result; | float3 result; | ||||
| result[0] = rgb_ramp_lookup(curves.data(), pos[0], true, true, curves.size()).x; | result[0] = rgb_ramp_lookup(curves.data(), pos[0], true, extrapolate, curves.size()).x; | ||||
| result[1] = rgb_ramp_lookup(curves.data(), pos[1], true, true, curves.size()).y; | result[1] = rgb_ramp_lookup(curves.data(), pos[1], true, extrapolate, curves.size()).y; | ||||
| result[2] = rgb_ramp_lookup(curves.data(), pos[2], true, true, curves.size()).z; | result[2] = rgb_ramp_lookup(curves.data(), pos[2], true, extrapolate, curves.size()).z; | ||||
| folder.make_constant(interp(value, result, fac)); | folder.make_constant(interp(value, result, fac)); | ||||
| } | } | ||||
| /* remove no-op node */ | /* remove no-op node */ | ||||
| else if (!fac_in->link && fac == 0.0f) { | else if (!fac_in->link && fac == 0.0f) { | ||||
| /* link is not null because otherwise all inputs are constant */ | /* link is not null because otherwise all inputs are constant */ | ||||
| folder.bypass(value_in->link); | folder.bypass(value_in->link); | ||||
| } | } | ||||
| } | } | ||||
| void CurvesNode::compile(SVMCompiler &compiler, | void CurvesNode::compile(SVMCompiler &compiler, | ||||
| int type, | int type, | ||||
| ShaderInput *value_in, | ShaderInput *value_in, | ||||
| ShaderOutput *value_out) | ShaderOutput *value_out) | ||||
| { | { | ||||
| if (curves.size() == 0) | if (curves.size() == 0) | ||||
| return; | return; | ||||
| ShaderInput *fac_in = input("Fac"); | ShaderInput *fac_in = input("Fac"); | ||||
| compiler.add_node(type, | compiler.add_node(type, | ||||
| compiler.encode_uchar4(compiler.stack_assign(fac_in), | compiler.encode_uchar4(compiler.stack_assign(fac_in), | ||||
| compiler.stack_assign(value_in), | compiler.stack_assign(value_in), | ||||
| compiler.stack_assign(value_out)), | compiler.stack_assign(value_out), | ||||
| extrapolate), | |||||
| __float_as_int(min_x), | __float_as_int(min_x), | ||||
| __float_as_int(max_x)); | __float_as_int(max_x)); | ||||
| compiler.add_node(curves.size()); | compiler.add_node(curves.size()); | ||||
| for (int i = 0; i < curves.size(); i++) | for (int i = 0; i < curves.size(); i++) | ||||
| compiler.add_node(float3_to_float4(curves[i])); | compiler.add_node(float3_to_float4(curves[i])); | ||||
| } | } | ||||
| void CurvesNode::compile(OSLCompiler &compiler, const char *name) | void CurvesNode::compile(OSLCompiler &compiler, const char *name) | ||||
| { | { | ||||
| if (curves.size() == 0) | if (curves.size() == 0) | ||||
| return; | return; | ||||
| compiler.parameter_color_array("ramp", curves); | compiler.parameter_color_array("ramp", curves); | ||||
| compiler.parameter(this, "min_x"); | compiler.parameter(this, "min_x"); | ||||
| compiler.parameter(this, "max_x"); | compiler.parameter(this, "max_x"); | ||||
| compiler.parameter(this, "extrapolate"); | |||||
| compiler.add(this, name); | compiler.add(this, name); | ||||
| } | } | ||||
| void CurvesNode::compile(SVMCompiler & /*compiler*/) | void CurvesNode::compile(SVMCompiler & /*compiler*/) | ||||
| { | { | ||||
| assert(0); | assert(0); | ||||
| } | } | ||||
| void CurvesNode::compile(OSLCompiler & /*compiler*/) | void CurvesNode::compile(OSLCompiler & /*compiler*/) | ||||
| { | { | ||||
| assert(0); | assert(0); | ||||
| } | } | ||||
| /* RGBCurvesNode */ | /* RGBCurvesNode */ | ||||
| NODE_DEFINE(RGBCurvesNode) | NODE_DEFINE(RGBCurvesNode) | ||||
| { | { | ||||
| NodeType *type = NodeType::add("rgb_curves", create, NodeType::SHADER); | NodeType *type = NodeType::add("rgb_curves", create, NodeType::SHADER); | ||||
| SOCKET_COLOR_ARRAY(curves, "Curves", array<float3>()); | SOCKET_COLOR_ARRAY(curves, "Curves", array<float3>()); | ||||
| SOCKET_FLOAT(min_x, "Min X", 0.0f); | SOCKET_FLOAT(min_x, "Min X", 0.0f); | ||||
| SOCKET_FLOAT(max_x, "Max X", 1.0f); | SOCKET_FLOAT(max_x, "Max X", 1.0f); | ||||
| SOCKET_BOOLEAN(extrapolate, "Extrapolate", true); | |||||
| SOCKET_IN_FLOAT(fac, "Fac", 0.0f); | SOCKET_IN_FLOAT(fac, "Fac", 0.0f); | ||||
| SOCKET_IN_COLOR(value, "Color", zero_float3()); | SOCKET_IN_COLOR(value, "Color", zero_float3()); | ||||
| SOCKET_OUT_COLOR(value, "Color"); | SOCKET_OUT_COLOR(value, "Color"); | ||||
| return type; | return type; | ||||
| } | } | ||||
| Show All 21 Lines | |||||
| NODE_DEFINE(VectorCurvesNode) | NODE_DEFINE(VectorCurvesNode) | ||||
| { | { | ||||
| NodeType *type = NodeType::add("vector_curves", create, NodeType::SHADER); | NodeType *type = NodeType::add("vector_curves", create, NodeType::SHADER); | ||||
| SOCKET_VECTOR_ARRAY(curves, "Curves", array<float3>()); | SOCKET_VECTOR_ARRAY(curves, "Curves", array<float3>()); | ||||
| SOCKET_FLOAT(min_x, "Min X", 0.0f); | SOCKET_FLOAT(min_x, "Min X", 0.0f); | ||||
| SOCKET_FLOAT(max_x, "Max X", 1.0f); | SOCKET_FLOAT(max_x, "Max X", 1.0f); | ||||
| SOCKET_BOOLEAN(extrapolate, "Extrapolate", true); | |||||
| SOCKET_IN_FLOAT(fac, "Fac", 0.0f); | SOCKET_IN_FLOAT(fac, "Fac", 0.0f); | ||||
| SOCKET_IN_VECTOR(value, "Vector", zero_float3()); | SOCKET_IN_VECTOR(value, "Vector", zero_float3()); | ||||
| SOCKET_OUT_VECTOR(value, "Vector"); | SOCKET_OUT_VECTOR(value, "Vector"); | ||||
| return type; | return type; | ||||
| } | } | ||||
| Show All 21 Lines | |||||
| NODE_DEFINE(FloatCurveNode) | NODE_DEFINE(FloatCurveNode) | ||||
| { | { | ||||
| NodeType *type = NodeType::add("float_curve", create, NodeType::SHADER); | NodeType *type = NodeType::add("float_curve", create, NodeType::SHADER); | ||||
| SOCKET_FLOAT_ARRAY(curve, "Curve", array<float>()); | SOCKET_FLOAT_ARRAY(curve, "Curve", array<float>()); | ||||
| SOCKET_FLOAT(min_x, "Min X", 0.0f); | SOCKET_FLOAT(min_x, "Min X", 0.0f); | ||||
| SOCKET_FLOAT(max_x, "Max X", 1.0f); | SOCKET_FLOAT(max_x, "Max X", 1.0f); | ||||
| SOCKET_BOOLEAN(extrapolate, "Extrapolate", true); | |||||
| SOCKET_IN_FLOAT(fac, "Factor", 0.0f); | SOCKET_IN_FLOAT(fac, "Factor", 0.0f); | ||||
| SOCKET_IN_FLOAT(value, "Value", 0.0f); | SOCKET_IN_FLOAT(value, "Value", 0.0f); | ||||
| SOCKET_OUT_FLOAT(value, "Value"); | SOCKET_OUT_FLOAT(value, "Value"); | ||||
| return type; | return type; | ||||
| } | } | ||||
| Show All 9 Lines | void FloatCurveNode::constant_fold(const ConstantFolder &folder) | ||||
| /* evaluate fully constant node */ | /* evaluate fully constant node */ | ||||
| if (folder.all_inputs_constant()) { | if (folder.all_inputs_constant()) { | ||||
| if (curve.size() == 0) { | if (curve.size() == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| float pos = (value - min_x) / (max_x - min_x); | float pos = (value - min_x) / (max_x - min_x); | ||||
| float result = float_ramp_lookup(curve.data(), pos, true, true, curve.size()); | float result = float_ramp_lookup(curve.data(), pos, true, extrapolate, curve.size()); | ||||
| folder.make_constant(value + fac * (result - value)); | folder.make_constant(value + fac * (result - value)); | ||||
| } | } | ||||
| /* remove no-op node */ | /* remove no-op node */ | ||||
| else if (!fac_in->link && fac == 0.0f) { | else if (!fac_in->link && fac == 0.0f) { | ||||
| /* link is not null because otherwise all inputs are constant */ | /* link is not null because otherwise all inputs are constant */ | ||||
| folder.bypass(value_in->link); | folder.bypass(value_in->link); | ||||
| } | } | ||||
| } | } | ||||
| void FloatCurveNode::compile(SVMCompiler &compiler) | void FloatCurveNode::compile(SVMCompiler &compiler) | ||||
| { | { | ||||
| if (curve.size() == 0) | if (curve.size() == 0) | ||||
| return; | return; | ||||
| ShaderInput *value_in = input("Value"); | ShaderInput *value_in = input("Value"); | ||||
| ShaderInput *fac_in = input("Factor"); | ShaderInput *fac_in = input("Factor"); | ||||
| ShaderOutput *value_out = output("Value"); | ShaderOutput *value_out = output("Value"); | ||||
| compiler.add_node(NODE_FLOAT_CURVE, | compiler.add_node(NODE_FLOAT_CURVE, | ||||
| compiler.encode_uchar4(compiler.stack_assign(fac_in), | compiler.encode_uchar4(compiler.stack_assign(fac_in), | ||||
| compiler.stack_assign(value_in), | compiler.stack_assign(value_in), | ||||
| compiler.stack_assign(value_out)), | compiler.stack_assign(value_out), | ||||
| extrapolate), | |||||
| __float_as_int(min_x), | __float_as_int(min_x), | ||||
| __float_as_int(max_x)); | __float_as_int(max_x)); | ||||
| compiler.add_node(curve.size()); | compiler.add_node(curve.size()); | ||||
| for (int i = 0; i < curve.size(); i++) | for (int i = 0; i < curve.size(); i++) | ||||
| compiler.add_node(make_float4(curve[i])); | compiler.add_node(make_float4(curve[i])); | ||||
| } | } | ||||
| void FloatCurveNode::compile(OSLCompiler &compiler) | void FloatCurveNode::compile(OSLCompiler &compiler) | ||||
| { | { | ||||
| if (curve.size() == 0) | if (curve.size() == 0) | ||||
| return; | return; | ||||
| compiler.parameter_array("ramp", curve.data(), curve.size()); | compiler.parameter_array("ramp", curve.data(), curve.size()); | ||||
| compiler.parameter(this, "min_x"); | compiler.parameter(this, "min_x"); | ||||
| compiler.parameter(this, "max_x"); | compiler.parameter(this, "max_x"); | ||||
| compiler.parameter(this, "extrapolate"); | |||||
| compiler.add(this, "node_float_curve"); | compiler.add(this, "node_float_curve"); | ||||
| } | } | ||||
| /* RGBRampNode */ | /* RGBRampNode */ | ||||
| NODE_DEFINE(RGBRampNode) | NODE_DEFINE(RGBRampNode) | ||||
| { | { | ||||
| NodeType *type = NodeType::add("rgb_ramp", create, NodeType::SHADER); | NodeType *type = NodeType::add("rgb_ramp", create, NodeType::SHADER); | ||||
| ▲ Show 20 Lines • Show All 553 Lines • Show Last 20 Lines | |||||