summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2021-08-11 19:08:37 +0300
committerYuri Roubinsky <chaosus89@gmail.com>2021-08-11 22:05:04 +0300
commit9cf158019da555238516d209dd4ab775b90580fc (patch)
tree56db4166d1bde832d4b2be260d3add782bfe6697 /scene
parent974cc68fb420768a244c14dfd7a59da73f2330bd (diff)
Changed `TransformMult` node to `TransformOp` in visual shaders
Diffstat (limited to 'scene')
-rw-r--r--scene/register_scene_types.cpp3
-rw-r--r--scene/resources/visual_shader_nodes.cpp72
-rw-r--r--scene/resources/visual_shader_nodes.h22
3 files changed, 62 insertions, 35 deletions
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 5ff92c6ff6..f9f8c4e39c 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -557,7 +557,7 @@ void register_scene_types() {
GDREGISTER_CLASS(VisualShaderNodeIntOp);
GDREGISTER_CLASS(VisualShaderNodeVectorOp);
GDREGISTER_CLASS(VisualShaderNodeColorOp);
- GDREGISTER_CLASS(VisualShaderNodeTransformMult);
+ GDREGISTER_CLASS(VisualShaderNodeTransformOp);
GDREGISTER_CLASS(VisualShaderNodeTransformVecMult);
GDREGISTER_CLASS(VisualShaderNodeFloatFunc);
GDREGISTER_CLASS(VisualShaderNodeIntFunc);
@@ -983,6 +983,7 @@ void register_scene_types() {
ClassDB::add_compatibility_class("VisualShaderNodeVectorScalarSmoothStep", "VisualShaderNodeSmoothStep");
ClassDB::add_compatibility_class("VisualShaderNodeVectorScalarStep", "VisualShaderNodeStep");
ClassDB::add_compatibility_class("VisualShaderNodeScalarSwitch", "VisualShaderNodeSwitch");
+ ClassDB::add_compatibility_class("VisualShaderNodeScalarTransformMult", "VisualShaderNodeTransformOp");
ClassDB::add_compatibility_class("World", "World3D");
ClassDB::add_compatibility_class("StreamTexture", "StreamTexture2D");
ClassDB::add_compatibility_class("Light2D", "PointLight2D");
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 6fd6fd8f3b..c60f283cef 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -1915,76 +1915,96 @@ VisualShaderNodeColorOp::VisualShaderNodeColorOp() {
set_input_port_default_value(1, Vector3());
}
-////////////// Transform Mult
+////////////// Transform Op
-String VisualShaderNodeTransformMult::get_caption() const {
- return "TransformMult";
+String VisualShaderNodeTransformOp::get_caption() const {
+ return "TransformOp";
}
-int VisualShaderNodeTransformMult::get_input_port_count() const {
+int VisualShaderNodeTransformOp::get_input_port_count() const {
return 2;
}
-VisualShaderNodeTransformMult::PortType VisualShaderNodeTransformMult::get_input_port_type(int p_port) const {
+VisualShaderNodeTransformOp::PortType VisualShaderNodeTransformOp::get_input_port_type(int p_port) const {
return PORT_TYPE_TRANSFORM;
}
-String VisualShaderNodeTransformMult::get_input_port_name(int p_port) const {
+String VisualShaderNodeTransformOp::get_input_port_name(int p_port) const {
return p_port == 0 ? "a" : "b";
}
-int VisualShaderNodeTransformMult::get_output_port_count() const {
+int VisualShaderNodeTransformOp::get_output_port_count() const {
return 1;
}
-VisualShaderNodeTransformMult::PortType VisualShaderNodeTransformMult::get_output_port_type(int p_port) const {
+VisualShaderNodeTransformOp::PortType VisualShaderNodeTransformOp::get_output_port_type(int p_port) const {
return PORT_TYPE_TRANSFORM;
}
-String VisualShaderNodeTransformMult::get_output_port_name(int p_port) const {
+String VisualShaderNodeTransformOp::get_output_port_name(int p_port) const {
return "mult"; //no output port means the editor will be used as port
}
-String VisualShaderNodeTransformMult::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 {
- if (op == OP_AxB) {
- return " " + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
- } else if (op == OP_BxA) {
- return " " + p_output_vars[0] + " = " + p_input_vars[1] + " * " + p_input_vars[0] + ";\n";
- } else if (op == OP_AxB_COMP) {
- return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
- } else {
- return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[1] + ", " + p_input_vars[0] + ");\n";
+String VisualShaderNodeTransformOp::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 {
+ switch (op) {
+ case OP_AxB:
+ return " " + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n";
+ case OP_BxA:
+ return " " + p_output_vars[0] + " = " + p_input_vars[1] + " * " + p_input_vars[0] + ";\n";
+ case OP_AxB_COMP:
+ return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n";
+ case OP_BxA_COMP:
+ return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[1] + ", " + p_input_vars[0] + ");\n";
+ case OP_ADD:
+ return " " + p_output_vars[0] + " = " + p_input_vars[0] + " + " + p_input_vars[1] + ";\n";
+ case OP_A_MINUS_B:
+ return " " + p_output_vars[0] + " = " + p_input_vars[0] + " - " + p_input_vars[1] + ";\n";
+ case OP_B_MINUS_A:
+ return " " + p_output_vars[0] + " = " + p_input_vars[1] + " - " + p_input_vars[0] + ";\n";
+ case OP_A_DIV_B:
+ return " " + p_output_vars[0] + " = " + p_input_vars[0] + " / " + p_input_vars[1] + ";\n";
+ case OP_B_DIV_A:
+ return " " + p_output_vars[0] + " = " + p_input_vars[1] + " / " + p_input_vars[0] + ";\n";
+ default:
+ return "";
}
}
-void VisualShaderNodeTransformMult::set_operator(Operator p_op) {
+void VisualShaderNodeTransformOp::set_operator(Operator p_op) {
+ ERR_FAIL_INDEX(int(p_op), int(OP_LIMITER));
op = p_op;
emit_changed();
}
-VisualShaderNodeTransformMult::Operator VisualShaderNodeTransformMult::get_operator() const {
+VisualShaderNodeTransformOp::Operator VisualShaderNodeTransformOp::get_operator() const {
return op;
}
-Vector<StringName> VisualShaderNodeTransformMult::get_editable_properties() const {
+Vector<StringName> VisualShaderNodeTransformOp::get_editable_properties() const {
Vector<StringName> props;
props.push_back("operator");
return props;
}
-void VisualShaderNodeTransformMult::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeTransformMult::set_operator);
- ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeTransformMult::get_operator);
+void VisualShaderNodeTransformOp::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_operator", "op"), &VisualShaderNodeTransformOp::set_operator);
+ ClassDB::bind_method(D_METHOD("get_operator"), &VisualShaderNodeTransformOp::get_operator);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "A x B,B x A,A x B(per component),B x A(per component)"), "set_operator", "get_operator");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "operator", PROPERTY_HINT_ENUM, "A x B,B x A,A x B(per component),B x A(per component),A + B,A - B,B - A,A / B,B / A"), "set_operator", "get_operator");
BIND_ENUM_CONSTANT(OP_AxB);
BIND_ENUM_CONSTANT(OP_BxA);
BIND_ENUM_CONSTANT(OP_AxB_COMP);
BIND_ENUM_CONSTANT(OP_BxA_COMP);
+ BIND_ENUM_CONSTANT(OP_ADD);
+ BIND_ENUM_CONSTANT(OP_A_MINUS_B);
+ BIND_ENUM_CONSTANT(OP_B_MINUS_A);
+ BIND_ENUM_CONSTANT(OP_A_DIV_B);
+ BIND_ENUM_CONSTANT(OP_B_DIV_A);
+ BIND_ENUM_CONSTANT(OP_LIMITER);
}
-VisualShaderNodeTransformMult::VisualShaderNodeTransformMult() {
+VisualShaderNodeTransformOp::VisualShaderNodeTransformOp() {
set_input_port_default_value(0, Transform3D());
set_input_port_default_value(1, Transform3D());
}
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index 33a45a4384..99617b46a3 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -696,19 +696,25 @@ public:
VARIANT_ENUM_CAST(VisualShaderNodeColorOp::Operator)
-///////////////////////////////////////
-/// TRANSFORM-TRANSFORM MULTIPLICATION
-///////////////////////////////////////
+////////////////////////////////
+/// TRANSFORM-TRANSFORM OPERATOR
+////////////////////////////////
-class VisualShaderNodeTransformMult : public VisualShaderNode {
- GDCLASS(VisualShaderNodeTransformMult, VisualShaderNode);
+class VisualShaderNodeTransformOp : public VisualShaderNode {
+ GDCLASS(VisualShaderNodeTransformOp, VisualShaderNode);
public:
enum Operator {
OP_AxB,
OP_BxA,
OP_AxB_COMP,
- OP_BxA_COMP
+ OP_BxA_COMP,
+ OP_ADD,
+ OP_A_MINUS_B,
+ OP_B_MINUS_A,
+ OP_A_DIV_B,
+ OP_B_DIV_A,
+ OP_LIMITER,
};
protected:
@@ -734,10 +740,10 @@ public:
virtual Vector<StringName> get_editable_properties() const override;
- VisualShaderNodeTransformMult();
+ VisualShaderNodeTransformOp();
};
-VARIANT_ENUM_CAST(VisualShaderNodeTransformMult::Operator)
+VARIANT_ENUM_CAST(VisualShaderNodeTransformOp::Operator)
///////////////////////////////////////
/// TRANSFORM-VECTOR MULTIPLICATION