diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/button.cpp | 5 | ||||
-rw-r--r-- | scene/gui/control.cpp | 5 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 17 | ||||
-rw-r--r-- | scene/gui/line_edit.h | 4 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 16 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 6 | ||||
-rw-r--r-- | scene/register_scene_types.cpp | 5 | ||||
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 4 | ||||
-rw-r--r-- | scene/resources/visual_shader_nodes.cpp | 141 | ||||
-rw-r--r-- | scene/resources/visual_shader_nodes.h | 59 |
10 files changed, 85 insertions, 177 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 552dd28513..3ed1b873af 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -197,6 +197,8 @@ void Button::_notification(int p_what) { color = get_theme_color(SNAME("font_disabled_color")); if (has_theme_color(SNAME("icon_disabled_color"))) { color_icon = get_theme_color(SNAME("icon_disabled_color")); + } else { + color_icon.a = 0.4; } } break; @@ -232,9 +234,6 @@ void Button::_notification(int p_what) { } if (!_icon.is_null()) { int valign = size.height - style->get_minimum_size().y; - if (is_disabled()) { - color_icon.a = 0.4; - } float icon_ofs_region = 0.0; Point2 style_offset; diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 562ea8a8f7..7ebc5c27f8 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -576,6 +576,11 @@ void Control::_update_canvas_item_transform() { Transform2D xform = _get_internal_transform(); xform[2] += get_position(); + // We use a little workaround to avoid flickering when moving the pivot with _edit_set_pivot() + if (is_inside_tree() && Math::abs(Math::sin(data.rotation * 4.0f)) < 0.00001f && get_viewport()->is_snap_controls_to_pixels_enabled()) { + xform[2] = xform[2].round(); + } + RenderingServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform); } diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 88953fa7db..3aae3377bc 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -752,7 +752,7 @@ void LineEdit::_notification(int p_what) { // Draw placeholder color. if (using_placeholder) { - font_color.a *= placeholder_alpha; + font_color = get_theme_color(SNAME("font_placeholder_color")); } bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; @@ -1476,15 +1476,6 @@ String LineEdit::get_placeholder() const { return placeholder; } -void LineEdit::set_placeholder_alpha(float p_alpha) { - placeholder_alpha = p_alpha; - update(); -} - -float LineEdit::get_placeholder_alpha() const { - return placeholder_alpha; -} - void LineEdit::set_caret_column(int p_column) { if (p_column > (int)text.length()) { p_column = text.length(); @@ -2245,8 +2236,6 @@ void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override_options"), &LineEdit::get_structured_text_bidi_override_options); ClassDB::bind_method(D_METHOD("set_placeholder", "text"), &LineEdit::set_placeholder); ClassDB::bind_method(D_METHOD("get_placeholder"), &LineEdit::get_placeholder); - ClassDB::bind_method(D_METHOD("set_placeholder_alpha", "alpha"), &LineEdit::set_placeholder_alpha); - ClassDB::bind_method(D_METHOD("get_placeholder_alpha"), &LineEdit::get_placeholder_alpha); ClassDB::bind_method(D_METHOD("set_caret_column", "position"), &LineEdit::set_caret_column); ClassDB::bind_method(D_METHOD("get_caret_column"), &LineEdit::get_caret_column); ClassDB::bind_method(D_METHOD("get_scroll_offset"), &LineEdit::get_scroll_offset); @@ -2328,6 +2317,7 @@ void LineEdit::_bind_methods() { BIND_ENUM_CONSTANT(MENU_MAX); ADD_PROPERTY(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "placeholder_text"), "set_placeholder", "get_placeholder"); ADD_PROPERTY(PropertyInfo(Variant::INT, "alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment"); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_length", PROPERTY_HINT_RANGE, "0,1000,1,or_greater"), "set_max_length", "get_max_length"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable"); @@ -2349,9 +2339,6 @@ void LineEdit::_bind_methods() { ADD_GROUP("Structured Text", "structured_text_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "structured_text_bidi_override", PROPERTY_HINT_ENUM, "Default,URI,File,Email,List,None,Custom"), "set_structured_text_bidi_override", "get_structured_text_bidi_override"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options"); - ADD_GROUP("Placeholder", "placeholder_"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "placeholder_text"), "set_placeholder", "get_placeholder"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "placeholder_alpha", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_placeholder_alpha", "get_placeholder_alpha"); ADD_GROUP("Caret", "caret_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "set_caret_blink_enabled", "is_caret_blink_enabled"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "set_caret_blink_speed", "get_caret_blink_speed"); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 0c313f71c2..1519c09d73 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -82,7 +82,6 @@ private: String placeholder; String placeholder_translated; String secret_character = "*"; - float placeholder_alpha = 0.6; String ime_text; Point2 ime_selection; @@ -262,9 +261,6 @@ public: void set_placeholder(String p_text); String get_placeholder() const; - void set_placeholder_alpha(float p_alpha); - float get_placeholder_alpha() const; - void set_caret_column(int p_column); int get_caret_column() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 7db1fae2b6..e060d3b901 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -874,7 +874,7 @@ void TextEdit::_notification(int p_what) { // Ensure we at least use the font color. Color current_color = !editable ? font_readonly_color : font_color; if (draw_placeholder) { - current_color.a *= placeholder_alpha; + current_color = font_placeholder_color; } const Ref<TextParagraph> ldata = draw_placeholder ? placeholder_data_buf : text.get_line_data(line); @@ -2515,6 +2515,7 @@ void TextEdit::_update_caches() { font_size = get_theme_font_size(SNAME("font_size")); font_color = get_theme_color(SNAME("font_color")); font_readonly_color = get_theme_color(SNAME("font_readonly_color")); + font_placeholder_color = get_theme_color(SNAME("font_placeholder_color")); outline_size = get_theme_constant(SNAME("outline_size")); outline_color = get_theme_color(SNAME("font_outline_color")); @@ -2947,15 +2948,6 @@ String TextEdit::get_placeholder() const { return placeholder_text; } -void TextEdit::set_placeholder_alpha(float p_alpha) { - placeholder_alpha = p_alpha; - update(); -} - -float TextEdit::get_placeholder_alpha() const { - return placeholder_alpha; -} - void TextEdit::set_line(int p_line, const String &p_new_text) { if (p_line < 0 || p_line >= text.size()) { return; @@ -4944,9 +4936,6 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_placeholder", "text"), &TextEdit::set_placeholder); ClassDB::bind_method(D_METHOD("get_placeholder"), &TextEdit::get_placeholder); - ClassDB::bind_method(D_METHOD("set_placeholder_alpha", "alpha"), &TextEdit::set_placeholder_alpha); - ClassDB::bind_method(D_METHOD("get_placeholder_alpha"), &TextEdit::get_placeholder_alpha); - ClassDB::bind_method(D_METHOD("set_line", "line", "new_text"), &TextEdit::set_line); ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line); @@ -5256,7 +5245,6 @@ void TextEdit::_bind_methods() { /* Inspector */ ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "placeholder_text", PROPERTY_HINT_MULTILINE_TEXT), "set_placeholder", "get_placeholder"); - ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "placeholder_alpha", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_placeholder_alpha", "get_placeholder_alpha"); ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language"); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index fdaa928598..079890249e 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -251,8 +251,6 @@ private: Point2 ime_selection; // Placeholder - float placeholder_alpha = 0.6; - String placeholder_text = ""; Array placeholder_bidi_override; Ref<TextParagraph> placeholder_data_buf; @@ -525,6 +523,7 @@ private: int font_size = 16; Color font_color = Color(1, 1, 1); Color font_readonly_color = Color(1, 1, 1); + Color font_placeholder_color = Color(1, 1, 1, 0.6); int outline_size = 0; Color outline_color = Color(1, 1, 1); @@ -684,9 +683,6 @@ public: void set_placeholder(const String &p_text); String get_placeholder() const; - void set_placeholder_alpha(float p_alpha); - float get_placeholder_alpha() const; - void set_line(int p_line, const String &p_new_text); String get_line(int p_line) const; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 69b06c1803..f7036578e2 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -577,8 +577,7 @@ void register_scene_types() { GDREGISTER_CLASS(VisualShaderNodeDotProduct); GDREGISTER_CLASS(VisualShaderNodeVectorLen); GDREGISTER_CLASS(VisualShaderNodeDeterminant); - GDREGISTER_CLASS(VisualShaderNodeScalarDerivativeFunc); - GDREGISTER_CLASS(VisualShaderNodeVectorDerivativeFunc); + GDREGISTER_CLASS(VisualShaderNodeDerivativeFunc); GDREGISTER_CLASS(VisualShaderNodeClamp); GDREGISTER_CLASS(VisualShaderNodeFaceForward); GDREGISTER_CLASS(VisualShaderNodeOuterProduct); @@ -1024,6 +1023,8 @@ void register_scene_types() { ClassDB::add_compatibility_class("VisualShaderNodeVectorScalarStep", "VisualShaderNodeStep"); ClassDB::add_compatibility_class("VisualShaderNodeScalarSwitch", "VisualShaderNodeSwitch"); ClassDB::add_compatibility_class("VisualShaderNodeScalarTransformMult", "VisualShaderNodeTransformOp"); + ClassDB::add_compatibility_class("VisualShaderNodeScalarDerivativeFunc", "VisualShaderNodeDerivativeFunc"); + ClassDB::add_compatibility_class("VisualShaderNodeVectorDerivativeFunc", "VisualShaderNodeDerivativeFunc"); ClassDB::add_compatibility_class("World", "World3D"); #endif /* DISABLE_DEPRECATED */ diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 12ea1683c8..be4dbfa64d 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -113,6 +113,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te const Color control_font_hover_color = Color(0.95, 0.95, 0.95); const Color control_font_focus_color = Color(0.95, 0.95, 0.95); const Color control_font_disabled_color = control_font_color * Color(1, 1, 1, 0.5); + const Color control_font_placeholder_color = Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.6f); const Color control_font_pressed_color = Color(1, 1, 1); const Color control_selection_color = Color(0.5, 0.5, 0.5); @@ -385,6 +386,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te theme->set_color("font_color", "LineEdit", control_font_color); theme->set_color("font_selected_color", "LineEdit", control_font_pressed_color); theme->set_color("font_uneditable_color", "LineEdit", control_font_disabled_color); + theme->set_color("font_placeholder_color", "LineEdit", control_font_placeholder_color); theme->set_color("font_outline_color", "LineEdit", Color(1, 1, 1)); theme->set_color("caret_color", "LineEdit", control_font_hover_color); theme->set_color("selection_color", "LineEdit", control_selection_color); @@ -427,6 +429,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te theme->set_color("font_color", "TextEdit", control_font_color); theme->set_color("font_selected_color", "TextEdit", control_font_pressed_color); theme->set_color("font_readonly_color", "TextEdit", control_font_disabled_color); + theme->set_color("font_placeholder_color", "TextEdit", control_font_placeholder_color); theme->set_color("font_outline_color", "TextEdit", Color(1, 1, 1)); theme->set_color("selection_color", "TextEdit", control_selection_color); theme->set_color("current_line_color", "TextEdit", Color(0.25, 0.25, 0.26, 0.8)); @@ -468,6 +471,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te theme->set_color("font_color", "CodeEdit", control_font_color); theme->set_color("font_selected_color", "CodeEdit", Color(0, 0, 0)); theme->set_color("font_readonly_color", "CodeEdit", Color(control_font_color.r, control_font_color.g, control_font_color.b, 0.5f)); + theme->set_color("font_placeholder_color", "CodeEdit", control_font_placeholder_color); theme->set_color("font_outline_color", "CodeEdit", Color(1, 1, 1)); theme->set_color("selection_color", "CodeEdit", control_selection_color); theme->set_color("bookmark_color", "CodeEdit", Color(0.5, 0.64, 1, 0.8)); diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 0cfa9f31f7..9987408046 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -2996,37 +2996,43 @@ VisualShaderNodeDeterminant::VisualShaderNodeDeterminant() { set_input_port_default_value(0, Transform3D()); } -////////////// Scalar Derivative Function +////////////// Derivative Function -String VisualShaderNodeScalarDerivativeFunc::get_caption() const { - return "ScalarDerivativeFunc"; +String VisualShaderNodeDerivativeFunc::get_caption() const { + return "DerivativeFunc"; } -int VisualShaderNodeScalarDerivativeFunc::get_input_port_count() const { +int VisualShaderNodeDerivativeFunc::get_input_port_count() const { return 1; } -VisualShaderNodeScalarDerivativeFunc::PortType VisualShaderNodeScalarDerivativeFunc::get_input_port_type(int p_port) const { +VisualShaderNodeDerivativeFunc::PortType VisualShaderNodeDerivativeFunc::get_input_port_type(int p_port) const { + if (op_type == OP_TYPE_VECTOR) { + return PORT_TYPE_VECTOR; + } return PORT_TYPE_SCALAR; } -String VisualShaderNodeScalarDerivativeFunc::get_input_port_name(int p_port) const { - return ""; +String VisualShaderNodeDerivativeFunc::get_input_port_name(int p_port) const { + return "p"; } -int VisualShaderNodeScalarDerivativeFunc::get_output_port_count() const { +int VisualShaderNodeDerivativeFunc::get_output_port_count() const { return 1; } -VisualShaderNodeScalarDerivativeFunc::PortType VisualShaderNodeScalarDerivativeFunc::get_output_port_type(int p_port) const { +VisualShaderNodeDerivativeFunc::PortType VisualShaderNodeDerivativeFunc::get_output_port_type(int p_port) const { + if (op_type == OP_TYPE_VECTOR) { + return PORT_TYPE_VECTOR; + } return PORT_TYPE_SCALAR; } -String VisualShaderNodeScalarDerivativeFunc::get_output_port_name(int p_port) const { - return ""; +String VisualShaderNodeDerivativeFunc::get_output_port_name(int p_port) const { + return "result"; } -String VisualShaderNodeScalarDerivativeFunc::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 { +String VisualShaderNodeDerivativeFunc::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 { static const char *functions[FUNC_MAX] = { "fwidth($)", "dFdx($)", @@ -3038,84 +3044,30 @@ String VisualShaderNodeScalarDerivativeFunc::generate_code(Shader::Mode p_mode, return code; } -void VisualShaderNodeScalarDerivativeFunc::set_function(Function p_func) { - ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX)); - if (func == p_func) { +void VisualShaderNodeDerivativeFunc::set_op_type(OpType p_op_type) { + ERR_FAIL_INDEX((int)p_op_type, int(OP_TYPE_MAX)); + if (op_type == p_op_type) { return; } - func = p_func; + switch (p_op_type) { + case OP_TYPE_SCALAR: + set_input_port_default_value(0, 0.0); + break; + case OP_TYPE_VECTOR: + set_input_port_default_value(0, Vector3(0.0, 0.0, 0.0)); + break; + default: + break; + } + op_type = p_op_type; emit_changed(); } -VisualShaderNodeScalarDerivativeFunc::Function VisualShaderNodeScalarDerivativeFunc::get_function() const { - return func; -} - -Vector<StringName> VisualShaderNodeScalarDerivativeFunc::get_editable_properties() const { - Vector<StringName> props; - props.push_back("function"); - return props; -} - -void VisualShaderNodeScalarDerivativeFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeScalarDerivativeFunc::set_function); - ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeScalarDerivativeFunc::get_function); - - ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Sum,X,Y"), "set_function", "get_function"); - - BIND_ENUM_CONSTANT(FUNC_SUM); - BIND_ENUM_CONSTANT(FUNC_X); - BIND_ENUM_CONSTANT(FUNC_Y); - BIND_ENUM_CONSTANT(FUNC_MAX); -} - -VisualShaderNodeScalarDerivativeFunc::VisualShaderNodeScalarDerivativeFunc() { - set_input_port_default_value(0, 0.0); -} - -////////////// Vector Derivative Function - -String VisualShaderNodeVectorDerivativeFunc::get_caption() const { - return "VectorDerivativeFunc"; -} - -int VisualShaderNodeVectorDerivativeFunc::get_input_port_count() const { - return 1; -} - -VisualShaderNodeVectorDerivativeFunc::PortType VisualShaderNodeVectorDerivativeFunc::get_input_port_type(int p_port) const { - return PORT_TYPE_VECTOR; -} - -String VisualShaderNodeVectorDerivativeFunc::get_input_port_name(int p_port) const { - return ""; -} - -int VisualShaderNodeVectorDerivativeFunc::get_output_port_count() const { - return 1; -} - -VisualShaderNodeVectorDerivativeFunc::PortType VisualShaderNodeVectorDerivativeFunc::get_output_port_type(int p_port) const { - return PORT_TYPE_VECTOR; -} - -String VisualShaderNodeVectorDerivativeFunc::get_output_port_name(int p_port) const { - return ""; -} - -String VisualShaderNodeVectorDerivativeFunc::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 { - static const char *functions[FUNC_MAX] = { - "fwidth($)", - "dFdx($)", - "dFdy($)" - }; - - String code; - code += " " + p_output_vars[0] + " = " + String(functions[func]).replace("$", p_input_vars[0]) + ";\n"; - return code; +VisualShaderNodeDerivativeFunc::OpType VisualShaderNodeDerivativeFunc::get_op_type() const { + return op_type; } -void VisualShaderNodeVectorDerivativeFunc::set_function(Function p_func) { +void VisualShaderNodeDerivativeFunc::set_function(Function p_func) { ERR_FAIL_INDEX(int(p_func), int(FUNC_MAX)); if (func == p_func) { return; @@ -3124,30 +3076,39 @@ void VisualShaderNodeVectorDerivativeFunc::set_function(Function p_func) { emit_changed(); } -VisualShaderNodeVectorDerivativeFunc::Function VisualShaderNodeVectorDerivativeFunc::get_function() const { +VisualShaderNodeDerivativeFunc::Function VisualShaderNodeDerivativeFunc::get_function() const { return func; } -Vector<StringName> VisualShaderNodeVectorDerivativeFunc::get_editable_properties() const { +Vector<StringName> VisualShaderNodeDerivativeFunc::get_editable_properties() const { Vector<StringName> props; + props.push_back("op_type"); props.push_back("function"); return props; } -void VisualShaderNodeVectorDerivativeFunc::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeVectorDerivativeFunc::set_function); - ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeVectorDerivativeFunc::get_function); +void VisualShaderNodeDerivativeFunc::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeDerivativeFunc::set_op_type); + ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeDerivativeFunc::get_op_type); + + ClassDB::bind_method(D_METHOD("set_function", "func"), &VisualShaderNodeDerivativeFunc::set_function); + ClassDB::bind_method(D_METHOD("get_function"), &VisualShaderNodeDerivativeFunc::get_function); + ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector"), "set_op_type", "get_op_type"); ADD_PROPERTY(PropertyInfo(Variant::INT, "function", PROPERTY_HINT_ENUM, "Sum,X,Y"), "set_function", "get_function"); + BIND_ENUM_CONSTANT(OP_TYPE_SCALAR); + BIND_ENUM_CONSTANT(OP_TYPE_VECTOR); + BIND_ENUM_CONSTANT(OP_TYPE_MAX); + BIND_ENUM_CONSTANT(FUNC_SUM); BIND_ENUM_CONSTANT(FUNC_X); BIND_ENUM_CONSTANT(FUNC_Y); BIND_ENUM_CONSTANT(FUNC_MAX); } -VisualShaderNodeVectorDerivativeFunc::VisualShaderNodeVectorDerivativeFunc() { - set_input_port_default_value(0, Vector3()); +VisualShaderNodeDerivativeFunc::VisualShaderNodeDerivativeFunc() { + set_input_port_default_value(0, 0.0); } ////////////// Clamp diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h index bf5777a3fb..16f916f240 100644 --- a/scene/resources/visual_shader_nodes.h +++ b/scene/resources/visual_shader_nodes.h @@ -1235,54 +1235,19 @@ public: VARIANT_ENUM_CAST(VisualShaderNodeClamp::OpType) /////////////////////////////////////// -/// DERIVATIVE FUNCTIONS +/// DERIVATIVE FUNCTION /////////////////////////////////////// -class VisualShaderNodeScalarDerivativeFunc : public VisualShaderNode { - GDCLASS(VisualShaderNodeScalarDerivativeFunc, VisualShaderNode); +class VisualShaderNodeDerivativeFunc : public VisualShaderNode { + GDCLASS(VisualShaderNodeDerivativeFunc, VisualShaderNode); public: - enum Function { - FUNC_SUM, - FUNC_X, - FUNC_Y, - FUNC_MAX, + enum OpType { + OP_TYPE_SCALAR, + OP_TYPE_VECTOR, + OP_TYPE_MAX, }; -protected: - Function func = FUNC_SUM; - - static void _bind_methods(); - -public: - virtual String get_caption() const override; - - virtual int get_input_port_count() const override; - virtual PortType get_input_port_type(int p_port) const override; - virtual String get_input_port_name(int p_port) const override; - - virtual int get_output_port_count() const override; - virtual PortType get_output_port_type(int p_port) const override; - virtual String get_output_port_name(int p_port) const override; - - 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 override; - - void set_function(Function p_func); - Function get_function() const; - - virtual Vector<StringName> get_editable_properties() const override; - - VisualShaderNodeScalarDerivativeFunc(); -}; - -VARIANT_ENUM_CAST(VisualShaderNodeScalarDerivativeFunc::Function) - -/////////////////////////////////////// - -class VisualShaderNodeVectorDerivativeFunc : public VisualShaderNode { - GDCLASS(VisualShaderNodeVectorDerivativeFunc, VisualShaderNode); - -public: enum Function { FUNC_SUM, FUNC_X, @@ -1291,8 +1256,10 @@ public: }; protected: + OpType op_type = OP_TYPE_SCALAR; Function func = FUNC_SUM; +protected: static void _bind_methods(); public: @@ -1308,15 +1275,19 @@ public: 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 override; + void set_op_type(OpType p_op_type); + OpType get_op_type() const; + void set_function(Function p_func); Function get_function() const; virtual Vector<StringName> get_editable_properties() const override; - VisualShaderNodeVectorDerivativeFunc(); + VisualShaderNodeDerivativeFunc(); }; -VARIANT_ENUM_CAST(VisualShaderNodeVectorDerivativeFunc::Function) +VARIANT_ENUM_CAST(VisualShaderNodeDerivativeFunc::OpType) +VARIANT_ENUM_CAST(VisualShaderNodeDerivativeFunc::Function) /////////////////////////////////////// /// FACEFORWARD |