Some improvements to Mix visual shader function
This commit is contained in:
parent
045ab51ae5
commit
d0dc195da8
|
@ -2425,6 +2425,7 @@ VisualShaderEditor::VisualShaderEditor() {
|
|||
add_options.push_back(AddOption("Max", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), VisualShaderNodeVectorOp::OP_MAX, VisualShaderNode::PORT_TYPE_VECTOR));
|
||||
add_options.push_back(AddOption("Min", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), VisualShaderNodeVectorOp::OP_MIN, VisualShaderNode::PORT_TYPE_VECTOR));
|
||||
add_options.push_back(AddOption("Mix", "Vector", "Functions", "VisualShaderNodeVectorInterp", TTR("Linear interpolation between two vectors."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
|
||||
add_options.push_back(AddOption("MixS", "Vector", "Functions", "VisualShaderNodeVectorScalarMix", TTR("Linear interpolation between two vectors using scalar."), -1, VisualShaderNode::PORT_TYPE_VECTOR));
|
||||
add_options.push_back(AddOption("Negate", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_VECTOR));
|
||||
add_options.push_back(AddOption("Normalize", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNode::PORT_TYPE_VECTOR));
|
||||
add_options.push_back(AddOption("OneMinus", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNode::PORT_TYPE_VECTOR));
|
||||
|
|
|
@ -509,6 +509,7 @@ void register_scene_types() {
|
|||
ClassDB::register_class<VisualShaderNodeVectorRefract>();
|
||||
ClassDB::register_class<VisualShaderNodeScalarInterp>();
|
||||
ClassDB::register_class<VisualShaderNodeVectorInterp>();
|
||||
ClassDB::register_class<VisualShaderNodeVectorScalarMix>();
|
||||
ClassDB::register_class<VisualShaderNodeVectorCompose>();
|
||||
ClassDB::register_class<VisualShaderNodeTransformCompose>();
|
||||
ClassDB::register_class<VisualShaderNodeVectorDecompose>();
|
||||
|
|
|
@ -2399,34 +2399,38 @@ VisualShaderNodeVectorRefract::VisualShaderNodeVectorRefract() {
|
|||
set_input_port_default_value(2, 0.0);
|
||||
}
|
||||
|
||||
////////////// Scalar Interp
|
||||
////////////// Scalar Mix
|
||||
|
||||
String VisualShaderNodeScalarInterp::get_caption() const {
|
||||
return "Mix";
|
||||
return "ScalarMix";
|
||||
}
|
||||
|
||||
int VisualShaderNodeScalarInterp::get_input_port_count() const {
|
||||
return 3;
|
||||
}
|
||||
|
||||
VisualShaderNodeScalarInterp::PortType VisualShaderNodeScalarInterp::get_input_port_type(int p_port) const {
|
||||
return PORT_TYPE_SCALAR;
|
||||
}
|
||||
|
||||
String VisualShaderNodeScalarInterp::get_input_port_name(int p_port) const {
|
||||
if (p_port == 0) {
|
||||
return "a";
|
||||
} else if (p_port == 1) {
|
||||
return "b";
|
||||
} else {
|
||||
return "c";
|
||||
return "weight";
|
||||
}
|
||||
}
|
||||
|
||||
int VisualShaderNodeScalarInterp::get_output_port_count() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
VisualShaderNodeScalarInterp::PortType VisualShaderNodeScalarInterp::get_output_port_type(int p_port) const {
|
||||
return PORT_TYPE_SCALAR;
|
||||
}
|
||||
|
||||
String VisualShaderNodeScalarInterp::get_output_port_name(int p_port) const {
|
||||
return "mix";
|
||||
}
|
||||
|
@ -2437,38 +2441,42 @@ String VisualShaderNodeScalarInterp::generate_code(Shader::Mode p_mode, VisualSh
|
|||
|
||||
VisualShaderNodeScalarInterp::VisualShaderNodeScalarInterp() {
|
||||
set_input_port_default_value(0, 0.0);
|
||||
set_input_port_default_value(1, 0.0);
|
||||
set_input_port_default_value(2, 0.0);
|
||||
set_input_port_default_value(1, 1.0);
|
||||
set_input_port_default_value(2, 0.5);
|
||||
}
|
||||
|
||||
////////////// Vector Interp
|
||||
////////////// Vector Mix
|
||||
|
||||
String VisualShaderNodeVectorInterp::get_caption() const {
|
||||
return "Mix";
|
||||
return "VectorMix";
|
||||
}
|
||||
|
||||
int VisualShaderNodeVectorInterp::get_input_port_count() const {
|
||||
return 3;
|
||||
}
|
||||
|
||||
VisualShaderNodeVectorInterp::PortType VisualShaderNodeVectorInterp::get_input_port_type(int p_port) const {
|
||||
return PORT_TYPE_VECTOR;
|
||||
}
|
||||
|
||||
String VisualShaderNodeVectorInterp::get_input_port_name(int p_port) const {
|
||||
if (p_port == 0) {
|
||||
return "a";
|
||||
} else if (p_port == 1) {
|
||||
return "b";
|
||||
} else {
|
||||
return "c";
|
||||
return "weight";
|
||||
}
|
||||
}
|
||||
|
||||
int VisualShaderNodeVectorInterp::get_output_port_count() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
VisualShaderNodeVectorInterp::PortType VisualShaderNodeVectorInterp::get_output_port_type(int p_port) const {
|
||||
return PORT_TYPE_VECTOR;
|
||||
}
|
||||
|
||||
String VisualShaderNodeVectorInterp::get_output_port_name(int p_port) const {
|
||||
return "mix";
|
||||
}
|
||||
|
@ -2478,9 +2486,57 @@ String VisualShaderNodeVectorInterp::generate_code(Shader::Mode p_mode, VisualSh
|
|||
}
|
||||
|
||||
VisualShaderNodeVectorInterp::VisualShaderNodeVectorInterp() {
|
||||
set_input_port_default_value(0, Vector3());
|
||||
set_input_port_default_value(1, Vector3());
|
||||
set_input_port_default_value(2, Vector3());
|
||||
set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
|
||||
set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0));
|
||||
set_input_port_default_value(2, Vector3(0.5, 0.5, 0.5));
|
||||
}
|
||||
|
||||
////////////// Vector Mix (by scalar)
|
||||
|
||||
String VisualShaderNodeVectorScalarMix::get_caption() const {
|
||||
return "VectorScalarMix";
|
||||
}
|
||||
|
||||
int VisualShaderNodeVectorScalarMix::get_input_port_count() const {
|
||||
return 3;
|
||||
}
|
||||
|
||||
VisualShaderNodeVectorScalarMix::PortType VisualShaderNodeVectorScalarMix::get_input_port_type(int p_port) const {
|
||||
if (p_port == 2)
|
||||
return PORT_TYPE_SCALAR;
|
||||
return PORT_TYPE_VECTOR;
|
||||
}
|
||||
|
||||
String VisualShaderNodeVectorScalarMix::get_input_port_name(int p_port) const {
|
||||
if (p_port == 0) {
|
||||
return "a";
|
||||
} else if (p_port == 1) {
|
||||
return "b";
|
||||
} else {
|
||||
return "weight";
|
||||
}
|
||||
}
|
||||
|
||||
int VisualShaderNodeVectorScalarMix::get_output_port_count() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
VisualShaderNodeVectorScalarMix::PortType VisualShaderNodeVectorScalarMix::get_output_port_type(int p_port) const {
|
||||
return PORT_TYPE_VECTOR;
|
||||
}
|
||||
|
||||
String VisualShaderNodeVectorScalarMix::get_output_port_name(int p_port) const {
|
||||
return "mix";
|
||||
}
|
||||
|
||||
String VisualShaderNodeVectorScalarMix::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
|
||||
return "\t" + p_output_vars[0] + " = mix( " + p_input_vars[0] + " , " + p_input_vars[1] + " , " + p_input_vars[2] + " );\n";
|
||||
}
|
||||
|
||||
VisualShaderNodeVectorScalarMix::VisualShaderNodeVectorScalarMix() {
|
||||
set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0));
|
||||
set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0));
|
||||
set_input_port_default_value(2, 0.5);
|
||||
}
|
||||
|
||||
////////////// Vector Compose
|
||||
|
|
|
@ -1170,6 +1170,27 @@ public:
|
|||
VisualShaderNodeVectorInterp();
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
class VisualShaderNodeVectorScalarMix : public VisualShaderNode {
|
||||
GDCLASS(VisualShaderNodeVectorScalarMix, VisualShaderNode);
|
||||
|
||||
public:
|
||||
virtual String get_caption() const;
|
||||
|
||||
virtual int get_input_port_count() const;
|
||||
virtual PortType get_input_port_type(int p_port) const;
|
||||
virtual String get_input_port_name(int p_port) const;
|
||||
|
||||
virtual int get_output_port_count() const;
|
||||
virtual PortType get_output_port_type(int p_port) const;
|
||||
virtual String get_output_port_name(int p_port) const;
|
||||
|
||||
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
|
||||
|
||||
VisualShaderNodeVectorScalarMix();
|
||||
};
|
||||
|
||||
///////////////////////////////////////
|
||||
/// COMPOSE
|
||||
///////////////////////////////////////
|
||||
|
|
Loading…
Reference in New Issue