summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/touch_screen_button.cpp5
-rw-r--r--scene/3d/audio_stream_player_3d.cpp5
-rw-r--r--scene/3d/camera_3d.cpp2
-rw-r--r--scene/animation/tween.cpp10
-rw-r--r--scene/gui/control.cpp2
-rw-r--r--scene/gui/link_button.cpp4
-rw-r--r--scene/gui/popup_menu.cpp6
-rw-r--r--scene/gui/popup_menu.h1
-rw-r--r--scene/gui/rich_text_label.cpp6
-rw-r--r--scene/gui/text_edit.cpp7
-rw-r--r--scene/gui/tree.cpp3
-rw-r--r--scene/resources/dynamic_font.cpp28
-rw-r--r--scene/resources/dynamic_font.h6
-rw-r--r--scene/resources/font.cpp10
-rw-r--r--scene/resources/font.h4
-rw-r--r--scene/resources/visual_shader.cpp45
-rw-r--r--scene/resources/visual_shader.h17
-rw-r--r--scene/resources/visual_shader_nodes.cpp66
-rw-r--r--scene/resources/visual_shader_nodes.h14
19 files changed, 211 insertions, 30 deletions
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp
index 85fd05ac15..590cc1e6c4 100644
--- a/scene/2d/touch_screen_button.cpp
+++ b/scene/2d/touch_screen_button.cpp
@@ -260,9 +260,10 @@ bool TouchScreenButton::_is_point_inside(const Point2 &p_point) {
bool check_rect = true;
if (shape.is_valid()) {
-
check_rect = false;
- Transform2D xform = shape_centered ? Transform2D().translated(shape->get_rect().size * 0.5f) : Transform2D();
+
+ Vector2 size = texture.is_null() ? shape->get_rect().size : texture->get_size();
+ Transform2D xform = shape_centered ? Transform2D().translated(size * 0.5f) : Transform2D();
touched = shape->collide(xform, unit_rect, Transform2D(0, coord + Vector2(0.5, 0.5)));
}
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index f2395d35fb..5701d3cea2 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -710,6 +710,11 @@ float AudioStreamPlayer3D::get_pitch_scale() const {
void AudioStreamPlayer3D::play(float p_from_pos) {
+ if (!is_playing()) {
+ // Reset the prev_output_count if the stream is stopped
+ prev_output_count = 0;
+ }
+
if (stream_playback.is_valid()) {
active = true;
setplay = p_from_pos;
diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp
index 2fcb2715be..871f3119bc 100644
--- a/scene/3d/camera_3d.cpp
+++ b/scene/3d/camera_3d.cpp
@@ -689,7 +689,7 @@ Camera3D::Camera3D() {
viewport = nullptr;
force_change = false;
mode = PROJECTION_PERSPECTIVE;
- set_perspective(70.0, 0.05, 100.0);
+ set_perspective(75.0, 0.05, 100.0);
keep_aspect = KEEP_HEIGHT;
layers = 0xfffff;
v_offset = 0;
diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp
index bc28c38e2c..d0c6cac8cf 100644
--- a/scene/animation/tween.cpp
+++ b/scene/animation/tween.cpp
@@ -126,14 +126,17 @@ bool Tween::_set(const StringName &p_name, const Variant &p_value) {
String name = p_name;
if (name == "playback/speed" || name == "speed") { // Backwards compatibility
set_speed_scale(p_value);
+ return true;
} else if (name == "playback/active") {
set_active(p_value);
+ return true;
} else if (name == "playback/repeat") {
set_repeat(p_value);
+ return true;
}
- return true;
+ return false;
}
bool Tween::_get(const StringName &p_name, Variant &r_ret) const {
@@ -142,14 +145,17 @@ bool Tween::_get(const StringName &p_name, Variant &r_ret) const {
String name = p_name;
if (name == "playback/speed") { // Backwards compatibility
r_ret = speed_scale;
+ return true;
} else if (name == "playback/active") {
r_ret = is_active();
+ return true;
} else if (name == "playback/repeat") {
r_ret = is_repeat();
+ return true;
}
- return true;
+ return false;
}
void Tween::_get_property_list(List<PropertyInfo> *p_list) const {
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index b4dc37c74f..b710ba4803 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2896,7 +2896,7 @@ void Control::_bind_methods() {
ADD_GROUP("Size Flags", "size_flags_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
ADD_GROUP("Theme", "");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_GROUP("", "");
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index 3dffa06b49..098e8297ad 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -111,11 +111,11 @@ void LinkButton::_notification(int p_what) {
draw_string(font, Vector2(0, font->get_ascent()), text, color);
if (do_underline) {
- int underline_spacing = get_theme_constant("underline_spacing");
+ int underline_spacing = get_theme_constant("underline_spacing") + font->get_underline_position();
int width = font->get_string_size(text).width;
int y = font->get_ascent() + underline_spacing;
- draw_line(Vector2(0, y), Vector2(width, y), color);
+ draw_line(Vector2(0, y), Vector2(width, y), color, font->get_underline_thickness());
}
} break;
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index a247863298..9c48801ec1 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -1079,6 +1079,11 @@ bool PopupMenu::is_item_shortcut_disabled(int p_idx) const {
return items[p_idx].shortcut_is_disabled;
}
+int PopupMenu::get_current_index() const {
+
+ return mouse_over;
+}
+
int PopupMenu::get_item_count() const {
return items.size();
@@ -1457,6 +1462,7 @@ void PopupMenu::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_item_tooltip", "idx"), &PopupMenu::get_item_tooltip);
ClassDB::bind_method(D_METHOD("get_item_shortcut", "idx"), &PopupMenu::get_item_shortcut);
+ ClassDB::bind_method(D_METHOD("get_current_index"), &PopupMenu::get_current_index);
ClassDB::bind_method(D_METHOD("get_item_count"), &PopupMenu::get_item_count);
ClassDB::bind_method(D_METHOD("remove_item", "idx"), &PopupMenu::remove_item);
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index 2eef1f009d..d5c1015863 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -178,6 +178,7 @@ public:
Ref<ShortCut> get_item_shortcut(int p_idx) const;
int get_item_state(int p_idx) const;
+ int get_current_index() const;
int get_item_count() const;
bool activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only = false);
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 5c293cdf3c..84097eb6a1 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -600,8 +600,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
if (underline) {
Color uc = color;
uc.a *= 0.5;
- int uy = y + lh - line_descent + 2;
- float underline_width = 1.0;
+ int uy = y + lh - line_descent + font->get_underline_position();
+ float underline_width = font->get_underline_thickness();
#ifdef TOOLS_ENABLED
underline_width *= EDSCALE;
#endif
@@ -610,7 +610,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
Color uc = color;
uc.a *= 0.5;
int uy = y + lh - (line_ascent + line_descent) / 2;
- float strikethrough_width = 1.0;
+ float strikethrough_width = font->get_underline_thickness();
#ifdef TOOLS_ENABLED
strikethrough_width *= EDSCALE;
#endif
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 9ee7456d26..aa518fbb7d 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1153,7 +1153,7 @@ void TextEdit::_notification(int p_what) {
highlighted_text_col = _get_column_pos_of_word(highlighted_text, str, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
if (select_identifiers_enabled && highlighted_word.length() != 0) {
- if (_is_char(highlighted_word[0])) {
+ if (_is_char(highlighted_word[0]) || highlighted_word[0] == '.') {
highlighted_word_col = _get_column_pos_of_word(highlighted_word, fullstr, SEARCH_MATCH_CASE | SEARCH_WHOLE_WORDS, 0);
}
}
@@ -1487,12 +1487,12 @@ void TextEdit::_notification(int p_what) {
int yofs = ofs_y + (get_row_height() - cache.font->get_height()) / 2;
int w = drawer.draw_char(ci, Point2i(char_ofs + char_margin + ofs_x, yofs + ascent), str[j], str[j + 1], in_selection && override_selected_font_color ? cache.font_color_selected : color);
if (underlined) {
- float line_width = 1.0;
+ float line_width = cache.font->get_underline_thickness();
#ifdef TOOLS_ENABLED
line_width *= EDSCALE;
#endif
- draw_rect(Rect2(char_ofs + char_margin + ofs_x, yofs + ascent + 2, w, line_width), in_selection && override_selected_font_color ? cache.font_color_selected : color);
+ draw_rect(Rect2(char_ofs + char_margin + ofs_x, yofs + ascent + cache.font->get_underline_position(), w, line_width), in_selection && override_selected_font_color ? cache.font_color_selected : color);
}
} else if (draw_tabs && str[j] == '\t') {
int yofs = (get_row_height() - cache.tab_icon->get_height()) / 2;
@@ -7083,6 +7083,7 @@ void TextEdit::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_line_count"), &TextEdit::get_line_count);
ClassDB::bind_method(D_METHOD("get_text"), &TextEdit::get_text);
ClassDB::bind_method(D_METHOD("get_line", "line"), &TextEdit::get_line);
+ ClassDB::bind_method(D_METHOD("set_line", "line", "new_text"), &TextEdit::set_line);
ClassDB::bind_method(D_METHOD("center_viewport_to_cursor"), &TextEdit::center_viewport_to_cursor);
ClassDB::bind_method(D_METHOD("cursor_set_column", "column", "adjust_viewport"), &TextEdit::cursor_set_column, DEFVAL(true));
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index aad36ebf02..329c1085df 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -779,6 +779,9 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_text", "column", "text"), &TreeItem::set_text);
ClassDB::bind_method(D_METHOD("get_text", "column"), &TreeItem::get_text);
+ ClassDB::bind_method(D_METHOD("set_suffix", "column", "text"), &TreeItem::set_suffix);
+ ClassDB::bind_method(D_METHOD("get_suffix", "column"), &TreeItem::get_suffix);
+
ClassDB::bind_method(D_METHOD("set_icon", "column", "texture"), &TreeItem::set_icon);
ClassDB::bind_method(D_METHOD("get_icon", "column"), &TreeItem::get_icon);
diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp
index eea4d12d0e..442151de36 100644
--- a/scene/resources/dynamic_font.cpp
+++ b/scene/resources/dynamic_font.cpp
@@ -221,6 +221,8 @@ Error DynamicFontAtSize::_load() {
ascent = (face->size->metrics.ascender / 64.0) / oversampling * scale_color_font;
descent = (-face->size->metrics.descender / 64.0) / oversampling * scale_color_font;
+ underline_position = -face->underline_position / 64.0 / oversampling * scale_color_font;
+ underline_thickness = face->underline_thickness / 64.0 / oversampling * scale_color_font;
linegap = 0;
valid = true;
@@ -243,6 +245,16 @@ float DynamicFontAtSize::get_descent() const {
return descent;
}
+float DynamicFontAtSize::get_underline_position() const {
+
+ return underline_position;
+}
+
+float DynamicFontAtSize::get_underline_thickness() const {
+
+ return underline_thickness;
+}
+
const Pair<const DynamicFontAtSize::Character *, DynamicFontAtSize *> DynamicFontAtSize::_find_char_with_font(CharType p_char, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const {
const Character *chr = char_map.getptr(p_char);
ERR_FAIL_COND_V(!chr, (Pair<const Character *, DynamicFontAtSize *>(nullptr, nullptr)));
@@ -821,6 +833,22 @@ float DynamicFont::get_descent() const {
return data_at_size->get_descent() + spacing_bottom;
}
+float DynamicFont::get_underline_position() const {
+
+ if (!data_at_size.is_valid())
+ return 2;
+
+ return data_at_size->get_underline_position();
+}
+
+float DynamicFont::get_underline_thickness() const {
+
+ if (!data_at_size.is_valid())
+ return 1;
+
+ return data_at_size->get_underline_thickness();
+}
+
Size2 DynamicFont::get_char_size(CharType p_char, CharType p_next) const {
if (!data_at_size.is_valid())
diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h
index ef4b9dd9d0..2fa1951d27 100644
--- a/scene/resources/dynamic_font.h
+++ b/scene/resources/dynamic_font.h
@@ -124,6 +124,8 @@ class DynamicFontAtSize : public Reference {
float rect_margin;
float oversampling;
float scale_color_font;
+ float underline_position;
+ float underline_thickness;
bool valid;
@@ -187,6 +189,8 @@ public:
float get_ascent() const;
float get_descent() const;
+ float get_underline_position() const;
+ float get_underline_thickness() const;
Size2 get_char_size(CharType p_char, CharType p_next, const Vector<Ref<DynamicFontAtSize>> &p_fallbacks) const;
@@ -274,6 +278,8 @@ public:
virtual float get_ascent() const;
virtual float get_descent() const;
+ virtual float get_underline_position() const;
+ virtual float get_underline_thickness() const;
virtual Size2 get_char_size(CharType p_char, CharType p_next = 0) const;
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index 267816f267..51c2ff389a 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -356,6 +356,16 @@ float BitmapFont::get_descent() const {
return height - ascent;
}
+float BitmapFont::get_underline_position() const {
+
+ return 2;
+}
+
+float BitmapFont::get_underline_thickness() const {
+
+ return 1;
+}
+
void BitmapFont::add_texture(const Ref<Texture2D> &p_texture) {
ERR_FAIL_COND_MSG(p_texture.is_null(), "It's not a reference to a valid Texture object.");
diff --git a/scene/resources/font.h b/scene/resources/font.h
index c233344529..54b1eaa1b9 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -47,6 +47,8 @@ public:
virtual float get_ascent() const = 0;
virtual float get_descent() const = 0;
+ virtual float get_underline_position() const = 0;
+ virtual float get_underline_thickness() const = 0;
virtual Size2 get_char_size(CharType p_char, CharType p_next = 0) const = 0;
Size2 get_string_size(const String &p_string) const;
@@ -167,6 +169,8 @@ public:
void set_ascent(float p_ascent);
float get_ascent() const;
float get_descent() const;
+ float get_underline_position() const;
+ float get_underline_thickness() const;
void add_texture(const Ref<Texture2D> &p_texture);
void add_char(CharType p_char, int p_texture_idx, const Rect2 &p_rect, const Size2 &p_align, float p_advance = -1);
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 310a7ef4e4..3b245f908a 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -1630,9 +1630,11 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_vec", "vec3(LIGHT_VEC, 0.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "light_height", "LIGHT_HEIGHT" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_color", "LIGHT_COLOR.rgb" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_alpha", "LIGHT_COLOR.a" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "light_alpha", "LIGHT_COLOR.a" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_uv", "vec3(LIGHT_UV, 0.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "shadow_color", "SHADOW_COLOR.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "shadow_alpha", "SHADOW_COLOR.a" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "shadow_vec", "vec3(SHADOW_VEC, 0.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "screen_uv", "vec3(SCREEN_UV, 0.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "texture_pixel_size", "vec3(TEXTURE_PIXEL_SIZE, 1.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "point_coord", "vec3(POINT_COORD, 0.0)" },
@@ -2156,12 +2158,43 @@ String VisualShaderNodeUniform::get_uniform_name() const {
return uniform_name;
}
+void VisualShaderNodeUniform::set_qualifier(VisualShaderNodeUniform::Qualifier p_qual) {
+ qualifier = p_qual;
+ emit_changed();
+}
+
+VisualShaderNodeUniform::Qualifier VisualShaderNodeUniform::get_qualifier() const {
+ return qualifier;
+}
+
void VisualShaderNodeUniform::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_uniform_name", "name"), &VisualShaderNodeUniform::set_uniform_name);
ClassDB::bind_method(D_METHOD("get_uniform_name"), &VisualShaderNodeUniform::get_uniform_name);
+ ClassDB::bind_method(D_METHOD("set_qualifier", "qualifier"), &VisualShaderNodeUniform::set_qualifier);
+ ClassDB::bind_method(D_METHOD("get_qualifier"), &VisualShaderNodeUniform::get_qualifier);
+
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "uniform_name"), "set_uniform_name", "get_uniform_name");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "qualifier", PROPERTY_HINT_ENUM, "None,Global,Instance"), "set_qualifier", "get_qualifier");
+
+ BIND_ENUM_CONSTANT(QUAL_NONE);
+ BIND_ENUM_CONSTANT(QUAL_GLOBAL);
+ BIND_ENUM_CONSTANT(QUAL_INSTANCE);
+}
+
+String VisualShaderNodeUniform::_get_qual_str() const {
+ if (is_qualifier_supported(qualifier)) {
+ switch (qualifier) {
+ case QUAL_NONE:
+ break;
+ case QUAL_GLOBAL:
+ return "global ";
+ case QUAL_INSTANCE:
+ return "instance ";
+ }
+ }
+ return String();
}
String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const {
@@ -2171,11 +2204,21 @@ String VisualShaderNodeUniform::get_warning(Shader::Mode p_mode, VisualShader::T
if (keyword_list.find(uniform_name)) {
return TTR("Uniform name cannot be equal to a shader keyword. Choose another name.");
}
+ if (!is_qualifier_supported(qualifier)) {
+ return "This uniform type does not support that qualifier.";
+ }
return String();
}
+Vector<StringName> VisualShaderNodeUniform::get_editable_properties() const {
+ Vector<StringName> props;
+ props.push_back("qualifier");
+ return props;
+}
+
VisualShaderNodeUniform::VisualShaderNodeUniform() {
+ qualifier = QUAL_NONE;
}
////////////// GroupBase
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index ecf3f93fbb..56f8e74d2b 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -369,21 +369,38 @@ public:
class VisualShaderNodeUniform : public VisualShaderNode {
GDCLASS(VisualShaderNodeUniform, VisualShaderNode);
+public:
+ enum Qualifier {
+ QUAL_NONE,
+ QUAL_GLOBAL,
+ QUAL_INSTANCE,
+ };
+
private:
String uniform_name;
+ Qualifier qualifier;
protected:
static void _bind_methods();
+ String _get_qual_str() const;
public:
void set_uniform_name(const String &p_name);
String get_uniform_name() const;
+ void set_qualifier(Qualifier p_qual);
+ Qualifier get_qualifier() const;
+
+ virtual bool is_qualifier_supported(Qualifier p_qual) const = 0;
+
+ virtual Vector<StringName> get_editable_properties() const;
virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const;
VisualShaderNodeUniform();
};
+VARIANT_ENUM_CAST(VisualShaderNodeUniform::Qualifier)
+
class VisualShaderNodeGroupBase : public VisualShaderNode {
GDCLASS(VisualShaderNodeGroupBase, VisualShaderNode);
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 2064ca10f3..7b9953a90f 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -3283,11 +3283,11 @@ String VisualShaderNodeFloatUniform::get_output_port_name(int p_port) const {
String VisualShaderNodeFloatUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
if (hint == HINT_RANGE) {
- return "uniform float " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ");\n";
+ return _get_qual_str() + "uniform float " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ");\n";
} else if (hint == HINT_RANGE_STEP) {
- return "uniform float " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ");\n";
+ return _get_qual_str() + "uniform float " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ");\n";
}
- return "uniform float " + get_uniform_name() + ";\n";
+ return _get_qual_str() + "uniform float " + get_uniform_name() + ";\n";
}
String VisualShaderNodeFloatUniform::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 {
@@ -3353,8 +3353,12 @@ void VisualShaderNodeFloatUniform::_bind_methods() {
BIND_ENUM_CONSTANT(HINT_RANGE_STEP);
}
+bool VisualShaderNodeFloatUniform::is_qualifier_supported(Qualifier p_qual) const {
+ return true; // all qualifiers are supported
+}
+
Vector<StringName> VisualShaderNodeFloatUniform::get_editable_properties() const {
- Vector<StringName> props;
+ Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("hint");
if (hint == HINT_RANGE || hint == HINT_RANGE_STEP) {
props.push_back("min");
@@ -3405,11 +3409,11 @@ String VisualShaderNodeIntUniform::get_output_port_name(int p_port) const {
String VisualShaderNodeIntUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
if (hint == HINT_RANGE) {
- return "uniform int " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ");\n";
+ return _get_qual_str() + "uniform int " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ");\n";
} else if (hint == HINT_RANGE_STEP) {
- return "uniform int " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ");\n";
+ return _get_qual_str() + "uniform int " + get_uniform_name() + " : hint_range(" + rtos(hint_range_min) + ", " + rtos(hint_range_max) + ", " + rtos(hint_range_step) + ");\n";
}
- return "uniform int " + get_uniform_name() + ";\n";
+ return _get_qual_str() + "uniform int " + get_uniform_name() + ";\n";
}
String VisualShaderNodeIntUniform::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 {
@@ -3475,8 +3479,12 @@ void VisualShaderNodeIntUniform::_bind_methods() {
BIND_ENUM_CONSTANT(HINT_RANGE_STEP);
}
+bool VisualShaderNodeIntUniform::is_qualifier_supported(Qualifier p_qual) const {
+ return true; // all qualifiers are supported
+}
+
Vector<StringName> VisualShaderNodeIntUniform::get_editable_properties() const {
- Vector<StringName> props;
+ Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("hint");
if (hint == HINT_RANGE || hint == HINT_RANGE_STEP) {
props.push_back("min");
@@ -3526,13 +3534,17 @@ String VisualShaderNodeBooleanUniform::get_output_port_name(int p_port) const {
}
String VisualShaderNodeBooleanUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform bool " + get_uniform_name() + ";\n";
+ return _get_qual_str() + "uniform bool " + get_uniform_name() + ";\n";
}
String VisualShaderNodeBooleanUniform::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] + " = " + get_uniform_name() + ";\n";
}
+bool VisualShaderNodeBooleanUniform::is_qualifier_supported(Qualifier p_qual) const {
+ return true; // all qualifiers are supported
+}
+
VisualShaderNodeBooleanUniform::VisualShaderNodeBooleanUniform() {
}
@@ -3568,7 +3580,7 @@ String VisualShaderNodeColorUniform::get_output_port_name(int p_port) const {
String VisualShaderNodeColorUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform vec4 " + get_uniform_name() + " : hint_color;\n";
+ return _get_qual_str() + "uniform vec4 " + get_uniform_name() + " : hint_color;\n";
}
String VisualShaderNodeColorUniform::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 {
@@ -3577,6 +3589,10 @@ String VisualShaderNodeColorUniform::generate_code(Shader::Mode p_mode, VisualSh
return code;
}
+bool VisualShaderNodeColorUniform::is_qualifier_supported(Qualifier p_qual) const {
+ return true; // all qualifiers are supported
+}
+
VisualShaderNodeColorUniform::VisualShaderNodeColorUniform() {
}
@@ -3611,13 +3627,17 @@ String VisualShaderNodeVec3Uniform::get_output_port_name(int p_port) const {
}
String VisualShaderNodeVec3Uniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform vec3 " + get_uniform_name() + ";\n";
+ return _get_qual_str() + "uniform vec3 " + get_uniform_name() + ";\n";
}
String VisualShaderNodeVec3Uniform::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] + " = " + get_uniform_name() + ";\n";
}
+bool VisualShaderNodeVec3Uniform::is_qualifier_supported(Qualifier p_qual) const {
+ return true; // all qualifiers are supported
+}
+
VisualShaderNodeVec3Uniform::VisualShaderNodeVec3Uniform() {
}
@@ -3652,13 +3672,17 @@ String VisualShaderNodeTransformUniform::get_output_port_name(int p_port) const
}
String VisualShaderNodeTransformUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- return "uniform mat4 " + get_uniform_name() + ";\n";
+ return _get_qual_str() + "uniform mat4 " + get_uniform_name() + ";\n";
}
String VisualShaderNodeTransformUniform::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] + " = " + get_uniform_name() + ";\n";
}
+bool VisualShaderNodeTransformUniform::is_qualifier_supported(Qualifier p_qual) const {
+ return true; // all qualifiers are supported
+}
+
VisualShaderNodeTransformUniform::VisualShaderNodeTransformUniform() {
}
@@ -3713,7 +3737,7 @@ String VisualShaderNodeTextureUniform::get_output_port_name(int p_port) const {
}
String VisualShaderNodeTextureUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform sampler2D " + get_uniform_name();
+ String code = _get_qual_str() + "uniform sampler2D " + get_uniform_name();
switch (texture_type) {
case TYPE_DATA:
@@ -3778,7 +3802,7 @@ VisualShaderNodeTextureUniform::ColorDefault VisualShaderNodeTextureUniform::get
}
Vector<StringName> VisualShaderNodeTextureUniform::get_editable_properties() const {
- Vector<StringName> props;
+ Vector<StringName> props = VisualShaderNodeUniform::get_editable_properties();
props.push_back("texture_type");
props.push_back("color_default");
return props;
@@ -3810,6 +3834,18 @@ String VisualShaderNodeTextureUniform::get_input_port_default_hint(int p_port) c
return "";
}
+bool VisualShaderNodeTextureUniform::is_qualifier_supported(Qualifier p_qual) const {
+ switch (p_qual) {
+ case Qualifier::QUAL_NONE:
+ return true;
+ case Qualifier::QUAL_GLOBAL:
+ return true;
+ case Qualifier::QUAL_INSTANCE:
+ return false;
+ }
+ return false;
+}
+
VisualShaderNodeTextureUniform::VisualShaderNodeTextureUniform() {
texture_type = TYPE_DATA;
color_default = COLOR_DEFAULT_WHITE;
@@ -3952,7 +3988,7 @@ String VisualShaderNodeCubemapUniform::get_input_port_default_hint(int p_port) c
}
String VisualShaderNodeCubemapUniform::generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
- String code = "uniform samplerCube " + get_uniform_name();
+ String code = _get_qual_str() + "uniform samplerCube " + get_uniform_name();
switch (texture_type) {
case TYPE_DATA:
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index 035e39230c..69f42f621a 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -1457,6 +1457,8 @@ public:
void set_step(float p_value);
float get_step() const;
+ bool is_qualifier_supported(Qualifier p_qual) const;
+
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeFloatUniform();
@@ -1509,6 +1511,8 @@ public:
void set_step(int p_value);
int get_step() const;
+ bool is_qualifier_supported(Qualifier p_qual) const;
+
virtual Vector<StringName> get_editable_properties() const;
VisualShaderNodeIntUniform();
@@ -1535,6 +1539,8 @@ public:
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) 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
+ bool is_qualifier_supported(Qualifier p_qual) const;
+
VisualShaderNodeBooleanUniform();
};
@@ -1557,6 +1563,8 @@ public:
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) 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
+ bool is_qualifier_supported(Qualifier p_qual) const;
+
VisualShaderNodeColorUniform();
};
@@ -1579,6 +1587,8 @@ public:
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) 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
+ bool is_qualifier_supported(Qualifier p_qual) const;
+
VisualShaderNodeVec3Uniform();
};
@@ -1601,6 +1611,8 @@ public:
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) 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
+ bool is_qualifier_supported(Qualifier p_qual) const;
+
VisualShaderNodeTransformUniform();
};
@@ -1652,6 +1664,8 @@ public:
void set_color_default(ColorDefault p_default);
ColorDefault get_color_default() const;
+ bool is_qualifier_supported(Qualifier p_qual) const;
+
VisualShaderNodeTextureUniform();
};