diff options
Diffstat (limited to 'scene/resources')
35 files changed, 589 insertions, 744 deletions
diff --git a/scene/resources/SCsub b/scene/resources/SCsub index 2ad90247a7..5e5b6f8fd5 100644 --- a/scene/resources/SCsub +++ b/scene/resources/SCsub @@ -4,6 +4,4 @@ Import('env') env.add_source_files(env.scene_sources, "*.cpp") -Export('env') - SConscript("default_theme/SCsub") diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 80ad2ad739..803c85ef34 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1469,7 +1469,7 @@ int Animation::_find(const Vector<K> &p_keys, float p_time) const { middle = (low + high) / 2; - if (p_time == keys[middle].time) { //match + if (Math::abs(p_time - keys[middle].time) < CMP_EPSILON) { //match return middle; } else if (p_time < keys[middle].time) high = middle - 1; //search low end of array @@ -1901,7 +1901,7 @@ void Animation::value_track_set_update_mode(int p_track, UpdateMode p_mode) { ERR_FAIL_INDEX(p_track, tracks.size()); Track *t = tracks[p_track]; ERR_FAIL_COND(t->type != TYPE_VALUE); - ERR_FAIL_INDEX(p_mode, 4); + ERR_FAIL_INDEX((int)p_mode, 4); ValueTrack *vt = static_cast<ValueTrack *>(t); vt->update_mode = p_mode; diff --git a/scene/resources/convex_polygon_shape.cpp b/scene/resources/convex_polygon_shape.cpp index 9d47bca5ed..39488760cd 100644 --- a/scene/resources/convex_polygon_shape.cpp +++ b/scene/resources/convex_polygon_shape.cpp @@ -38,10 +38,9 @@ Vector<Vector3> ConvexPolygonShape::_gen_debug_mesh_lines() { if (points.size() > 3) { - QuickHull qh; Vector<Vector3> varr = Variant(points); Geometry::MeshData md; - Error err = qh.build(varr, md); + Error err = QuickHull::build(varr, md); if (err == OK) { Vector<Vector3> lines; lines.resize(md.edges.size() * 2); diff --git a/scene/resources/convex_polygon_shape_2d.cpp b/scene/resources/convex_polygon_shape_2d.cpp index f325af7ea4..fc3d3f3334 100644 --- a/scene/resources/convex_polygon_shape_2d.cpp +++ b/scene/resources/convex_polygon_shape_2d.cpp @@ -41,7 +41,11 @@ bool ConvexPolygonShape2D::_edit_is_selected_on_click(const Point2 &p_point, dou void ConvexPolygonShape2D::_update_shape() { - Physics2DServer::get_singleton()->shape_set_data(get_rid(), points); + Vector<Vector2> final_points = points; + if (Geometry::is_polygon_clockwise(final_points)) { //needs to be counter clockwise + final_points.invert(); + } + Physics2DServer::get_singleton()->shape_set_data(get_rid(), final_points); emit_changed(); } @@ -55,6 +59,7 @@ void ConvexPolygonShape2D::set_point_cloud(const Vector<Vector2> &p_points) { void ConvexPolygonShape2D::set_points(const Vector<Vector2> &p_points) { points = p_points; + _update_shape(); } diff --git a/scene/resources/default_theme/SCsub b/scene/resources/default_theme/SCsub index bf9125be7f..b01e2fd54d 100644 --- a/scene/resources/default_theme/SCsub +++ b/scene/resources/default_theme/SCsub @@ -3,5 +3,3 @@ Import('env') env.add_source_files(env.scene_sources, "*.cpp") - -Export('env') diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 20fa1d6e2b..fff136cdc3 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -120,41 +120,7 @@ static Ref<Texture> make_icon(T p_src) { return texture; } -static Ref<Shader> make_shader(const char *vertex_code, const char *fragment_code, const char *lighting_code) { - Ref<Shader> shader = (memnew(Shader())); - //shader->set_code(vertex_code, fragment_code, lighting_code); - - return shader; -} - -static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_valign, int p_charcount, const int *p_chars, const Ref<Texture> &p_texture) { - - Ref<BitmapFont> font(memnew(BitmapFont)); - font->add_texture(p_texture); - - for (int i = 0; i < p_charcount; i++) { - - const int *c = &p_chars[i * 8]; - - int chr = c[0]; - Rect2 frect; - frect.position.x = c[1]; - frect.position.y = c[2]; - frect.size.x = c[3]; - frect.size.y = c[4]; - Point2 align(c[5], c[6] + p_valign); - int advance = c[7]; - - font->add_char(chr, 0, frect, align, advance); - } - - font->set_height(p_height); - font->set_ascent(p_ascent); - - return font; -} - -static Ref<BitmapFont> make_font2(int p_height, int p_ascent, int p_charcount, const int *p_char_rects, int p_kerning_count, const int *p_kernings, int p_w, int p_h, const unsigned char *p_img) { +static Ref<BitmapFont> make_font(int p_height, int p_ascent, int p_charcount, const int *p_char_rects, int p_kerning_count, const int *p_kernings, int p_w, int p_h, const unsigned char *p_img) { Ref<BitmapFont> font(memnew(BitmapFont)); @@ -209,8 +175,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const tex_cache = memnew(TexCacheMap); - //Ref<BitmapFont> default_font = make_font(_bi_font_normal_height,_bi_font_normal_ascent,_bi_font_normal_valign,_bi_font_normal_charcount,_bi_font_normal_characters,make_icon(font_normal_png)); - // Font Colors Color control_font_color = Color::html("e0e0e0"); @@ -364,6 +328,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("pressed", "CheckBox", cbx_empty); theme->set_stylebox("disabled", "CheckBox", cbx_empty); theme->set_stylebox("hover", "CheckBox", cbx_empty); + theme->set_stylebox("hover_pressed", "CheckBox", cbx_empty); theme->set_stylebox("focus", "CheckBox", cbx_focus); theme->set_icon("checked", "CheckBox", make_icon(checked_png)); @@ -376,6 +341,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_color("font_color", "CheckBox", control_font_color); theme->set_color("font_color_pressed", "CheckBox", control_font_color_pressed); theme->set_color("font_color_hover", "CheckBox", control_font_color_hover); + theme->set_color("font_color_hover_pressed", "CheckBox", control_font_color_pressed); theme->set_color("font_color_disabled", "CheckBox", control_font_color_disabled); theme->set_constant("hseparation", "CheckBox", 4 * scale); @@ -393,6 +359,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_stylebox("pressed", "CheckButton", cb_empty); theme->set_stylebox("disabled", "CheckButton", cb_empty); theme->set_stylebox("hover", "CheckButton", cb_empty); + theme->set_stylebox("hover_pressed", "CheckButton", cb_empty); theme->set_stylebox("focus", "CheckButton", focus); theme->set_icon("on", "CheckButton", make_icon(toggle_on_png)); @@ -403,6 +370,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_color("font_color", "CheckButton", control_font_color); theme->set_color("font_color_pressed", "CheckButton", control_font_color_pressed); theme->set_color("font_color_hover", "CheckButton", control_font_color_hover); + theme->set_color("font_color_hover_pressed", "CheckButton", control_font_color_pressed); theme->set_color("font_color_disabled", "CheckButton", control_font_color_disabled); theme->set_constant("hseparation", "CheckButton", 4 * scale); @@ -685,6 +653,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const theme->set_constant("item_margin", "Tree", 12 * scale); theme->set_constant("button_margin", "Tree", 4 * scale); theme->set_constant("draw_relationship_lines", "Tree", 0); + theme->set_constant("draw_guides", "Tree", 1); theme->set_constant("scroll_border", "Tree", 4); theme->set_constant("scroll_speed", "Tree", 12); @@ -909,9 +878,9 @@ void make_default_theme(bool p_hidpi, Ref<Font> p_font) { if (p_font.is_valid()) { default_font = p_font; } else if (p_hidpi) { - default_font = make_font2(_hidpi_font_height, _hidpi_font_ascent, _hidpi_font_charcount, &_hidpi_font_charrects[0][0], _hidpi_font_kerning_pair_count, &_hidpi_font_kerning_pairs[0][0], _hidpi_font_img_width, _hidpi_font_img_height, _hidpi_font_img_data); + default_font = make_font(_hidpi_font_height, _hidpi_font_ascent, _hidpi_font_charcount, &_hidpi_font_charrects[0][0], _hidpi_font_kerning_pair_count, &_hidpi_font_kerning_pairs[0][0], _hidpi_font_img_width, _hidpi_font_img_height, _hidpi_font_img_data); } else { - default_font = make_font2(_lodpi_font_height, _lodpi_font_ascent, _lodpi_font_charcount, &_lodpi_font_charrects[0][0], _lodpi_font_kerning_pair_count, &_lodpi_font_kerning_pairs[0][0], _lodpi_font_img_width, _lodpi_font_img_height, _lodpi_font_img_data); + default_font = make_font(_lodpi_font_height, _lodpi_font_ascent, _lodpi_font_charcount, &_lodpi_font_charrects[0][0], _lodpi_font_kerning_pair_count, &_lodpi_font_kerning_pairs[0][0], _lodpi_font_img_width, _lodpi_font_img_height, _lodpi_font_img_data); } Ref<Font> large_font = default_font; fill_default_theme(t, default_font, large_font, default_icon, default_style, p_hidpi ? 2.0 : 1.0); diff --git a/scene/resources/default_theme/error_icon.png b/scene/resources/default_theme/error_icon.png Binary files differindex 7741d00749..00680db5df 100644 --- a/scene/resources/default_theme/error_icon.png +++ b/scene/resources/default_theme/error_icon.png diff --git a/scene/resources/dynamic_font.cpp b/scene/resources/dynamic_font.cpp index 0785d3bfc6..ad22d6530c 100644 --- a/scene/resources/dynamic_font.cpp +++ b/scene/resources/dynamic_font.cpp @@ -82,11 +82,14 @@ void DynamicFontData::set_force_autohinter(bool p_force) { } void DynamicFontData::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &DynamicFontData::set_antialiased); + ClassDB::bind_method(D_METHOD("is_antialiased"), &DynamicFontData::is_antialiased); ClassDB::bind_method(D_METHOD("set_font_path", "path"), &DynamicFontData::set_font_path); ClassDB::bind_method(D_METHOD("get_font_path"), &DynamicFontData::get_font_path); ClassDB::bind_method(D_METHOD("set_hinting", "mode"), &DynamicFontData::set_hinting); ClassDB::bind_method(D_METHOD("get_hinting"), &DynamicFontData::get_hinting); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "is_antialiased"); ADD_PROPERTY(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), "set_hinting", "get_hinting"); BIND_ENUM_CONSTANT(HINTING_NONE); @@ -98,6 +101,7 @@ void DynamicFontData::_bind_methods() { DynamicFontData::DynamicFontData() { + antialiased = true; force_autohinter = false; hinting = DynamicFontData::HINTING_NORMAL; font_mem = NULL; @@ -201,10 +205,10 @@ Error DynamicFontAtSize::_load() { if (FT_HAS_COLOR(face)) { int best_match = 0; - int diff = ABS(id.size - face->available_sizes[0].width); + int diff = ABS(id.size - ((int64_t)face->available_sizes[0].width)); scale_color_font = float(id.size) / face->available_sizes[0].width; for (int i = 1; i < face->num_fixed_sizes; i++) { - int ndiff = ABS(id.size - face->available_sizes[i].width); + int ndiff = ABS(id.size - ((int64_t)face->available_sizes[i].width)); if (ndiff < diff) { best_match = i; diff = ndiff; @@ -632,7 +636,7 @@ void DynamicFontAtSize::_update_char(CharType p_char) { if (id.outline_size > 0) { character = _make_outline_char(p_char); } else { - error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL); + error = FT_Render_Glyph(face->glyph, font->antialiased ? FT_RENDER_MODE_NORMAL : FT_RENDER_MODE_MONO); if (!error) character = _bitmap_to_character(slot->bitmap, slot->bitmap_top, slot->bitmap_left, slot->advance.x / 64.0); } @@ -785,6 +789,18 @@ void DynamicFont::set_use_filter(bool p_enable) { _reload_cache(); } +bool DynamicFontData::is_antialiased() const { + + return antialiased; +} + +void DynamicFontData::set_antialiased(bool p_antialiased) { + + if (antialiased == p_antialiased) + return; + antialiased = p_antialiased; +} + DynamicFontData::Hinting DynamicFontData::get_hinting() const { return hinting; @@ -1014,10 +1030,10 @@ void DynamicFont::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_mipmaps"), "set_use_mipmaps", "get_use_mipmaps"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_filter"), "set_use_filter", "get_use_filter"); ADD_GROUP("Extra Spacing", "extra_spacing"); - ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "extra_spacing_top"), "set_spacing", "get_spacing", SPACING_TOP); - ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "extra_spacing_bottom"), "set_spacing", "get_spacing", SPACING_BOTTOM); - ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "extra_spacing_char"), "set_spacing", "get_spacing", SPACING_CHAR); - ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "extra_spacing_space"), "set_spacing", "get_spacing", SPACING_SPACE); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "extra_spacing_top"), "set_spacing", "get_spacing", SPACING_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "extra_spacing_bottom"), "set_spacing", "get_spacing", SPACING_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "extra_spacing_char"), "set_spacing", "get_spacing", SPACING_CHAR); + ADD_PROPERTYI(PropertyInfo(Variant::INT, "extra_spacing_space"), "set_spacing", "get_spacing", SPACING_SPACE); ADD_GROUP("Font", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "font_data", PROPERTY_HINT_RESOURCE_TYPE, "DynamicFontData"), "set_font_data", "get_font_data"); @@ -1029,7 +1045,7 @@ void DynamicFont::_bind_methods() { Mutex *DynamicFont::dynamic_font_mutex = NULL; -SelfList<DynamicFont>::List DynamicFont::dynamic_fonts; +SelfList<DynamicFont>::List *DynamicFont::dynamic_fonts = NULL; DynamicFont::DynamicFont() : font_list(this) { @@ -1041,29 +1057,31 @@ DynamicFont::DynamicFont() : spacing_char = 0; spacing_space = 0; outline_color = Color(1, 1, 1); - if (dynamic_font_mutex) + if (dynamic_font_mutex) { dynamic_font_mutex->lock(); - dynamic_fonts.add(&font_list); - if (dynamic_font_mutex) + dynamic_fonts->add(&font_list); dynamic_font_mutex->unlock(); + } } DynamicFont::~DynamicFont() { - - if (dynamic_font_mutex) + if (dynamic_font_mutex) { dynamic_font_mutex->lock(); - dynamic_fonts.remove(&font_list); - if (dynamic_font_mutex) + dynamic_fonts->remove(&font_list); dynamic_font_mutex->unlock(); + } } void DynamicFont::initialize_dynamic_fonts() { + dynamic_fonts = memnew(SelfList<DynamicFont>::List()); dynamic_font_mutex = Mutex::create(); } void DynamicFont::finish_dynamic_fonts() { memdelete(dynamic_font_mutex); dynamic_font_mutex = NULL; + memdelete(dynamic_fonts); + dynamic_fonts = NULL; } void DynamicFont::update_oversampling() { @@ -1073,7 +1091,7 @@ void DynamicFont::update_oversampling() { if (dynamic_font_mutex) dynamic_font_mutex->lock(); - SelfList<DynamicFont> *E = dynamic_fonts.first(); + SelfList<DynamicFont> *E = dynamic_fonts->first(); while (E) { if (E->self()->data_at_size.is_valid()) { @@ -1083,8 +1101,19 @@ void DynamicFont::update_oversampling() { E->self()->outline_data_at_size->update_oversampling(); } + for (int i = 0; i < E->self()->fallback_data_at_size.size(); i++) { + if (E->self()->fallback_data_at_size[i].is_valid()) { + E->self()->fallback_data_at_size.write[i]->update_oversampling(); + + if (E->self()->has_outline() && E->self()->fallback_outline_data_at_size[i].is_valid()) { + E->self()->fallback_outline_data_at_size.write[i]->update_oversampling(); + } + } + } + changed.push_back(Ref<DynamicFont>(E->self())); } + E = E->next(); } diff --git a/scene/resources/dynamic_font.h b/scene/resources/dynamic_font.h index afda48a566..96437e8982 100644 --- a/scene/resources/dynamic_font.h +++ b/scene/resources/dynamic_font.h @@ -71,12 +71,15 @@ public: HINTING_NORMAL }; + bool is_antialiased() const; + void set_antialiased(bool p_antialiased); Hinting get_hinting() const; void set_hinting(Hinting p_hinting); private: const uint8_t *font_mem; int font_mem_size; + bool antialiased; bool force_autohinter; Hinting hinting; @@ -285,7 +288,7 @@ public: SelfList<DynamicFont> font_list; static Mutex *dynamic_font_mutex; - static SelfList<DynamicFont>::List dynamic_fonts; + static SelfList<DynamicFont>::List *dynamic_fonts; static void initialize_dynamic_fonts(); static void finish_dynamic_fonts(); diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp index f4d5b8376b..90552ebb47 100644 --- a/scene/resources/environment.cpp +++ b/scene/resources/environment.cpp @@ -504,7 +504,7 @@ float Environment::get_ssao_edge_sharpness() const { void Environment::set_glow_enabled(bool p_enabled) { glow_enabled = p_enabled; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); _change_notify(); } @@ -522,7 +522,7 @@ void Environment::set_glow_level(int p_level, bool p_enabled) { else glow_levels &= ~(1 << p_level); - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); } bool Environment::is_glow_level_enabled(int p_level) const { @@ -535,7 +535,7 @@ void Environment::set_glow_intensity(float p_intensity) { glow_intensity = p_intensity; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); } float Environment::get_glow_intensity() const { @@ -545,7 +545,7 @@ float Environment::get_glow_intensity() const { void Environment::set_glow_strength(float p_strength) { glow_strength = p_strength; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); } float Environment::get_glow_strength() const { @@ -556,7 +556,7 @@ void Environment::set_glow_bloom(float p_threshold) { glow_bloom = p_threshold; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); } float Environment::get_glow_bloom() const { @@ -567,7 +567,7 @@ void Environment::set_glow_blend_mode(GlowBlendMode p_mode) { glow_blend_mode = p_mode; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); } Environment::GlowBlendMode Environment::get_glow_blend_mode() const { @@ -578,18 +578,29 @@ void Environment::set_glow_hdr_bleed_threshold(float p_threshold) { glow_hdr_bleed_threshold = p_threshold; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); } float Environment::get_glow_hdr_bleed_threshold() const { return glow_hdr_bleed_threshold; } +void Environment::set_glow_hdr_luminance_cap(float p_amount) { + + glow_hdr_luminance_cap = p_amount; + + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); +} +float Environment::get_glow_hdr_luminance_cap() const { + + return glow_hdr_luminance_cap; +} + void Environment::set_glow_hdr_bleed_scale(float p_scale) { glow_hdr_bleed_scale = p_scale; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); } float Environment::get_glow_hdr_bleed_scale() const { @@ -599,7 +610,7 @@ float Environment::get_glow_hdr_bleed_scale() const { void Environment::set_glow_bicubic_upscale(bool p_enable) { glow_bicubic_upscale = p_enable; - VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_bicubic_upscale); + VS::get_singleton()->environment_set_glow(environment, glow_enabled, glow_levels, glow_intensity, glow_strength, glow_bloom, VS::EnvironmentGlowBlendMode(glow_blend_mode), glow_hdr_bleed_threshold, glow_hdr_bleed_threshold, glow_hdr_luminance_cap, glow_bicubic_upscale); } bool Environment::is_glow_bicubic_upscale_enabled() const { @@ -761,7 +772,7 @@ float Environment::get_fog_sun_amount() const { void Environment::set_fog_depth_enabled(bool p_enabled) { fog_depth_enabled = p_enabled; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } bool Environment::is_fog_depth_enabled() const { @@ -771,17 +782,28 @@ bool Environment::is_fog_depth_enabled() const { void Environment::set_fog_depth_begin(float p_distance) { fog_depth_begin = p_distance; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_depth_begin() const { return fog_depth_begin; } +void Environment::set_fog_depth_end(float p_distance) { + + fog_depth_end = p_distance; + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); +} + +float Environment::get_fog_depth_end() const { + + return fog_depth_end; +} + void Environment::set_fog_depth_curve(float p_curve) { fog_depth_curve = p_curve; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_depth_curve() const { @@ -791,7 +813,7 @@ float Environment::get_fog_depth_curve() const { void Environment::set_fog_transmit_enabled(bool p_enabled) { fog_transmit_enabled = p_enabled; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } bool Environment::is_fog_transmit_enabled() const { @@ -801,7 +823,7 @@ bool Environment::is_fog_transmit_enabled() const { void Environment::set_fog_transmit_curve(float p_curve) { fog_transmit_curve = p_curve; - VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); + VS::get_singleton()->environment_set_fog_depth(environment, fog_depth_enabled, fog_depth_begin, fog_depth_end, fog_depth_curve, fog_transmit_enabled, fog_transmit_curve); } float Environment::get_fog_transmit_curve() const { @@ -900,6 +922,9 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_fog_depth_begin", "distance"), &Environment::set_fog_depth_begin); ClassDB::bind_method(D_METHOD("get_fog_depth_begin"), &Environment::get_fog_depth_begin); + ClassDB::bind_method(D_METHOD("set_fog_depth_end", "distance"), &Environment::set_fog_depth_end); + ClassDB::bind_method(D_METHOD("get_fog_depth_end"), &Environment::get_fog_depth_end); + ClassDB::bind_method(D_METHOD("set_fog_depth_curve", "curve"), &Environment::set_fog_depth_curve); ClassDB::bind_method(D_METHOD("get_fog_depth_curve"), &Environment::get_fog_depth_curve); @@ -928,6 +953,7 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_sun_amount", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_fog_sun_amount", "get_fog_sun_amount"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fog_depth_enabled"), "set_fog_depth_enabled", "is_fog_depth_enabled"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_depth_begin", PROPERTY_HINT_RANGE, "0,4000,0.1"), "set_fog_depth_begin", "get_fog_depth_begin"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_depth_end", PROPERTY_HINT_RANGE, "0,4000,0.1,or_greater"), "set_fog_depth_end", "get_fog_depth_end"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_depth_curve", PROPERTY_HINT_EXP_EASING), "set_fog_depth_curve", "get_fog_depth_curve"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fog_transmit_enabled"), "set_fog_transmit_enabled", "is_fog_transmit_enabled"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "fog_transmit_curve", PROPERTY_HINT_EXP_EASING), "set_fog_transmit_curve", "get_fog_transmit_curve"); @@ -961,7 +987,7 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("get_tonemap_auto_exposure_grey"), &Environment::get_tonemap_auto_exposure_grey); ADD_GROUP("Tonemap", "tonemap_"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "tonemap_mode", PROPERTY_HINT_ENUM, "Linear,Reindhart,Filmic,Aces"), "set_tonemapper", "get_tonemapper"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "tonemap_mode", PROPERTY_HINT_ENUM, "Linear,Reinhard,Filmic,Aces"), "set_tonemapper", "get_tonemapper"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "tonemap_exposure", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_exposure", "get_tonemap_exposure"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "tonemap_white", PROPERTY_HINT_RANGE, "0,16,0.01"), "set_tonemap_white", "get_tonemap_white"); ADD_GROUP("Auto Exposure", "auto_exposure_"); @@ -1112,6 +1138,9 @@ void Environment::_bind_methods() { ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_threshold", "threshold"), &Environment::set_glow_hdr_bleed_threshold); ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_threshold"), &Environment::get_glow_hdr_bleed_threshold); + ClassDB::bind_method(D_METHOD("set_glow_hdr_luminance_cap", "amount"), &Environment::set_glow_hdr_luminance_cap); + ClassDB::bind_method(D_METHOD("get_glow_hdr_luminance_cap"), &Environment::get_glow_hdr_luminance_cap); + ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_scale", "scale"), &Environment::set_glow_hdr_bleed_scale); ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_scale"), &Environment::get_glow_hdr_bleed_scale); @@ -1133,6 +1162,7 @@ void Environment::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_bloom", PROPERTY_HINT_RANGE, "0.0,1.0,0.01"), "set_glow_bloom", "get_glow_bloom"); ADD_PROPERTY(PropertyInfo(Variant::INT, "glow_blend_mode", PROPERTY_HINT_ENUM, "Additive,Screen,Softlight,Replace"), "set_glow_blend_mode", "get_glow_blend_mode"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_hdr_threshold", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_threshold", "get_glow_hdr_bleed_threshold"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_hdr_luminance_cap", PROPERTY_HINT_RANGE, "0.0,256.0,0.01"), "set_glow_hdr_luminance_cap", "get_glow_hdr_luminance_cap"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_hdr_scale", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_scale", "get_glow_hdr_bleed_scale"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "glow_bicubic_upscale"), "set_glow_bicubic_upscale", "is_glow_bicubic_upscale_enabled"); @@ -1246,6 +1276,7 @@ Environment::Environment() { glow_bloom = 0.0; glow_blend_mode = GLOW_BLEND_MODE_SOFTLIGHT; glow_hdr_bleed_threshold = 1.0; + glow_hdr_luminance_cap = 12.0; glow_hdr_bleed_scale = 2.0; glow_bicubic_upscale = false; @@ -1269,6 +1300,7 @@ Environment::Environment() { fog_depth_enabled = true; fog_depth_begin = 10; + fog_depth_end = 0; fog_depth_curve = 1; fog_transmit_enabled = false; diff --git a/scene/resources/environment.h b/scene/resources/environment.h index aab37719e0..55d96bc5bd 100644 --- a/scene/resources/environment.h +++ b/scene/resources/environment.h @@ -141,6 +141,7 @@ private: GlowBlendMode glow_blend_mode; float glow_hdr_bleed_threshold; float glow_hdr_bleed_scale; + float glow_hdr_luminance_cap; bool glow_bicubic_upscale; bool dof_blur_far_enabled; @@ -162,6 +163,7 @@ private: bool fog_depth_enabled; float fog_depth_begin; + float fog_depth_end; float fog_depth_curve; bool fog_transmit_enabled; @@ -311,6 +313,9 @@ public: void set_glow_hdr_bleed_threshold(float p_threshold); float get_glow_hdr_bleed_threshold() const; + void set_glow_hdr_luminance_cap(float p_amount); + float get_glow_hdr_luminance_cap() const; + void set_glow_hdr_bleed_scale(float p_scale); float get_glow_hdr_bleed_scale() const; @@ -365,6 +370,9 @@ public: void set_fog_depth_begin(float p_distance); float get_fog_depth_begin() const; + void set_fog_depth_end(float p_distance); + float get_fog_depth_end() const; + void set_fog_depth_curve(float p_curve); float get_fog_depth_curve() const; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index ce801c8763..5327ed318f 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -299,6 +299,7 @@ void SpatialMaterial::init_shaders() { shader_names->particles_anim_loop = "particles_anim_loop"; shader_names->depth_min_layers = "depth_min_layers"; shader_names->depth_max_layers = "depth_max_layers"; + shader_names->depth_flip = "depth_flip"; shader_names->grow = "grow"; @@ -532,6 +533,7 @@ void SpatialMaterial::_update_shader() { code += "uniform float depth_scale;\n"; code += "uniform int depth_min_layers;\n"; code += "uniform int depth_max_layers;\n"; + code += "uniform vec2 depth_flip;\n"; } if (flags[FLAG_UV1_USE_TRIPLANAR]) { code += "varying vec3 uv1_triplanar_pos;\n"; @@ -610,11 +612,11 @@ void SpatialMaterial::_update_shader() { code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat_world;\n"; //handle animation - code += "\tint particle_total_frames = particles_anim_h_frames * particles_anim_v_frames;\n"; - code += "\tint particle_frame = int(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; - code += "\tif (particles_anim_loop) particle_frame=clamp(particle_frame,0,particle_total_frames-1); else particle_frame=abs(particle_frame)%particle_total_frames;\n"; + code += "\tfloat particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n"; + code += "\tfloat particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; + code += "\tif (!particles_anim_loop) particle_frame=clamp(particle_frame,0.0,particle_total_frames-1.0); else particle_frame=mod(particle_frame,float(particle_total_frames));\n"; code += "\tUV /= vec2(float(particles_anim_h_frames),float(particles_anim_v_frames));\n"; - code += "\tUV += vec2(float(particle_frame % particles_anim_h_frames) / float(particles_anim_h_frames),float(particle_frame / particles_anim_h_frames) / float(particles_anim_v_frames));\n"; + code += "\tUV += vec2(mod(particle_frame,float(particles_anim_h_frames)) / float(particles_anim_h_frames), floor(particle_frame / float(particles_anim_h_frames)) / float(particles_anim_v_frames));\n"; } break; } @@ -697,7 +699,7 @@ void SpatialMaterial::_update_shader() { if (features[FEATURE_DEPTH_MAPPING] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //depthmap not supported with triplanar code += "\t{\n"; - code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT,-BINORMAL,NORMAL));\n"; //binormal is negative due to mikktpsace + code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*depth_flip.x,BINORMAL*depth_flip.y,NORMAL));\n"; // binormal is negative due to mikktspace if (deep_parallax) { code += "\t\tfloat num_layers = mix(float(depth_max_layers),float(depth_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n"; @@ -817,7 +819,7 @@ void SpatialMaterial::_update_shader() { code += "\tALPHA = albedo.a * albedo_tex.a;\n"; } - if (proximity_fade_enabled) { + if (!VisualServer::get_singleton()->is_low_end() && proximity_fade_enabled) { code += "\tfloat depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;\n"; code += "\tvec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);\n"; code += "\tworld_pos.xyz/=world_pos.w;\n"; @@ -825,43 +827,45 @@ void SpatialMaterial::_update_shader() { } if (distance_fade != DISTANCE_FADE_DISABLED) { - if (distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER) { - - code += "\t{\n"; - if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) { - code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n"; - - } else { - code += "\t\tfloat fade_distance=-VERTEX.z;\n"; + if ((distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER)) { + + if (!VisualServer::get_singleton()->is_low_end()) { + code += "\t{\n"; + if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) { + code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n"; + + } else { + code += "\t\tfloat fade_distance=-VERTEX.z;\n"; + } + + code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n"; + code += "\t\tint x = int(FRAGCOORD.x) % 4;\n"; + code += "\t\tint y = int(FRAGCOORD.y) % 4;\n"; + code += "\t\tint index = x + y * 4;\n"; + code += "\t\tfloat limit = 0.0;\n\n"; + code += "\t\tif (x < 8) {\n"; + code += "\t\t\tif (index == 0) limit = 0.0625;\n"; + code += "\t\t\tif (index == 1) limit = 0.5625;\n"; + code += "\t\t\tif (index == 2) limit = 0.1875;\n"; + code += "\t\t\tif (index == 3) limit = 0.6875;\n"; + code += "\t\t\tif (index == 4) limit = 0.8125;\n"; + code += "\t\t\tif (index == 5) limit = 0.3125;\n"; + code += "\t\t\tif (index == 6) limit = 0.9375;\n"; + code += "\t\t\tif (index == 7) limit = 0.4375;\n"; + code += "\t\t\tif (index == 8) limit = 0.25;\n"; + code += "\t\t\tif (index == 9) limit = 0.75;\n"; + code += "\t\t\tif (index == 10) limit = 0.125;\n"; + code += "\t\t\tif (index == 11) limit = 0.625;\n"; + code += "\t\t\tif (index == 12) limit = 1.0;\n"; + code += "\t\t\tif (index == 13) limit = 0.5;\n"; + code += "\t\t\tif (index == 14) limit = 0.875;\n"; + code += "\t\t\tif (index == 15) limit = 0.375;\n"; + code += "\t\t}\n\n"; + code += "\tif (fade < limit)\n"; + code += "\t\tdiscard;\n"; + code += "\t}\n\n"; } - code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n"; - code += "\t\tint x = int(FRAGCOORD.x) % 4;\n"; - code += "\t\tint y = int(FRAGCOORD.y) % 4;\n"; - code += "\t\tint index = x + y * 4;\n"; - code += "\t\tfloat limit = 0.0;\n\n"; - code += "\t\tif (x < 8) {\n"; - code += "\t\t\tif (index == 0) limit = 0.0625;\n"; - code += "\t\t\tif (index == 1) limit = 0.5625;\n"; - code += "\t\t\tif (index == 2) limit = 0.1875;\n"; - code += "\t\t\tif (index == 3) limit = 0.6875;\n"; - code += "\t\t\tif (index == 4) limit = 0.8125;\n"; - code += "\t\t\tif (index == 5) limit = 0.3125;\n"; - code += "\t\t\tif (index == 6) limit = 0.9375;\n"; - code += "\t\t\tif (index == 7) limit = 0.4375;\n"; - code += "\t\t\tif (index == 8) limit = 0.25;\n"; - code += "\t\t\tif (index == 9) limit = 0.75;\n"; - code += "\t\t\tif (index == 10) limit = 0.125;\n"; - code += "\t\t\tif (index == 11) limit = 0.625;\n"; - code += "\t\t\tif (index == 12) limit = 1.0;\n"; - code += "\t\t\tif (index == 13) limit = 0.5;\n"; - code += "\t\t\tif (index == 14) limit = 0.875;\n"; - code += "\t\t\tif (index == 15) limit = 0.375;\n"; - code += "\t\t}\n\n"; - code += "\tif (fade < limit)\n"; - code += "\t\tdiscard;\n"; - code += "\t}\n\n"; - } else { code += "\tALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n"; } @@ -1369,6 +1373,12 @@ void SpatialMaterial::_validate_feature(const String &text, Feature feature, Pro } } +void SpatialMaterial::_validate_high_end(const String &text, PropertyInfo &property) const { + if (property.name.begins_with(text)) { + property.usage |= PROPERTY_USAGE_HIGH_END_GFX; + } +} + void SpatialMaterial::_validate_property(PropertyInfo &property) const { _validate_feature("normal", FEATURE_NORMAL_MAPPING, property); _validate_feature("emission", FEATURE_EMISSION, property); @@ -1382,6 +1392,12 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const { _validate_feature("refraction", FEATURE_REFRACTION, property); _validate_feature("detail", FEATURE_DETAIL, property); + _validate_high_end("refraction", property); + _validate_high_end("subsurf_scatter", property); + _validate_high_end("anisotropy", property); + _validate_high_end("clearcoat", property); + _validate_high_end("depth", property); + if (property.name.begins_with("particles_anim_") && billboard_mode != BILLBOARD_PARTICLES) { property.usage = 0; } @@ -1527,13 +1543,13 @@ int SpatialMaterial::get_particles_anim_v_frames() const { return particles_anim_v_frames; } -void SpatialMaterial::set_particles_anim_loop(int p_frames) { +void SpatialMaterial::set_particles_anim_loop(bool p_loop) { - particles_anim_loop = p_frames; - VS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, p_frames); + particles_anim_loop = p_loop; + VS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, particles_anim_loop); } -int SpatialMaterial::get_particles_anim_loop() const { +bool SpatialMaterial::get_particles_anim_loop() const { return particles_anim_loop; } @@ -1570,6 +1586,28 @@ int SpatialMaterial::get_depth_deep_parallax_max_layers() const { return deep_parallax_max_layers; } +void SpatialMaterial::set_depth_deep_parallax_flip_tangent(bool p_flip) { + + depth_parallax_flip_tangent = p_flip; + VS::get_singleton()->material_set_param(_get_material(), shader_names->depth_flip, Vector2(depth_parallax_flip_tangent ? -1 : 1, depth_parallax_flip_binormal ? -1 : 1)); +} + +bool SpatialMaterial::get_depth_deep_parallax_flip_tangent() const { + + return depth_parallax_flip_tangent; +} + +void SpatialMaterial::set_depth_deep_parallax_flip_binormal(bool p_flip) { + + depth_parallax_flip_binormal = p_flip; + VS::get_singleton()->material_set_param(_get_material(), shader_names->depth_flip, Vector2(depth_parallax_flip_tangent ? -1 : 1, depth_parallax_flip_binormal ? -1 : 1)); +} + +bool SpatialMaterial::get_depth_deep_parallax_flip_binormal() const { + + return depth_parallax_flip_binormal; +} + void SpatialMaterial::set_grow_enabled(bool p_enable) { grow_enabled = p_enable; _queue_shader_change(); @@ -1884,7 +1922,7 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_particles_anim_v_frames", "frames"), &SpatialMaterial::set_particles_anim_v_frames); ClassDB::bind_method(D_METHOD("get_particles_anim_v_frames"), &SpatialMaterial::get_particles_anim_v_frames); - ClassDB::bind_method(D_METHOD("set_particles_anim_loop", "frames"), &SpatialMaterial::set_particles_anim_loop); + ClassDB::bind_method(D_METHOD("set_particles_anim_loop", "loop"), &SpatialMaterial::set_particles_anim_loop); ClassDB::bind_method(D_METHOD("get_particles_anim_loop"), &SpatialMaterial::get_particles_anim_loop); ClassDB::bind_method(D_METHOD("set_depth_deep_parallax", "enable"), &SpatialMaterial::set_depth_deep_parallax); @@ -1896,6 +1934,12 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_depth_deep_parallax_max_layers", "layer"), &SpatialMaterial::set_depth_deep_parallax_max_layers); ClassDB::bind_method(D_METHOD("get_depth_deep_parallax_max_layers"), &SpatialMaterial::get_depth_deep_parallax_max_layers); + ClassDB::bind_method(D_METHOD("set_depth_deep_parallax_flip_tangent", "flip"), &SpatialMaterial::set_depth_deep_parallax_flip_tangent); + ClassDB::bind_method(D_METHOD("get_depth_deep_parallax_flip_tangent"), &SpatialMaterial::get_depth_deep_parallax_flip_tangent); + + ClassDB::bind_method(D_METHOD("set_depth_deep_parallax_flip_binormal", "flip"), &SpatialMaterial::set_depth_deep_parallax_flip_binormal); + ClassDB::bind_method(D_METHOD("get_depth_deep_parallax_flip_binormal"), &SpatialMaterial::get_depth_deep_parallax_flip_binormal); + ClassDB::bind_method(D_METHOD("set_grow", "amount"), &SpatialMaterial::set_grow); ClassDB::bind_method(D_METHOD("get_grow"), &SpatialMaterial::get_grow); @@ -2031,6 +2075,8 @@ void SpatialMaterial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "depth_deep_parallax"), "set_depth_deep_parallax", "is_depth_deep_parallax_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "depth_min_layers", PROPERTY_HINT_RANGE, "1,32,1"), "set_depth_deep_parallax_min_layers", "get_depth_deep_parallax_min_layers"); ADD_PROPERTY(PropertyInfo(Variant::INT, "depth_max_layers", PROPERTY_HINT_RANGE, "1,32,1"), "set_depth_deep_parallax_max_layers", "get_depth_deep_parallax_max_layers"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "depth_flip_tangent"), "set_depth_deep_parallax_flip_tangent", "get_depth_deep_parallax_flip_tangent"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "depth_flip_binormal"), "set_depth_deep_parallax_flip_binormal", "get_depth_deep_parallax_flip_binormal"); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "depth_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_DEPTH); ADD_GROUP("Subsurf Scatter", "subsurf_scatter_"); @@ -2230,8 +2276,11 @@ SpatialMaterial::SpatialMaterial() : set_grow(0.0); deep_parallax = false; + depth_parallax_flip_tangent = false; + depth_parallax_flip_binormal = false; set_depth_deep_parallax_min_layers(8); set_depth_deep_parallax_max_layers(32); + set_depth_deep_parallax_flip_tangent(false); //also sets binormal detail_uv = DETAIL_UV_1; blend_mode = BLEND_MODE_MIX; diff --git a/scene/resources/material.h b/scene/resources/material.h index 4a2a813341..54fceaddc1 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -286,7 +286,7 @@ private: mk.key = 0; for (int i = 0; i < FEATURE_MAX; i++) { if (features[i]) { - mk.feature_mask |= (1 << i); + mk.feature_mask |= ((uint64_t)1 << i); } } mk.detail_uv = detail_uv; @@ -295,7 +295,7 @@ private: mk.cull_mode = cull_mode; for (int i = 0; i < FLAG_MAX; i++) { if (flags[i]) { - mk.flags |= (1 << i); + mk.flags |= ((uint64_t)1 << i); } } mk.detail_blend_mode = detail_blend_mode; @@ -338,6 +338,7 @@ private: StringName particles_anim_loop; StringName depth_min_layers; StringName depth_max_layers; + StringName depth_flip; StringName uv1_blend_sharpness; StringName uv2_blend_sharpness; StringName grow; @@ -407,6 +408,8 @@ private: bool deep_parallax; int deep_parallax_min_layers; int deep_parallax_max_layers; + bool depth_parallax_flip_tangent; + bool depth_parallax_flip_binormal; bool proximity_fade_enabled; float proximity_fade_distance; @@ -442,6 +445,8 @@ private: static Ref<SpatialMaterial> materials_for_2d[MAX_MATERIALS_FOR_2D]; //used by Sprite3D and other stuff + void _validate_high_end(const String &text, PropertyInfo &property) const; + protected: static void _bind_methods(); void _validate_property(PropertyInfo &property) const; @@ -499,6 +504,12 @@ public: void set_depth_deep_parallax_max_layers(int p_layer); int get_depth_deep_parallax_max_layers() const; + void set_depth_deep_parallax_flip_tangent(bool p_flip); + bool get_depth_deep_parallax_flip_tangent() const; + + void set_depth_deep_parallax_flip_binormal(bool p_flip); + bool get_depth_deep_parallax_flip_binormal() const; + void set_subsurface_scattering_strength(float p_subsurface_scattering_strength); float get_subsurface_scattering_strength() const; @@ -572,8 +583,8 @@ public: void set_particles_anim_v_frames(int p_frames); int get_particles_anim_v_frames() const; - void set_particles_anim_loop(int p_frames); - int get_particles_anim_loop() const; + void set_particles_anim_loop(bool p_loop); + bool get_particles_anim_loop() const; void set_grow_enabled(bool p_enable); bool is_grow_enabled() const; diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp index fa87623e38..80191367ce 100644 --- a/scene/resources/mesh.cpp +++ b/scene/resources/mesh.cpp @@ -482,7 +482,7 @@ void Mesh::_bind_methods() { ClassDB::bind_method(D_METHOD("set_lightmap_size_hint", "size"), &Mesh::set_lightmap_size_hint); ClassDB::bind_method(D_METHOD("get_lightmap_size_hint"), &Mesh::get_lightmap_size_hint); - ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "lightmap_size_hint"), "set_lightmap_size_hint", "get_lightmap_size_hint"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "lightmap_size_hint"), "set_lightmap_size_hint", "get_lightmap_size_hint"); ClassDB::bind_method(D_METHOD("get_surface_count"), &Mesh::get_surface_count); ClassDB::bind_method(D_METHOD("surface_get_arrays", "surf_idx"), &Mesh::surface_get_arrays); @@ -546,33 +546,6 @@ void Mesh::clear_cache() const { Mesh::Mesh() { } -static const ArrayMesh::ArrayType _array_types[] = { - - ArrayMesh::ARRAY_VERTEX, - ArrayMesh::ARRAY_NORMAL, - ArrayMesh::ARRAY_TANGENT, - ArrayMesh::ARRAY_COLOR, - ArrayMesh::ARRAY_TEX_UV, - ArrayMesh::ARRAY_TEX_UV2, - ArrayMesh::ARRAY_BONES, - ArrayMesh::ARRAY_WEIGHTS, - ArrayMesh::ARRAY_INDEX -}; - -/* compatibility */ -static const int _format_translate[] = { - - ArrayMesh::ARRAY_FORMAT_VERTEX, - ArrayMesh::ARRAY_FORMAT_NORMAL, - ArrayMesh::ARRAY_FORMAT_TANGENT, - ArrayMesh::ARRAY_FORMAT_COLOR, - ArrayMesh::ARRAY_FORMAT_TEX_UV, - ArrayMesh::ARRAY_FORMAT_TEX_UV2, - ArrayMesh::ARRAY_FORMAT_BONES, - ArrayMesh::ARRAY_FORMAT_WEIGHTS, - ArrayMesh::ARRAY_FORMAT_INDEX, -}; - bool ArrayMesh::_set(const StringName &p_name, const Variant &p_value) { String sname = p_name; @@ -733,6 +706,7 @@ bool ArrayMesh::_get(const StringName &p_name, Variant &r_ret) const { Vector<AABB> skel_aabb = VS::get_singleton()->mesh_surface_get_skeleton_aabb(mesh, idx); Array arr; + arr.resize(skel_aabb.size()); for (int i = 0; i < skel_aabb.size(); i++) { arr[i] = skel_aabb[i]; } diff --git a/scene/resources/mesh_data_tool.cpp b/scene/resources/mesh_data_tool.cpp index 6732303925..7af9086ab7 100644 --- a/scene/resources/mesh_data_tool.cpp +++ b/scene/resources/mesh_data_tool.cpp @@ -42,8 +42,6 @@ void MeshDataTool::clear() { Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surface) { ERR_FAIL_COND_V(p_mesh.is_null(), ERR_INVALID_PARAMETER); - - ERR_FAIL_COND_V(p_mesh.is_null(), ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_mesh->surface_get_primitive_type(p_surface) != Mesh::PRIMITIVE_TRIANGLES, ERR_INVALID_PARAMETER); Array arrays = p_mesh->surface_get_arrays(p_surface); @@ -79,9 +77,9 @@ Error MeshDataTool::create_from_surface(const Ref<ArrayMesh> &p_mesh, int p_surf if (arrays[Mesh::ARRAY_COLOR].get_type() != Variant::NIL) col = arrays[Mesh::ARRAY_COLOR].operator PoolVector<Color>().read(); - PoolVector<real_t>::Read bo; + PoolVector<int>::Read bo; if (arrays[Mesh::ARRAY_BONES].get_type() != Variant::NIL) - bo = arrays[Mesh::ARRAY_BONES].operator PoolVector<real_t>().read(); + bo = arrays[Mesh::ARRAY_BONES].operator PoolVector<int>().read(); PoolVector<real_t>::Read we; if (arrays[Mesh::ARRAY_WEIGHTS].get_type() != Variant::NIL) @@ -194,7 +192,7 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { PoolVector<Vector2> u; PoolVector<Vector2> u2; PoolVector<Color> c; - PoolVector<real_t> b; + PoolVector<int> b; PoolVector<real_t> w; PoolVector<int> in; @@ -233,7 +231,7 @@ Error MeshDataTool::commit_to_surface(const Ref<ArrayMesh> &p_mesh) { col = c.write(); } - PoolVector<real_t>::Write bo; + PoolVector<int>::Write bo; if (format & Mesh::ARRAY_FORMAT_BONES) { b.resize(vcount * 4); bo = b.write(); diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 086fb83af9..87483a7da4 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -264,7 +264,7 @@ Node *SceneState::instance(GenEditState p_edit_state) const { } if (n.instance >= 0 || n.type != TYPE_INSTANCED || i == 0) { - //if node was not part of instance, must set it's name, parenthood and ownership + //if node was not part of instance, must set its name, parenthood and ownership if (i > 0) { if (parent) { parent->_add_child_nocheck(node, snames[n.name]); @@ -472,6 +472,7 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map List<PropertyInfo> plist; p_node->get_property_list(&plist); + StringName type = p_node->get_class(); for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { @@ -482,12 +483,23 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map String name = E->get().name; Variant value = p_node->get(E->get().name); - bool isdefault = ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO) && value.is_zero()) || ((E->get().usage & PROPERTY_USAGE_STORE_IF_NONONE) && value.is_one()); + bool isdefault = false; + Variant default_value = ClassDB::class_get_default_property_value(type, name); - if (E->get().usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) { - isdefault = true; //is script default value + if (default_value.get_type() != Variant::NIL) { + isdefault = bool(Variant::evaluate(Variant::OP_EQUAL, value, default_value)); } + Ref<Script> script = p_node->get_script(); + if (!isdefault && script.is_valid() && script->get_property_default_value(name, default_value)) { + isdefault = bool(Variant::evaluate(Variant::OP_EQUAL, value, default_value)); + } + // the version above makes more sense, because it does not rely on placeholder or usage flag + // in the script, just the default value function. + // if (E->get().usage & PROPERTY_USAGE_SCRIPT_DEFAULT_VALUE) { + // isdefault = true; //is script default value + // } + if (pack_state_stack.size()) { // we are on part of an instanced subscene // or part of instanced scene. diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index 364ec9bb19..dae01e8d96 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -308,7 +308,7 @@ void ParticlesMaterial::_update_shader() { code += " float angle2_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad * (1.0 - flatness);\n"; code += " vec3 direction_xz = vec3(sin(angle1_rad), 0, cos(angle1_rad));\n"; code += " vec3 direction_yz = vec3(0, sin(angle2_rad), cos(angle2_rad));\n"; - code += " direction_yz.z = direction_yz.z / sqrt(direction_yz.z); // better uniform distribution\n"; + code += " direction_yz.z = direction_yz.z / max(0.0001,sqrt(abs(direction_yz.z))); // better uniform distribution\n"; code += " vec3 direction = vec3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);\n"; code += " direction = normalize(direction);\n"; code += " VELOCITY = direction * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);\n"; @@ -463,12 +463,6 @@ void ParticlesMaterial::_update_shader() { code += " base_angle += CUSTOM.y * LIFETIME * (angular_velocity + tex_angular_velocity) * mix(1.0, rand_from_seed(alt_seed) * 2.0 - 1.0, angular_velocity_random);\n"; code += " CUSTOM.x = base_angle * degree_to_rad;\n"; // angle code += " CUSTOM.z = (anim_offset + tex_anim_offset) * mix(1.0, anim_offset_rand, anim_offset_random) + CUSTOM.y * (anim_speed + tex_anim_speed) * mix(1.0, rand_from_seed(alt_seed), anim_speed_random);\n"; // angle - if (flags[FLAG_ANIM_LOOP]) { - code += " CUSTOM.z = mod(CUSTOM.z, 1.0);\n"; // loop - - } else { - code += " CUSTOM.z = clamp(CUSTOM.z, 0.0, 1.0);\n"; // 0 to 1 only - } code += " }\n"; // apply color // apply hue rotation @@ -691,6 +685,7 @@ void ParticlesMaterial::set_param(Parameter p_param, float p_value) { case PARAM_ANIM_OFFSET: { VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset, p_value); } break; + case PARAM_MAX: break; // Can't happen, but silences warning } } float ParticlesMaterial::get_param(Parameter p_param) const { @@ -743,6 +738,7 @@ void ParticlesMaterial::set_param_randomness(Parameter p_param, float p_value) { case PARAM_ANIM_OFFSET: { VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_random, p_value); } break; + case PARAM_MAX: break; // Can't happen, but silences warning } } float ParticlesMaterial::get_param_randomness(Parameter p_param) const { @@ -801,12 +797,7 @@ void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture> } break; case PARAM_SCALE: { VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_texture, p_texture); - - Ref<CurveTexture> curve_tex = p_texture; - if (curve_tex.is_valid()) { - curve_tex->ensure_default_setup(); - } - + _adjust_curve_range(p_texture, 0, 1); } break; case PARAM_HUE_VARIATION: { VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->hue_variation_texture, p_texture); @@ -819,6 +810,7 @@ void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture> case PARAM_ANIM_OFFSET: { VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_texture, p_texture); } break; + case PARAM_MAX: break; // Can't happen, but silences warning } _queue_shader_change(); @@ -1126,7 +1118,7 @@ void ParticlesMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL, "initial_velocity", PROPERTY_HINT_RANGE, "0,1000,0.01,or_lesser,or_greater"), "set_param", "get_param", PARAM_INITIAL_LINEAR_VELOCITY); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "initial_velocity_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_INITIAL_LINEAR_VELOCITY); ADD_GROUP("Angular Velocity", "angular_"); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_velocity", PROPERTY_HINT_RANGE, "-360,360,0.01"), "set_param", "get_param", PARAM_ANGULAR_VELOCITY); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_velocity", PROPERTY_HINT_RANGE, "-720,720,0.01,or_lesser,or_greater"), "set_param", "get_param", PARAM_ANGULAR_VELOCITY); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angular_velocity_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANGULAR_VELOCITY); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angular_velocity_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANGULAR_VELOCITY); ADD_GROUP("Orbit Velocity", "orbit_"); @@ -1162,7 +1154,7 @@ void ParticlesMaterial::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture"), "set_color_ramp", "get_color_ramp"); ADD_GROUP("Hue Variation", "hue_"); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "hue_variation", PROPERTY_HINT_RANGE, "-1,1,0.1"), "set_param", "get_param", PARAM_HUE_VARIATION); + ADD_PROPERTYI(PropertyInfo(Variant::REAL, "hue_variation", PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_param", "get_param", PARAM_HUE_VARIATION); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "hue_variation_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_HUE_VARIATION); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "hue_variation_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_HUE_VARIATION); ADD_GROUP("Animation", "anim_"); @@ -1172,7 +1164,6 @@ void ParticlesMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anim_offset", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_ANIM_OFFSET); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anim_offset_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANIM_OFFSET); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_offset_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANIM_OFFSET); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "anim_loop"), "set_flag", "get_flag", FLAG_ANIM_LOOP); BIND_ENUM_CONSTANT(PARAM_INITIAL_LINEAR_VELOCITY); BIND_ENUM_CONSTANT(PARAM_ANGULAR_VELOCITY); diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h index 91fdcc0346..06ebb3c4dc 100644 --- a/scene/resources/particles_material.h +++ b/scene/resources/particles_material.h @@ -60,7 +60,6 @@ public: FLAG_ALIGN_Y_TO_VELOCITY, FLAG_ROTATE_Y, FLAG_DISABLE_Z, - FLAG_ANIM_LOOP, FLAG_MAX }; diff --git a/scene/resources/primitive_meshes.cpp b/scene/resources/primitive_meshes.cpp index 63aa44e1d8..dafdddd990 100644 --- a/scene/resources/primitive_meshes.cpp +++ b/scene/resources/primitive_meshes.cpp @@ -102,6 +102,9 @@ void PrimitiveMesh::_request_update() { } int PrimitiveMesh::get_surface_count() const { + if (pending_request) { + _update(); + } return 1; } @@ -303,7 +306,7 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const { Vector3 p = Vector3(x * radius * w, y * radius * w, z); points.push_back(p + Vector3(0.0, 0.0, 0.5 * mid_height)); normals.push_back(p.normalized()); - ADD_TANGENT(y, -x, 0.0, -1.0) + ADD_TANGENT(-y, x, 0.0, -1.0) uvs.push_back(Vector2(u, v * onethird)); point++; @@ -342,7 +345,7 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const { Vector3 p = Vector3(x * radius, y * radius, z); points.push_back(p); normals.push_back(Vector3(x, y, 0.0)); - ADD_TANGENT(y, -x, 0.0, -1.0) + ADD_TANGENT(-y, x, 0.0, -1.0) uvs.push_back(Vector2(u, onethird + (v * onethird))); point++; @@ -382,7 +385,7 @@ void CapsuleMesh::_create_mesh_array(Array &p_arr) const { Vector3 p = Vector3(x * radius * w, y * radius * w, z); points.push_back(p + Vector3(0.0, 0.0, -0.5 * mid_height)); normals.push_back(p.normalized()); - ADD_TANGENT(y, -x, 0.0, -1.0) + ADD_TANGENT(-y, x, 0.0, -1.0) uvs.push_back(Vector2(u, twothirds + ((v - 1.0) * onethird))); point++; @@ -511,14 +514,14 @@ void CubeMesh::_create_mesh_array(Array &p_arr) const { // front points.push_back(Vector3(x, -y, -start_pos.z)); // double negative on the Z! normals.push_back(Vector3(0.0, 0.0, 1.0)); - ADD_TANGENT(-1.0, 0.0, 0.0, -1.0); + ADD_TANGENT(1.0, 0.0, 0.0, -1.0); uvs.push_back(Vector2(u, v)); point++; // back points.push_back(Vector3(-x, -y, start_pos.z)); normals.push_back(Vector3(0.0, 0.0, -1.0)); - ADD_TANGENT(1.0, 0.0, 0.0, -1.0); + ADD_TANGENT(-1.0, 0.0, 0.0, -1.0); uvs.push_back(Vector2(twothirds + u, v)); point++; @@ -565,14 +568,14 @@ void CubeMesh::_create_mesh_array(Array &p_arr) const { // right points.push_back(Vector3(-start_pos.x, -y, -z)); normals.push_back(Vector3(1.0, 0.0, 0.0)); - ADD_TANGENT(0.0, 0.0, 1.0, -1.0); + ADD_TANGENT(0.0, 0.0, -1.0, -1.0); uvs.push_back(Vector2(onethird + u, v)); point++; // left points.push_back(Vector3(start_pos.x, -y, z)); normals.push_back(Vector3(-1.0, 0.0, 0.0)); - ADD_TANGENT(0.0, 0.0, -1.0, -1.0); + ADD_TANGENT(0.0, 0.0, 1.0, -1.0); uvs.push_back(Vector2(u, 0.5 + v)); point++; @@ -619,14 +622,14 @@ void CubeMesh::_create_mesh_array(Array &p_arr) const { // top points.push_back(Vector3(-x, -start_pos.y, -z)); normals.push_back(Vector3(0.0, 1.0, 0.0)); - ADD_TANGENT(1.0, 0.0, 0.0, -1.0); + ADD_TANGENT(-1.0, 0.0, 0.0, -1.0); uvs.push_back(Vector2(onethird + u, 0.5 + v)); point++; // bottom points.push_back(Vector3(x, start_pos.y, -z)); normals.push_back(Vector3(0.0, -1.0, 0.0)); - ADD_TANGENT(-1.0, 0.0, 0.0, -1.0); + ADD_TANGENT(1.0, 0.0, 0.0, -1.0); uvs.push_back(Vector2(twothirds + u, 0.5 + v)); point++; @@ -770,7 +773,7 @@ void CylinderMesh::_create_mesh_array(Array &p_arr) const { Vector3 p = Vector3(x * radius, y, z * radius); points.push_back(p); normals.push_back(Vector3(x, 0.0, z)); - ADD_TANGENT(-z, 0.0, x, -1.0) + ADD_TANGENT(z, 0.0, -x, -1.0) uvs.push_back(Vector2(u, v * 0.5)); point++; @@ -796,7 +799,7 @@ void CylinderMesh::_create_mesh_array(Array &p_arr) const { thisrow = point; points.push_back(Vector3(0.0, y, 0.0)); normals.push_back(Vector3(0.0, 1.0, 0.0)); - ADD_TANGENT(1.0, 0.0, 0.0, 1.0) + ADD_TANGENT(1.0, 0.0, 0.0, -1.0) uvs.push_back(Vector2(0.25, 0.75)); point++; @@ -813,7 +816,7 @@ void CylinderMesh::_create_mesh_array(Array &p_arr) const { Vector3 p = Vector3(x * top_radius, y, z * top_radius); points.push_back(p); normals.push_back(Vector3(0.0, 1.0, 0.0)); - ADD_TANGENT(1.0, 0.0, 0.0, 1.0) + ADD_TANGENT(1.0, 0.0, 0.0, -1.0) uvs.push_back(Vector2(u, v)); point++; @@ -832,7 +835,7 @@ void CylinderMesh::_create_mesh_array(Array &p_arr) const { thisrow = point; points.push_back(Vector3(0.0, y, 0.0)); normals.push_back(Vector3(0.0, -1.0, 0.0)); - ADD_TANGENT(-1.0, 0.0, 0.0, -1.0) + ADD_TANGENT(1.0, 0.0, 0.0, -1.0) uvs.push_back(Vector2(0.75, 0.75)); point++; @@ -849,7 +852,7 @@ void CylinderMesh::_create_mesh_array(Array &p_arr) const { Vector3 p = Vector3(x * bottom_radius, y, z * bottom_radius); points.push_back(p); normals.push_back(Vector3(0.0, -1.0, 0.0)); - ADD_TANGENT(-1.0, 0.0, 0.0, -1.0) + ADD_TANGENT(1.0, 0.0, 0.0, -1.0) uvs.push_back(Vector2(u, v)); point++; @@ -980,7 +983,7 @@ void PlaneMesh::_create_mesh_array(Array &p_arr) const { points.push_back(Vector3(-x, 0.0, -z)); normals.push_back(Vector3(0.0, 1.0, 0.0)); ADD_TANGENT(1.0, 0.0, 0.0, -1.0); - uvs.push_back(Vector2(u, v)); + uvs.push_back(Vector2(1.0 - u, 1.0 - v)); /* 1.0 - uv to match orientation with Quad */ point++; if (i > 0 && j > 0) { @@ -1105,14 +1108,14 @@ void PrismMesh::_create_mesh_array(Array &p_arr) const { /* front */ points.push_back(Vector3(start_x + x, -y, -start_pos.z)); // double negative on the Z! normals.push_back(Vector3(0.0, 0.0, 1.0)); - ADD_TANGENT(-1.0, 0.0, 0.0, -1.0); + ADD_TANGENT(1.0, 0.0, 0.0, -1.0); uvs.push_back(Vector2(offset_front + u, v)); point++; /* back */ points.push_back(Vector3(start_x + scaled_size_x - x, -y, start_pos.z)); normals.push_back(Vector3(0.0, 0.0, -1.0)); - ADD_TANGENT(1.0, 0.0, 0.0, -1.0); + ADD_TANGENT(-1.0, 0.0, 0.0, -1.0); uvs.push_back(Vector2(twothirds + offset_back + u, v)); point++; @@ -1184,14 +1187,14 @@ void PrismMesh::_create_mesh_array(Array &p_arr) const { /* right */ points.push_back(Vector3(right, -y, -z)); normals.push_back(normal_right); - ADD_TANGENT(0.0, 0.0, 1.0, -1.0); + ADD_TANGENT(0.0, 0.0, -1.0, -1.0); uvs.push_back(Vector2(onethird + u, v)); point++; /* left */ points.push_back(Vector3(left, -y, z)); normals.push_back(normal_left); - ADD_TANGENT(0.0, 0.0, -1.0, -1.0); + ADD_TANGENT(0.0, 0.0, 1.0, -1.0); uvs.push_back(Vector2(u, 0.5 + v)); point++; @@ -1238,7 +1241,7 @@ void PrismMesh::_create_mesh_array(Array &p_arr) const { /* bottom */ points.push_back(Vector3(x, start_pos.y, -z)); normals.push_back(Vector3(0.0, -1.0, 0.0)); - ADD_TANGENT(-1.0, 0.0, 0.0, -1.0); + ADD_TANGENT(1.0, 0.0, 0.0, -1.0); uvs.push_back(Vector2(twothirds + u, 0.5 + v)); point++; @@ -1282,7 +1285,7 @@ void PrismMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_subdivide_depth"), &PrismMesh::get_subdivide_depth); ADD_PROPERTY(PropertyInfo(Variant::REAL, "left_to_right", PROPERTY_HINT_RANGE, "-2.0,2.0,0.1"), "set_left_to_right", "get_left_to_right"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_width", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_width", "get_subdivide_width"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_height", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_height", "get_subdivide_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "subdivide_depth", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_subdivide_depth", "get_subdivide_depth"); @@ -1379,7 +1382,7 @@ void QuadMesh::_create_mesh_array(Array &p_arr) const { tangents.set(i * 4 + 0, 1.0); tangents.set(i * 4 + 1, 0.0); tangents.set(i * 4 + 2, 0.0); - tangents.set(i * 4 + 3, 1.0); + tangents.set(i * 4 + 3, -1.0); static const Vector2 quad_uv[4] = { Vector2(0, 1), @@ -1465,7 +1468,7 @@ void SphereMesh::_create_mesh_array(Array &p_arr) const { points.push_back(p); normals.push_back(p.normalized()); }; - ADD_TANGENT(-z, 0.0, x, -1.0) + ADD_TANGENT(z, 0.0, -x, -1.0) uvs.push_back(Vector2(u, v)); point++; diff --git a/scene/resources/scene_format_text.cpp b/scene/resources/scene_format_text.cpp index 597ffe49ae..5ae843f2bd 100644 --- a/scene/resources/scene_format_text.cpp +++ b/scene/resources/scene_format_text.cpp @@ -626,14 +626,14 @@ Error ResourceInteractiveLoaderText::poll() { if (!packed_scene.is_valid()) return error; - error = OK; + error = ERR_FILE_EOF; //get it here resource = packed_scene; if (!ResourceCache::has(res_path)) { packed_scene->set_path(res_path); } - return ERR_FILE_EOF; + return error; } else { error_text += "Unknown tag in file: " + next_tag.name; @@ -1600,9 +1600,11 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r String name = PE->get().name; Variant value = res->get(name); + Variant default_value = ClassDB::class_get_default_property_value(res->get_class(), name); - if ((PE->get().usage & PROPERTY_USAGE_STORE_IF_NONZERO && value.is_zero()) || (PE->get().usage & PROPERTY_USAGE_STORE_IF_NONONE && value.is_one())) + if (default_value.get_type() != Variant::NIL && bool(Variant::evaluate(Variant::OP_EQUAL, value, default_value))) { continue; + } if (PE->get().type == Variant::OBJECT && value.is_zero() && !(PE->get().usage & PROPERTY_USAGE_STORE_IF_NULL)) continue; diff --git a/scene/resources/shape.cpp b/scene/resources/shape.cpp index 8ccca81acd..214e2e8edc 100644 --- a/scene/resources/shape.cpp +++ b/scene/resources/shape.cpp @@ -101,7 +101,7 @@ void Shape::_bind_methods() { ClassDB::bind_method(D_METHOD("set_margin", "margin"), &Shape::set_margin); ClassDB::bind_method(D_METHOD("get_margin"), &Shape::get_margin); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0.04,10,0.01"), "set_margin", "get_margin"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "margin", PROPERTY_HINT_RANGE, "0.001,10,0.001"), "set_margin", "get_margin"); } Shape::Shape() : diff --git a/scene/resources/sky_box.cpp b/scene/resources/sky_box.cpp index a6a52c7bba..347bca4400 100644 --- a/scene/resources/sky_box.cpp +++ b/scene/resources/sky_box.cpp @@ -190,9 +190,15 @@ Ref<Image> ProceduralSky::_generate_sky() { float c = (v_angle - (Math_PI * 0.5)) / (Math_PI * 0.5); color = ground_horizon_linear.linear_interpolate(ground_bottom_linear, Math::ease(c, ground_curve)); + color.r *= ground_energy; + color.g *= ground_energy; + color.b *= ground_energy; } else { float c = v_angle / (Math_PI * 0.5); color = sky_horizon_linear.linear_interpolate(sky_top_linear, Math::ease(1.0 - c, sky_curve)); + color.r *= sky_energy; + color.g *= sky_energy; + color.b *= sky_energy; float sun_angle = Math::rad2deg(Math::acos(CLAMP(sun.dot(normal), -1.0, 1.0))); diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp index fb81375b0a..087990c308 100644 --- a/scene/resources/style_box.cpp +++ b/scene/resources/style_box.cpp @@ -136,7 +136,7 @@ Ref<Texture> StyleBoxTexture::get_normal_map() const { void StyleBoxTexture::set_margin_size(Margin p_margin, float p_size) { - ERR_FAIL_INDEX(p_margin, 4); + ERR_FAIL_INDEX((int)p_margin, 4); margin[p_margin] = p_size; emit_changed(); @@ -200,7 +200,7 @@ Size2 StyleBoxTexture::get_center_size() const { void StyleBoxTexture::set_expand_margin_size(Margin p_expand_margin, float p_size) { - ERR_FAIL_INDEX(p_expand_margin, 4); + ERR_FAIL_INDEX((int)p_expand_margin, 4); expand_margin[p_expand_margin] = p_size; emit_changed(); } @@ -223,7 +223,7 @@ void StyleBoxTexture::set_expand_margin_size_all(float p_expand_margin_size) { float StyleBoxTexture::get_expand_margin_size(Margin p_expand_margin) const { - ERR_FAIL_INDEX_V(p_expand_margin, 4, 0); + ERR_FAIL_INDEX_V((int)p_expand_margin, 4, 0); return expand_margin[p_expand_margin]; } @@ -310,7 +310,7 @@ void StyleBoxTexture::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal_map", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_normal_map", "get_normal_map"); - ADD_PROPERTYNZ(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect"); + ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect"); ADD_GROUP("Margin", "margin_"); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "margin_left", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", MARGIN_LEFT); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "margin_right", PROPERTY_HINT_RANGE, "0,2048,1"), "set_margin_size", "get_margin_size", MARGIN_RIGHT); @@ -322,8 +322,8 @@ void StyleBoxTexture::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL, "expand_margin_top", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", MARGIN_TOP); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "expand_margin_bottom", PROPERTY_HINT_RANGE, "0,2048,1"), "set_expand_margin_size", "get_expand_margin_size", MARGIN_BOTTOM); ADD_GROUP("Axis Stretch", "axis_stretch_"); - ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "axis_stretch_horizontal", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_h_axis_stretch_mode", "get_h_axis_stretch_mode"); - ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "axis_stretch_vertical", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_v_axis_stretch_mode", "get_v_axis_stretch_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_stretch_horizontal", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_h_axis_stretch_mode", "get_h_axis_stretch_mode"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "axis_stretch_vertical", PROPERTY_HINT_ENUM, "Stretch,Tile,Tile Fit"), "set_v_axis_stretch_mode", "get_v_axis_stretch_mode"); ADD_GROUP("Modulate", "modulate_"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "modulate_color"), "set_modulate", "get_modulate"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_center"), "set_draw_center", "is_draw_center_enabled"); @@ -565,8 +565,6 @@ inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color vert_offset = 0; } int adapted_corner_detail = (corner_radius[0] == 0 && corner_radius[1] == 0 && corner_radius[2] == 0 && corner_radius[3] == 0) ? 1 : corner_detail; - int rings = (border_width[0] == 0 && border_width[1] == 0 && border_width[2] == 0 && border_width[3] == 0) ? 1 : 2; - rings = 2; int ring_corner_radius[4]; set_inner_corner_radius(style_rect, ring_rect, corner_radius, ring_corner_radius); @@ -592,7 +590,7 @@ inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color //calculate the vert array for (int corner_index = 0; corner_index < 4; corner_index++) { for (int detail = 0; detail <= adapted_corner_detail; detail++) { - for (int inner_outer = (2 - rings); inner_outer < 2; inner_outer++) { + for (int inner_outer = 0; inner_outer < 2; inner_outer++) { float radius; Color color; Point2 corner_point; @@ -613,19 +611,17 @@ inline void draw_ring(Vector<Vector2> &verts, Vector<int> &indices, Vector<Color } } - if (rings == 2) { - int vert_count = (adapted_corner_detail + 1) * 4 * rings; - //fill the indices and the colors for the border - for (int i = 0; i < vert_count; i++) { - //poly 1 - indices.push_back(vert_offset + ((i + 0) % vert_count)); - indices.push_back(vert_offset + ((i + 2) % vert_count)); - indices.push_back(vert_offset + ((i + 1) % vert_count)); - //poly 2 - indices.push_back(vert_offset + ((i + 1) % vert_count)); - indices.push_back(vert_offset + ((i + 2) % vert_count)); - indices.push_back(vert_offset + ((i + 3) % vert_count)); - } + int vert_count = (adapted_corner_detail + 1) * 4 * 2; + //fill the indices and the colors for the border + for (int i = 0; i < vert_count; i++) { + //poly 1 + indices.push_back(vert_offset + ((i + 0) % vert_count)); + indices.push_back(vert_offset + ((i + 2) % vert_count)); + indices.push_back(vert_offset + ((i + 1) % vert_count)); + //poly 2 + indices.push_back(vert_offset + ((i + 1) % vert_count)); + indices.push_back(vert_offset + ((i + 2) % vert_count)); + indices.push_back(vert_offset + ((i + 3) % vert_count)); } } diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp index 5d4c7861e3..9907636e91 100644 --- a/scene/resources/surface_tool.cpp +++ b/scene/resources/surface_tool.cpp @@ -764,10 +764,22 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const } //mikktspace callbacks +namespace { +struct TangentGenerationContextUserData { + Vector<List<SurfaceTool::Vertex>::Element *> vertices; + Vector<List<int>::Element *> indices; +}; +} // namespace + int SurfaceTool::mikktGetNumFaces(const SMikkTSpaceContext *pContext) { - Vector<List<Vertex>::Element *> &varr = *((Vector<List<Vertex>::Element *> *)pContext->m_pUserData); - return varr.size() / 3; + TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); + + if (triangle_data.indices.size() > 0) { + return triangle_data.indices.size() / 3; + } else { + return triangle_data.vertices.size() / 3; + } } int SurfaceTool::mikktGetNumVerticesOfFace(const SMikkTSpaceContext *pContext, const int iFace) { @@ -775,8 +787,17 @@ int SurfaceTool::mikktGetNumVerticesOfFace(const SMikkTSpaceContext *pContext, c } void SurfaceTool::mikktGetPosition(const SMikkTSpaceContext *pContext, float fvPosOut[], const int iFace, const int iVert) { - Vector<List<Vertex>::Element *> &varr = *((Vector<List<Vertex>::Element *> *)pContext->m_pUserData); - Vector3 v = varr[iFace * 3 + iVert]->get().vertex; + TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); + Vector3 v; + if (triangle_data.indices.size() > 0) { + int index = triangle_data.indices[iFace * 3 + iVert]->get(); + if (index < triangle_data.vertices.size()) { + v = triangle_data.vertices[index]->get().vertex; + } + } else { + v = triangle_data.vertices[iFace * 3 + iVert]->get().vertex; + } + fvPosOut[0] = v.x; fvPosOut[1] = v.y; fvPosOut[2] = v.z; @@ -784,38 +805,56 @@ void SurfaceTool::mikktGetPosition(const SMikkTSpaceContext *pContext, float fvP void SurfaceTool::mikktGetNormal(const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert) { - Vector<List<Vertex>::Element *> &varr = *((Vector<List<Vertex>::Element *> *)pContext->m_pUserData); - Vector3 v = varr[iFace * 3 + iVert]->get().normal; + TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); + Vector3 v; + if (triangle_data.indices.size() > 0) { + int index = triangle_data.indices[iFace * 3 + iVert]->get(); + if (index < triangle_data.vertices.size()) { + v = triangle_data.vertices[index]->get().normal; + } + } else { + v = triangle_data.vertices[iFace * 3 + iVert]->get().normal; + } + fvNormOut[0] = v.x; fvNormOut[1] = v.y; fvNormOut[2] = v.z; } void SurfaceTool::mikktGetTexCoord(const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert) { - Vector<List<Vertex>::Element *> &varr = *((Vector<List<Vertex>::Element *> *)pContext->m_pUserData); - Vector2 v = varr[iFace * 3 + iVert]->get().uv; + TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); + Vector2 v; + if (triangle_data.indices.size() > 0) { + int index = triangle_data.indices[iFace * 3 + iVert]->get(); + if (index < triangle_data.vertices.size()) { + v = triangle_data.vertices[index]->get().uv; + } + } else { + v = triangle_data.vertices[iFace * 3 + iVert]->get().uv; + } + fvTexcOut[0] = v.x; fvTexcOut[1] = v.y; - //fvTexcOut[1]=1.0-v.y; } void SurfaceTool::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fvBiTangent[], const float fMagS, const float fMagT, const tbool bIsOrientationPreserving, const int iFace, const int iVert) { - Vector<List<Vertex>::Element *> &varr = *((Vector<List<Vertex>::Element *> *)pContext->m_pUserData); - Vertex *vtx = &varr[iFace * 3 + iVert]->get(); - - vtx->tangent = Vector3(fvTangent[0], fvTangent[1], fvTangent[2]); - vtx->binormal = Vector3(fvBiTangent[0], fvBiTangent[1], fvBiTangent[2]); -} - -void SurfaceTool::mikktSetTSpaceBasic(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert) { - - Vector<List<Vertex>::Element *> &varr = *((Vector<List<Vertex>::Element *> *)pContext->m_pUserData); - Vertex &vtx = varr[iFace * 3 + iVert]->get(); + TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData); + Vertex *vtx = NULL; + if (triangle_data.indices.size() > 0) { + int index = triangle_data.indices[iFace * 3 + iVert]->get(); + if (index < triangle_data.vertices.size()) { + vtx = &triangle_data.vertices[index]->get(); + } + } else { + vtx = &triangle_data.vertices[iFace * 3 + iVert]->get(); + } - vtx.tangent = Vector3(fvTangent[0], fvTangent[1], fvTangent[2]); - vtx.binormal = vtx.normal.cross(vtx.tangent) * fSign; + if (vtx != NULL) { + vtx->tangent = Vector3(fvTangent[0], fvTangent[1], fvTangent[2]); + vtx->binormal = Vector3(fvBiTangent[0], fvBiTangent[1], fvBiTangent[2]); + } } void SurfaceTool::generate_tangents() { @@ -823,10 +862,6 @@ void SurfaceTool::generate_tangents() { ERR_FAIL_COND(!(format & Mesh::ARRAY_FORMAT_TEX_UV)); ERR_FAIL_COND(!(format & Mesh::ARRAY_FORMAT_NORMAL)); - bool indexed = index_array.size() > 0; - if (indexed) - deindex(); - SMikkTSpaceInterface mkif; mkif.m_getNormal = mikktGetNormal; mkif.m_getNumFaces = mikktGetNumFaces; @@ -839,24 +874,25 @@ void SurfaceTool::generate_tangents() { SMikkTSpaceContext msc; msc.m_pInterface = &mkif; - Vector<List<Vertex>::Element *> vtx; - vtx.resize(vertex_array.size()); + TangentGenerationContextUserData triangle_data; + triangle_data.vertices.resize(vertex_array.size()); int idx = 0; for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) { - vtx.write[idx++] = E; + triangle_data.vertices.write[idx++] = E; E->get().binormal = Vector3(); E->get().tangent = Vector3(); } - msc.m_pUserData = &vtx; + triangle_data.indices.resize(index_array.size()); + idx = 0; + for (List<int>::Element *E = index_array.front(); E; E = E->next()) { + triangle_data.indices.write[idx++] = E; + } + msc.m_pUserData = &triangle_data; bool res = genTangSpaceDefault(&msc); ERR_FAIL_COND(!res); format |= Mesh::ARRAY_FORMAT_TANGENT; - - if (indexed) { - index(); - } } void SurfaceTool::generate_normals(bool p_flip) { diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h index 459d399380..cc8599e90a 100644 --- a/scene/resources/surface_tool.h +++ b/scene/resources/surface_tool.h @@ -90,7 +90,6 @@ private: static void mikktGetPosition(const SMikkTSpaceContext *pContext, float fvPosOut[], const int iFace, const int iVert); static void mikktGetNormal(const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert); static void mikktGetTexCoord(const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert); - static void mikktSetTSpaceBasic(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fSign, const int iFace, const int iVert); static void mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fvBiTangent[], const float fMagS, const float fMagT, const tbool bIsOrientationPreserving, const int iFace, const int iVert); diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 16b4ed31df..4f4d375481 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -207,6 +207,9 @@ void ImageTexture::set_flags(uint32_t p_flags) { flags=p_flags|cube; */ flags = p_flags; + if (w == 0 || h == 0) { + return; //uninitialized, do not set to texture + } VisualServer::get_singleton()->texture_set_flags(texture, p_flags); } @@ -423,6 +426,15 @@ ImageTexture::~ImageTexture() { ////////////////////////////////////////// +void StreamTexture::set_path(const String &p_path, bool p_take_over) { + + if (texture.is_valid()) { + VisualServer::get_singleton()->texture_set_path(texture, p_path); + } + + Resource::set_path(p_path, p_take_over); +} + void StreamTexture::_requested_3d(void *p_ud) { StreamTexture *st = (StreamTexture *)p_ud; @@ -982,11 +994,11 @@ void AtlasTexture::_bind_methods() { void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const { - Rect2 rc = region; - if (!atlas.is_valid()) return; + Rect2 rc = region; + if (rc.size.width == 0) { rc.size.width = atlas->get_width(); } @@ -1001,11 +1013,11 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref<Texture> &p_normal_map) const { - Rect2 rc = region; - if (!atlas.is_valid()) return; + Rect2 rc = region; + if (rc.size.width == 0) { rc.size.width = atlas->get_width(); } @@ -1036,11 +1048,11 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { - Rect2 rc = region; - if (!atlas.is_valid()) return false; + Rect2 rc = region; + Rect2 src = p_src_rect; if (src.size == Size2()) { src.size = rc.size; @@ -1072,11 +1084,13 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const { - if (atlas.is_valid()) { - return atlas->is_pixel_opaque(p_x + region.position.x + margin.position.x, p_x + region.position.y + margin.position.y); - } + if (!atlas.is_valid()) + return true; - return true; + int x = p_x + region.position.x + margin.position.x; + int y = p_y + region.position.y + margin.position.y; + + return atlas->is_pixel_opaque(x, y); } AtlasTexture::AtlasTexture() { diff --git a/scene/resources/texture.h b/scene/resources/texture.h index cb759c63da..e9b69e9cb1 100644 --- a/scene/resources/texture.h +++ b/scene/resources/texture.h @@ -219,6 +219,8 @@ public: int get_height() const; virtual RID get_rid() const; + virtual void set_path(const String &p_path, bool p_take_over); + virtual void draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const; virtual void draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>()) const; virtual void draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false, const Ref<Texture> &p_normal_map = Ref<Texture>(), bool p_clip_uv = true) const; diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index b102d477f2..3eb652ecd9 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -39,26 +39,6 @@ void Theme::_emit_theme_changed() { emit_changed(); } -void Theme::_ref_font(Ref<Font> p_sc) { - - if (!font_refcount.has(p_sc)) { - font_refcount[p_sc] = 1; - p_sc->connect("changed", this, "_emit_theme_changed"); - } else { - font_refcount[p_sc] += 1; - } -} - -void Theme::_unref_font(Ref<Font> p_sc) { - - ERR_FAIL_COND(!font_refcount.has(p_sc)); - font_refcount[p_sc]--; - if (font_refcount[p_sc] == 0) { - p_sc->disconnect("changed", this, "_emit_theme_changed"); - font_refcount.erase(p_sc); - } -} - bool Theme::_set(const StringName &p_name, const Variant &p_value) { String sname = p_name; @@ -217,13 +197,13 @@ void Theme::set_default_theme_font(const Ref<Font> &p_default_font) { return; if (default_theme_font.is_valid()) { - _unref_font(default_theme_font); + default_theme_font->disconnect("changed", this, "_emit_theme_changed"); } default_theme_font = p_default_font; if (default_theme_font.is_valid()) { - _ref_font(default_theme_font); + default_theme_font->connect("changed", this, "_emit_theme_changed", varray(), CONNECT_REFERENCE_COUNTED); } _change_notify(); @@ -263,8 +243,16 @@ void Theme::set_icon(const StringName &p_name, const StringName &p_type, const R bool new_value = !icon_map.has(p_type) || !icon_map[p_type].has(p_name); + if (icon_map[p_type].has(p_name) && icon_map[p_type][p_name].is_valid()) { + icon_map[p_type][p_name]->disconnect("changed", this, "_emit_theme_changed"); + } + icon_map[p_type][p_name] = p_icon; + if (p_icon.is_valid()) { + icon_map[p_type][p_name]->connect("changed", this, "_emit_theme_changed", varray(), CONNECT_REFERENCE_COUNTED); + } + if (new_value) { _change_notify(); emit_changed(); @@ -290,7 +278,12 @@ void Theme::clear_icon(const StringName &p_name, const StringName &p_type) { ERR_FAIL_COND(!icon_map.has(p_type)); ERR_FAIL_COND(!icon_map[p_type].has(p_name)); + if (icon_map[p_type][p_name].is_valid()) { + icon_map[p_type][p_name]->disconnect("changed", this, "_emit_theme_changed"); + } + icon_map[p_type].erase(p_name); + _change_notify(); emit_changed(); } @@ -358,8 +351,16 @@ void Theme::set_stylebox(const StringName &p_name, const StringName &p_type, con bool new_value = !style_map.has(p_type) || !style_map[p_type].has(p_name); + if (style_map[p_type].has(p_name) && style_map[p_type][p_name].is_valid()) { + style_map[p_type][p_name]->disconnect("changed", this, "_emit_theme_changed"); + } + style_map[p_type][p_name] = p_style; + if (p_style.is_valid()) { + style_map[p_type][p_name]->connect("changed", this, "_emit_theme_changed", varray(), CONNECT_REFERENCE_COUNTED); + } + if (new_value) _change_notify(); emit_changed(); @@ -385,7 +386,12 @@ void Theme::clear_stylebox(const StringName &p_name, const StringName &p_type) { ERR_FAIL_COND(!style_map.has(p_type)); ERR_FAIL_COND(!style_map[p_type].has(p_name)); + if (style_map[p_type][p_name].is_valid()) { + style_map[p_type][p_name]->disconnect("changed", this, "_emit_theme_changed"); + } + style_map[p_type].erase(p_name); + _change_notify(); emit_changed(); } @@ -416,15 +422,14 @@ void Theme::set_font(const StringName &p_name, const StringName &p_type, const R bool new_value = !font_map.has(p_type) || !font_map[p_type].has(p_name); - if (!new_value) { - if (font_map[p_type][p_name].is_valid()) { - _unref_font(font_map[p_type][p_name]); - } + if (font_map[p_type][p_name].is_valid()) { + font_map[p_type][p_name]->disconnect("changed", this, "_emit_theme_changed"); } + font_map[p_type][p_name] = p_font; if (p_font.is_valid()) { - _ref_font(p_font); + font_map[p_type][p_name]->connect("changed", this, "_emit_theme_changed", varray(), CONNECT_REFERENCE_COUNTED); } if (new_value) { @@ -452,8 +457,8 @@ void Theme::clear_font(const StringName &p_name, const StringName &p_type) { ERR_FAIL_COND(!font_map.has(p_type)); ERR_FAIL_COND(!font_map[p_type].has(p_name)); - if (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()) { - _unref_font(font_map[p_type][p_name]); + if (font_map[p_type][p_name].is_valid()) { + font_map[p_type][p_name]->disconnect("changed", this, "_emit_theme_changed"); } font_map[p_type].erase(p_name); @@ -570,15 +575,91 @@ void Theme::get_constant_list(StringName p_type, List<StringName> *p_list) const } } +void Theme::clear() { + + //these need disconnecting + { + const StringName *K = NULL; + while ((K = icon_map.next(K))) { + const StringName *L = NULL; + while ((L = icon_map[*K].next(L))) { + icon_map[*K][*L]->disconnect("changed", this, "_emit_theme_changed"); + } + } + } + + { + const StringName *K = NULL; + while ((K = style_map.next(K))) { + const StringName *L = NULL; + while ((L = style_map[*K].next(L))) { + style_map[*K][*L]->disconnect("changed", this, "_emit_theme_changed"); + } + } + } + + { + const StringName *K = NULL; + while ((K = font_map.next(K))) { + const StringName *L = NULL; + while ((L = font_map[*K].next(L))) { + font_map[*K][*L]->disconnect("changed", this, "_emit_theme_changed"); + } + } + } + + icon_map.clear(); + style_map.clear(); + font_map.clear(); + shader_map.clear(); + color_map.clear(); + constant_map.clear(); + + _change_notify(); + emit_changed(); +} + void Theme::copy_default_theme() { Ref<Theme> default_theme = get_default(); - icon_map = default_theme->icon_map; - style_map = default_theme->style_map; - font_map = default_theme->font_map; + //these need reconnecting, so add normally + { + const StringName *K = NULL; + while ((K = default_theme->icon_map.next(K))) { + const StringName *L = NULL; + while ((L = default_theme->icon_map[*K].next(L))) { + set_icon(*K, *L, default_theme->icon_map[*K][*L]); + } + } + } + + { + const StringName *K = NULL; + while ((K = default_theme->style_map.next(K))) { + const StringName *L = NULL; + while ((L = default_theme->style_map[*K].next(L))) { + set_stylebox(*K, *L, default_theme->style_map[*K][*L]); + } + } + } + + { + const StringName *K = NULL; + while ((K = default_theme->font_map.next(K))) { + const StringName *L = NULL; + while ((L = default_theme->font_map[*K].next(L))) { + set_font(*K, *L, default_theme->font_map[*K][*L]); + } + } + } + + //these are ok to just copy + color_map = default_theme->color_map; constant_map = default_theme->constant_map; + shader_map = default_theme->shader_map; + _change_notify(); emit_changed(); } @@ -661,6 +742,8 @@ void Theme::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_constant", "name", "type"), &Theme::clear_constant); ClassDB::bind_method(D_METHOD("get_constant_list", "type"), &Theme::_get_constant_list); + ClassDB::bind_method(D_METHOD("clear"), &Theme::clear); + ClassDB::bind_method(D_METHOD("set_default_font", "font"), &Theme::set_default_theme_font); ClassDB::bind_method(D_METHOD("get_default_font"), &Theme::get_default_theme_font); @@ -678,411 +761,3 @@ Theme::Theme() { Theme::~Theme() { } - -RES ResourceFormatLoaderTheme::load(const String &p_path, const String &p_original_path, Error *r_error) { - if (r_error) - *r_error = ERR_CANT_OPEN; - - Error err; - FileAccess *f = FileAccess::open(p_path, FileAccess::READ, &err); - - ERR_EXPLAIN("Unable to open theme file: " + p_path); - ERR_FAIL_COND_V(err, RES()); - String base_path = p_path.get_base_dir(); - Ref<Theme> theme(memnew(Theme)); - Map<StringName, Variant> library; - if (r_error) - *r_error = ERR_FILE_CORRUPT; - - bool reading_library = false; - int line = 0; - - while (!f->eof_reached()) { - - String l = f->get_line().strip_edges(); - line++; - - int comment = l.find(";"); - if (comment != -1) - l = l.substr(0, comment); - if (l == "") - continue; - - if (l.begins_with("[")) { - if (l == "[library]") { - reading_library = true; - } else if (l == "[theme]") { - reading_library = false; - } else { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Unknown section type: '" + l + "'."); - ERR_FAIL_V(RES()); - } - continue; - } - - int eqpos = l.find("="); - if (eqpos == -1) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Expected '='."); - ERR_FAIL_V(RES()); - } - - String right = l.substr(eqpos + 1, l.length()).strip_edges(); - if (right == "") { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Expected value after '='."); - ERR_FAIL_V(RES()); - } - - Variant value; - - if (right.is_valid_integer()) { - //is number - value = right.to_int(); - } else if (right.is_valid_html_color()) { - //is html color - value = Color::html(right); - } else if (right.begins_with("@")) { //reference - - String reference = right.substr(1, right.length()); - if (!library.has(reference)) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid reference to '" + reference + "'."); - ERR_FAIL_V(RES()); - } - - value = library[reference]; - - } else if (right.begins_with("default")) { //use default - //do none - } else { - //attempt to parse a constructor - int popenpos = right.find("("); - - if (popenpos == -1) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid constructor syntax: " + right); - ERR_FAIL_V(RES()); - } - - int pclosepos = right.find_last(")"); - - if (pclosepos == -1) { - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid constructor parameter syntax: " + right); - ERR_FAIL_V(RES()); - } - - String type = right.substr(0, popenpos); - String param = right.substr(popenpos + 1, pclosepos - popenpos - 1); - - if (type == "icon") { - - String path; - - if (param.is_abs_path()) - path = param; - else - path = base_path + "/" + param; - - Ref<Texture> texture = ResourceLoader::load(path); - if (!texture.is_valid()) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Couldn't find icon at path: " + path); - ERR_FAIL_V(RES()); - } - - value = texture; - - } else if (type == "sbox") { - - String path; - - if (param.is_abs_path()) - path = param; - else - path = base_path + "/" + param; - - Ref<StyleBox> stylebox = ResourceLoader::load(path); - if (!stylebox.is_valid()) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Couldn't find stylebox at path: " + path); - ERR_FAIL_V(RES()); - } - - value = stylebox; - - } else if (type == "sboxt") { - - Vector<String> params = param.split(","); - if (params.size() != 5 && params.size() != 9) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid param count for sboxt(): '" + right + "'."); - ERR_FAIL_V(RES()); - } - - String path = params[0]; - - if (!param.is_abs_path()) - path = base_path + "/" + path; - - Ref<Texture> tex = ResourceLoader::load(path); - if (tex.is_null()) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Could not open texture for sboxt at path: '" + params[0] + "'."); - ERR_FAIL_V(RES()); - } - - Ref<StyleBoxTexture> sbtex(memnew(StyleBoxTexture)); - - sbtex->set_texture(tex); - - for (int i = 0; i < 4; i++) { - if (!params[i + 1].is_valid_integer()) { - - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid expand margin parameter for sboxt #" + itos(i + 1) + ", expected integer constant, got: '" + params[i + 1] + "'."); - ERR_FAIL_V(RES()); - } - - int margin = params[i + 1].to_int(); - sbtex->set_expand_margin_size(Margin(i), margin); - } - - if (params.size() == 9) { - - for (int i = 0; i < 4; i++) { - - if (!params[i + 5].is_valid_integer()) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid expand margin parameter for sboxt #" + itos(i + 5) + ", expected integer constant, got: '" + params[i + 5] + "'."); - ERR_FAIL_V(RES()); - } - - int margin = params[i + 5].to_int(); - sbtex->set_margin_size(Margin(i), margin); - } - } - - value = sbtex; - } else if (type == "sboxf") { - - Vector<String> params = param.split(","); - if (params.size() < 2) { - - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid param count for sboxf(): '" + right + "'."); - ERR_FAIL_V(RES()); - } - - Ref<StyleBoxFlat> sbflat(memnew(StyleBoxFlat)); - - if (!params[0].is_valid_integer()) { - - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Expected integer numeric constant for parameter 0 (border size)."); - ERR_FAIL_V(RES()); - } - - sbflat->set_border_width_all(params[0].to_int()); - - if (!params[0].is_valid_integer()) { - - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Expected integer numeric constant for parameter 0 (border size)."); - ERR_FAIL_V(RES()); - } - - int left = MIN(params.size() - 1, 3); - - int ccodes = 0; - - for (int i = 0; i < left; i++) { - - if (params[i + 1].is_valid_html_color()) - ccodes++; - else - break; - } - - Color normal; - Color bright; - Color dark; - - if (ccodes < 1) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Expected at least 1, 2 or 3 html color codes."); - ERR_FAIL_V(RES()); - } else if (ccodes == 1) { - - normal = Color::html(params[1]); - bright = Color::html(params[1]); - dark = Color::html(params[1]); - } else if (ccodes == 2) { - - normal = Color::html(params[1]); - bright = Color::html(params[2]); - dark = Color::html(params[2]); - } else { - - normal = Color::html(params[1]); - bright = Color::html(params[2]); - dark = Color::html(params[3]); - } - - sbflat->set_border_color_all(bright); - // sbflat->set_dark_color(dark); - sbflat->set_bg_color(normal); - - if (params.size() == ccodes + 5) { - //margins - for (int i = 0; i < 4; i++) { - - if (!params[i + ccodes + 1].is_valid_integer()) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid expand margin parameter for sboxf #" + itos(i + ccodes + 1) + ", expected integer constant, got: '" + params[i + ccodes + 1] + "'."); - ERR_FAIL_V(RES()); - } - - //int margin = params[i+ccodes+1].to_int(); - //sbflat->set_margin_size(Margin(i),margin); - } - } else if (params.size() != ccodes + 1) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid amount of margin parameters for sboxt."); - ERR_FAIL_V(RES()); - } - - value = sbflat; - - } else { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid constructor type: '" + type + "'."); - ERR_FAIL_V(RES()); - } - } - - //parse left and do something with it - String left = l.substr(0, eqpos); - - if (reading_library) { - - left = left.strip_edges(); - if (!left.is_valid_identifier()) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": <LibraryItem> is not a valid identifier."); - ERR_FAIL_V(RES()); - } - if (library.has(left)) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Already in library: '" + left + "'."); - ERR_FAIL_V(RES()); - } - - library[left] = value; - } else { - - int pointpos = left.find("."); - if (pointpos == -1) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Expected 'control.item=..' assign syntax."); - ERR_FAIL_V(RES()); - } - - String control = left.substr(0, pointpos).strip_edges(); - if (!control.is_valid_identifier()) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": <Control> is not a valid identifier."); - ERR_FAIL_V(RES()); - } - String item = left.substr(pointpos + 1, left.size()).strip_edges(); - if (!item.is_valid_identifier()) { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": <Item> is not a valid identifier."); - ERR_FAIL_V(RES()); - } - - if (value.get_type() == Variant::NIL) { - //try to use exiting - if (Theme::get_default()->has_stylebox(item, control)) - value = Theme::get_default()->get_stylebox(item, control); - else if (Theme::get_default()->has_font(item, control)) - value = Theme::get_default()->get_font(item, control); - else if (Theme::get_default()->has_icon(item, control)) - value = Theme::get_default()->get_icon(item, control); - else if (Theme::get_default()->has_color(item, control)) - value = Theme::get_default()->get_color(item, control); - else if (Theme::get_default()->has_constant(item, control)) - value = Theme::get_default()->get_constant(item, control); - else { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Default not present for: '" + control + "." + item + "'."); - ERR_FAIL_V(RES()); - } - } - - if (value.get_type() == Variant::OBJECT) { - - Ref<Resource> res = value; - if (!res.is_valid()) { - - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid resource (NULL)."); - ERR_FAIL_V(RES()); - } - - if (Object::cast_to<StyleBox>(*res)) { - theme->set_stylebox(item, control, res); - } else if (Object::cast_to<Font>(*res)) { - theme->set_font(item, control, res); - } else if (Object::cast_to<Font>(*res)) { - theme->set_font(item, control, res); - } else if (Object::cast_to<Texture>(*res)) { - theme->set_icon(item, control, res); - } else { - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Invalid resource type."); - ERR_FAIL_V(RES()); - } - } else if (value.get_type() == Variant::COLOR) { - - theme->set_color(item, control, value); - - } else if (value.get_type() == Variant::INT) { - - theme->set_constant(item, control, value); - - } else { - - memdelete(f); - ERR_EXPLAIN(p_path + ":" + itos(line) + ": Couldn't even determine what this setting is! what did you do!?"); - ERR_FAIL_V(RES()); - } - } - } - - f->close(); - memdelete(f); - - if (r_error) - *r_error = OK; - - return theme; -} - -void ResourceFormatLoaderTheme::get_recognized_extensions(List<String> *p_extensions) const { - - p_extensions->push_back("theme"); -} - -bool ResourceFormatLoaderTheme::handles_type(const String &p_type) const { - - return p_type == "Theme"; -} - -String ResourceFormatLoaderTheme::get_resource_type(const String &p_path) const { - - if (p_path.get_extension().to_lower() == "theme") - return "Theme"; - return ""; -} diff --git a/scene/resources/theme.h b/scene/resources/theme.h index 0b76e95f18..ba47c5fb3c 100644 --- a/scene/resources/theme.h +++ b/scene/resources/theme.h @@ -47,12 +47,6 @@ class Theme : public Resource { RES_BASE_EXTENSION("theme"); static Ref<Theme> default_theme; - - //keep a reference count to font, so each time the font changes, we emit theme changed too - Map<Ref<Font>, int> font_refcount; - - void _ref_font(Ref<Font> p_sc); - void _unref_font(Ref<Font> p_sc); void _emit_theme_changed(); HashMap<StringName, HashMap<StringName, Ref<Texture> > > icon_map; @@ -190,17 +184,10 @@ public: void get_type_list(List<StringName> *p_list) const; void copy_default_theme(); + void clear(); Theme(); ~Theme(); }; -class ResourceFormatLoaderTheme : public ResourceFormatLoader { -public: - virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = NULL); - virtual void get_recognized_extensions(List<String> *p_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; -}; - #endif diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index f852ecd7eb..88dbc67e01 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -129,6 +129,22 @@ bool TileSet::_set(const StringName &p_name, const Variant &p_value) { } p.pop_front(); } + } else if (what == "z_index_map") { + tile_map[id].autotile_data.z_index_map.clear(); + Array p = p_value; + Vector3 val; + Vector2 v; + int z_index; + while (p.size() > 0) { + val = p[0]; + if (val.z > 1) { + v.x = val.x; + v.y = val.y; + z_index = (int)val.z; + tile_map[id].autotile_data.z_index_map[v] = z_index; + } + p.pop_front(); + } } } else if (what == "shape") tile_set_shape(id, 0, p_value); @@ -228,6 +244,19 @@ bool TileSet::_get(const StringName &p_name, Variant &r_ret) const { } } r_ret = p; + } else if (what == "z_index_map") { + Array p; + Vector3 v; + for (Map<Vector2, int>::Element *E = tile_map[id].autotile_data.z_index_map.front(); E; E = E->next()) { + if (E->value() != 0) { + //Don't save default value + v.x = E->key().x; + v.y = E->key().y; + v.z = E->value(); + p.push_back(v); + } + } + r_ret = p; } } else if (what == "shape") r_ret = tile_get_shape(id, 0); @@ -278,6 +307,7 @@ void TileSet::_get_property_list(List<PropertyInfo> *p_list) const { p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/occluder_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/navpoly_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/priority_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); + p_list->push_back(PropertyInfo(Variant::ARRAY, pre + "autotile/z_index_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); } else if (tile_get_tile_mode(id) == ATLAS_TILE) { p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/icon_coordinate", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::VECTOR2, pre + "autotile/tile_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL)); @@ -476,6 +506,23 @@ int TileSet::autotile_get_subtile_priority(int p_id, const Vector2 &p_coord) { return 1; } +void TileSet::autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index) { + + ERR_FAIL_COND(!tile_map.has(p_id)); + tile_map[p_id].autotile_data.z_index_map[p_coord] = p_z_index; + emit_changed(); +} + +int TileSet::autotile_get_z_index(int p_id, const Vector2 &p_coord) { + + ERR_FAIL_COND_V(!tile_map.has(p_id), 1); + if (tile_map[p_id].autotile_data.z_index_map.has(p_coord)) { + return tile_map[p_id].autotile_data.z_index_map[p_coord]; + } + //When not custom z index set return the default value + return 0; +} + const Map<Vector2, int> &TileSet::autotile_get_priority_map(int p_id) const { static Map<Vector2, int> dummy; diff --git a/scene/resources/tile_set.h b/scene/resources/tile_set.h index 74dcd47c48..2ab771b1b0 100644 --- a/scene/resources/tile_set.h +++ b/scene/resources/tile_set.h @@ -80,21 +80,21 @@ public: struct AutotileData { BitmaskMode bitmask_mode; - int spacing; Size2 size; + int spacing; Vector2 icon_coord; Map<Vector2, uint16_t> flags; Map<Vector2, Ref<OccluderPolygon2D> > occluder_map; Map<Vector2, Ref<NavigationPolygon> > navpoly_map; Map<Vector2, int> priority_map; + Map<Vector2, int> z_index_map; // Default size to prevent invalid value explicit AutotileData() : + bitmask_mode(BITMASK_2X2), size(64, 64), spacing(0), - icon_coord(0, 0) { - bitmask_mode = BITMASK_2X2; - } + icon_coord(0, 0) {} }; private: @@ -111,8 +111,8 @@ private: Vector2 navigation_polygon_offset; Ref<NavigationPolygon> navigation_polygon; Ref<ShaderMaterial> material; - Color modulate; TileMode tile_mode; + Color modulate; AutotileData autotile_data; int z_index; @@ -173,6 +173,9 @@ public: int autotile_get_subtile_priority(int p_id, const Vector2 &p_coord); const Map<Vector2, int> &autotile_get_priority_map(int p_id) const; + void autotile_set_z_index(int p_id, const Vector2 &p_coord, int p_z_index); + int autotile_get_z_index(int p_id, const Vector2 &p_coord); + void autotile_set_bitmask(int p_id, Vector2 p_coord, uint16_t p_flag); uint16_t autotile_get_bitmask(int p_id, Vector2 p_coord); const Map<Vector2, uint16_t> &autotile_get_bitmask_map(int p_id); diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index 96b9cfa137..3d247ab7ad 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -106,7 +106,7 @@ void VisualShaderNode::_bind_methods() { ClassDB::bind_method(D_METHOD("_get_default_input_values"), &VisualShaderNode::_get_default_input_values); ADD_PROPERTY(PropertyInfo(Variant::INT, "output_port_for_preview"), "set_output_port_for_preview", "get_output_port_for_preview"); - ADD_PROPERTYNZ(PropertyInfo(Variant::ARRAY, "default_input_values", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_default_input_values", "_get_default_input_values"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "default_input_values", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_default_input_values", "_get_default_input_values"); ADD_SIGNAL(MethodInfo("editor_refresh_request")); } diff --git a/scene/resources/world.h b/scene/resources/world.h index 4c517323f3..4ba6b13476 100644 --- a/scene/resources/world.h +++ b/scene/resources/world.h @@ -36,9 +36,9 @@ #include "servers/physics_server.h" #include "servers/visual_server.h" -class SpatialIndexer; class Camera; class VisibilityNotifier; +struct SpatialIndexer; class World : public Resource { GDCLASS(World, Resource); diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index b390e74073..dd78d04104 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -29,13 +29,13 @@ /*************************************************************************/ #include "world_2d.h" -#include "servers/physics_2d_server.h" -#include "servers/visual_server.h" -//#include "servers/spatial_sound_2d_server.h" + #include "core/project_settings.h" #include "scene/2d/camera_2d.h" #include "scene/2d/visibility_notifier_2d.h" #include "scene/main/viewport.h" +#include "servers/physics_2d_server.h" +#include "servers/visual_server.h" struct SpatialIndexer2D { diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index 856e9dbf01..88ad392f85 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -35,9 +35,9 @@ #include "core/resource.h" #include "servers/physics_2d_server.h" -class SpatialIndexer2D; class VisibilityNotifier2D; class Viewport; +struct SpatialIndexer2D; class World2D : public Resource { |