summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/physics_body_2d.cpp5
-rw-r--r--scene/3d/physics_body.cpp4
-rw-r--r--scene/gui/container.cpp18
-rw-r--r--scene/gui/control.cpp104
-rw-r--r--scene/gui/control.h24
-rw-r--r--scene/gui/rich_text_label.cpp33
-rw-r--r--scene/gui/rich_text_label.h6
-rw-r--r--scene/main/viewport.cpp2
-rw-r--r--scene/resources/environment.cpp38
-rw-r--r--scene/resources/environment.h8
-rw-r--r--scene/resources/material.cpp354
-rw-r--r--scene/resources/material.h94
-rw-r--r--scene/resources/world_2d.cpp1
13 files changed, 575 insertions, 116 deletions
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index fd261117e1..8b2653f639 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -554,11 +554,12 @@ real_t RigidBody2D::get_inertia() const {
void RigidBody2D::set_weight(real_t p_weight) {
- set_mass(p_weight / 9.8);
+ set_mass(p_weight / real_t(GLOBAL_DEF("physics/2d/default_gravity", 98)) / 10);
}
+
real_t RigidBody2D::get_weight() const {
- return mass * 9.8;
+ return mass * real_t(GLOBAL_DEF("physics/2d/default_gravity", 98)) / 10;
}
void RigidBody2D::set_friction(real_t p_friction) {
diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp
index 2a7a804470..718daab75a 100644
--- a/scene/3d/physics_body.cpp
+++ b/scene/3d/physics_body.cpp
@@ -520,11 +520,11 @@ real_t RigidBody::get_mass() const {
void RigidBody::set_weight(real_t p_weight) {
- set_mass(p_weight / 9.8);
+ set_mass(p_weight / real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8)));
}
real_t RigidBody::get_weight() const {
- return mass * 9.8;
+ return mass * real_t(GLOBAL_DEF("physics/3d/default_gravity", 9.8));
}
void RigidBody::set_friction(real_t p_friction) {
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index 92bb5d43a7..2a96f8260c 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -95,13 +95,25 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) {
Rect2 r = p_rect;
if (!(p_child->get_h_size_flags() & SIZE_FILL)) {
- r.size.x = minsize.x;
- r.position.x += Math::floor((p_rect.size.x - minsize.x) / 2);
+ r.size.x = minsize.width;
+ if (p_child->get_h_size_flags() & SIZE_SHRINK_END) {
+ r.position.x += p_rect.size.width - minsize.width;
+ } else if (p_child->get_h_size_flags() & SIZE_SHRINK_CENTER) {
+ r.position.x += Math::floor((p_rect.size.x - minsize.width) / 2);
+ } else {
+ r.position.x += 0;
+ }
}
if (!(p_child->get_v_size_flags() & SIZE_FILL)) {
r.size.y = minsize.y;
- r.position.y += Math::floor((p_rect.size.y - minsize.y) / 2);
+ if (p_child->get_v_size_flags() & SIZE_SHRINK_END) {
+ r.position.y += p_rect.size.height - minsize.height;
+ } else if (p_child->get_v_size_flags() & SIZE_SHRINK_CENTER) {
+ r.position.y += Math::floor((p_rect.size.y - minsize.height) / 2);
+ } else {
+ r.position.y += 0;
+ }
}
for (int i = 0; i < 4; i++)
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 45485b768e..bf8d81d4a6 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -90,11 +90,22 @@ Size2 Control::edit_get_minimum_size() const {
return get_combined_minimum_size();
}
+Transform2D Control::_get_internal_transform() const {
+
+ Transform2D rot_scale;
+ rot_scale.set_rotation_and_scale(data.rotation, data.scale);
+ Transform2D offset;
+ offset.set_origin(-data.pivot_offset);
+
+ return offset.affine_inverse() * (rot_scale * offset);
+}
void Control::edit_set_rect(const Rect2 &p_edit_rect) {
- Transform2D postxf;
- postxf.set_rotation_and_scale(data.rotation, data.scale);
- Vector2 new_pos = postxf.xform(p_edit_rect.position);
+ Transform2D xform = _get_internal_transform();
+
+ // xform[2] += get_position();
+
+ Vector2 new_pos = xform.basis_xform(p_edit_rect.position);
Vector2 pos = get_position() + new_pos;
@@ -353,8 +364,9 @@ void Control::remove_child_notify(Node *p_child) {
void Control::_update_canvas_item_transform() {
- Transform2D xform = Transform2D(data.rotation, get_position());
- xform.scale_basis(data.scale);
+ Transform2D xform = _get_internal_transform();
+ xform[2] += get_position();
+
VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform);
}
@@ -1219,10 +1231,26 @@ void Control::_size_changed() {
Point2 new_pos_cache = Point2(margin_pos[0], margin_pos[1]).floor();
Size2 new_size_cache = Point2(margin_pos[2], margin_pos[3]).floor() - new_pos_cache;
+
Size2 minimum_size = get_combined_minimum_size();
- new_size_cache.x = MAX(minimum_size.x, new_size_cache.x);
- new_size_cache.y = MAX(minimum_size.y, new_size_cache.y);
+ if (data.h_grow == GROW_DIRECTION_BEGIN) {
+ if (minimum_size.width > new_size_cache.width) {
+ new_pos_cache.x = new_pos_cache.x + new_size_cache.width - minimum_size.width;
+ new_size_cache.width = minimum_size.width;
+ }
+ } else {
+ new_size_cache.width = MAX(minimum_size.width, new_size_cache.width);
+ }
+
+ if (data.v_grow == GROW_DIRECTION_BEGIN) {
+ if (minimum_size.height > new_size_cache.height) {
+ new_pos_cache.y = new_pos_cache.y + new_size_cache.height - minimum_size.height;
+ new_size_cache.height = minimum_size.height;
+ }
+ } else {
+ new_size_cache.height = MAX(minimum_size.height, new_size_cache.height);
+ }
bool pos_changed = new_pos_cache != data.pos_cache;
bool size_changed = new_size_cache != data.size_cache;
@@ -1887,8 +1915,8 @@ Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const {
Transform2D Control::get_transform() const {
- Transform2D xform = Transform2D(data.rotation, get_position());
- xform.scale_basis(data.scale);
+ Transform2D xform = _get_internal_transform();
+ xform[2] += get_position();
return xform;
}
@@ -2214,6 +2242,19 @@ void Control::_font_changed() {
minimum_size_changed(); //fonts affect minimum size pretty much almost always
}
+void Control::set_pivot_offset(const Vector2 &p_pivot) {
+
+ data.pivot_offset = p_pivot;
+ update();
+ _notify_transform();
+ _change_notify("rect_pivot_offset");
+}
+
+Vector2 Control::get_pivot_offset() const {
+
+ return data.pivot_offset;
+}
+
void Control::set_scale(const Vector2 &p_scale) {
data.scale = p_scale;
@@ -2300,6 +2341,27 @@ bool Control::is_clipping_contents() {
return data.clip_contents;
}
+void Control::set_h_grow_direction(GrowDirection p_direction) {
+
+ data.h_grow = p_direction;
+ _size_changed();
+}
+
+Control::GrowDirection Control::get_h_grow_direction() const {
+
+ return data.h_grow;
+}
+
+void Control::set_v_grow_direction(GrowDirection p_direction) {
+
+ data.v_grow = p_direction;
+ _size_changed();
+}
+Control::GrowDirection Control::get_v_grow_direction() const {
+
+ return data.v_grow;
+}
+
void Control::_bind_methods() {
//ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event);
@@ -2325,6 +2387,7 @@ void Control::_bind_methods() {
// TODO: Obsolete this method (old name) properly (GH-4397)
ClassDB::bind_method(D_METHOD("_set_rotation_deg", "degrees"), &Control::_set_rotation_deg);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale);
+ ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset);
ClassDB::bind_method(D_METHOD("get_margin", "margin"), &Control::get_margin);
ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin);
ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end);
@@ -2335,6 +2398,7 @@ void Control::_bind_methods() {
// TODO: Obsolete this method (old name) properly (GH-4397)
ClassDB::bind_method(D_METHOD("_get_rotation_deg"), &Control::_get_rotation_deg);
ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale);
+ ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset);
ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size);
ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_size);
ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position);
@@ -2388,6 +2452,12 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_parent_control:Control"), &Control::get_parent_control);
+ ClassDB::bind_method(D_METHOD("set_h_grow_direction", "direction"), &Control::set_h_grow_direction);
+ ClassDB::bind_method(D_METHOD("get_h_grow_direction"), &Control::get_h_grow_direction);
+
+ ClassDB::bind_method(D_METHOD("set_v_grow_direction", "direction"), &Control::set_v_grow_direction);
+ ClassDB::bind_method(D_METHOD("get_v_grow_direction"), &Control::get_v_grow_direction);
+
ClassDB::bind_method(D_METHOD("set_tooltip", "tooltip"), &Control::set_tooltip);
ClassDB::bind_method(D_METHOD("get_tooltip", "atpos"), &Control::get_tooltip, DEFVAL(Point2()));
ClassDB::bind_method(D_METHOD("_get_tooltip"), &Control::_get_tooltip);
@@ -2438,12 +2508,17 @@ void Control::_bind_methods() {
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_right", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_RIGHT);
ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_BOTTOM);
+ ADD_GROUP("Grow Direction", "grow_");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Begin,End"), "set_h_grow_direction", "get_h_grow_direction");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Begin,End"), "set_v_grow_direction", "get_v_grow_direction");
+
ADD_GROUP("Rect", "rect_");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_position", "get_position");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_size", "get_size");
ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size");
ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_deg", "get_rotation_deg");
ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale");
+ ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset");
ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
ADD_GROUP("Hint", "hint_");
@@ -2459,8 +2534,8 @@ void Control::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");
ADD_GROUP("Size Flags", "size_flags_");
- ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand"), "set_h_size_flags", "get_h_size_flags");
- ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand"), "set_v_size_flags", "get_v_size_flags");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
ADD_PROPERTYNO(PropertyInfo(Variant::INT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "1,128,0.01"), "set_stretch_ratio", "get_stretch_ratio");
ADD_GROUP("Theme", "");
ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
@@ -2502,11 +2577,16 @@ void Control::_bind_methods() {
BIND_CONSTANT(SIZE_EXPAND);
BIND_CONSTANT(SIZE_FILL);
BIND_CONSTANT(SIZE_EXPAND_FILL);
+ BIND_CONSTANT(SIZE_SHRINK_CENTER);
+ BIND_CONSTANT(SIZE_SHRINK_END);
BIND_CONSTANT(MOUSE_FILTER_STOP);
BIND_CONSTANT(MOUSE_FILTER_PASS);
BIND_CONSTANT(MOUSE_FILTER_IGNORE);
+ BIND_CONSTANT(GROW_DIRECTION_BEGIN);
+ BIND_CONSTANT(GROW_DIRECTION_END);
+
ADD_SIGNAL(MethodInfo("resized"));
ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
@@ -2543,6 +2623,8 @@ Control::Control() {
data.modal_frame = 0;
data.block_minimum_size_adjust = false;
data.disable_visibility_clip = false;
+ data.h_grow = GROW_DIRECTION_END;
+ data.v_grow = GROW_DIRECTION_END;
data.clip_contents = false;
for (int i = 0; i < 4; i++) {
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 5834d1550a..86cf8f6dbd 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -57,6 +57,11 @@ public:
ANCHOR_CENTER,
};
+ enum GrowDirection {
+ GROW_DIRECTION_BEGIN,
+ GROW_DIRECTION_END
+ };
+
enum FocusMode {
FOCUS_NONE,
FOCUS_CLICK,
@@ -67,7 +72,9 @@ public:
SIZE_FILL = 1,
SIZE_EXPAND = 2,
- SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL
+ SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL,
+ SIZE_SHRINK_CENTER = 4, //ignored by expand or fill
+ SIZE_SHRINK_END = 8, //ignored by expand or fil
};
@@ -117,9 +124,12 @@ private:
float margin[4];
AnchorType anchor[4];
FocusMode focus_mode;
+ GrowDirection h_grow;
+ GrowDirection v_grow;
float rotation;
Vector2 scale;
+ Vector2 pivot_offset;
bool pending_resize;
@@ -200,6 +210,8 @@ private:
void _update_canvas_item_transform();
+ Transform2D _get_internal_transform() const;
+
friend class Viewport;
void _modal_stack_remove();
void _modal_set_prev_focus_owner(ObjectID p_prev);
@@ -273,6 +285,12 @@ public:
void set_begin(const Point2 &p_point); // helper
void set_end(const Point2 &p_point); // helper
+ void set_h_grow_direction(GrowDirection p_direction);
+ GrowDirection get_h_grow_direction() const;
+
+ void set_v_grow_direction(GrowDirection p_direction);
+ GrowDirection get_v_grow_direction() const;
+
float get_margin(Margin p_margin) const;
Point2 get_begin() const;
Point2 get_end() const;
@@ -293,6 +311,9 @@ public:
float get_rotation() const;
float get_rotation_deg() const;
+ void set_pivot_offset(const Vector2 &p_pivot);
+ Vector2 get_pivot_offset() const;
+
void set_scale(const Vector2 &p_scale);
Vector2 get_scale() const;
@@ -409,5 +430,6 @@ VARIANT_ENUM_CAST(Control::FocusMode);
VARIANT_ENUM_CAST(Control::SizeFlags);
VARIANT_ENUM_CAST(Control::CursorShape);
VARIANT_ENUM_CAST(Control::MouseFilter);
+VARIANT_ENUM_CAST(Control::GrowDirection);
#endif
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 78ede6e494..c6b8398736 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -1822,12 +1822,37 @@ String RichTextLabel::get_text() {
return text;
}
+void RichTextLabel::set_text(const String &p_string) {
+ clear();
+ add_text(p_string);
+}
+
+void RichTextLabel::set_percent_visible(float p_percent) {
+
+ if (p_percent < 0 || p_percent >= 1) {
+
+ visible_characters = -1;
+ percent_visible = 1;
+
+ } else {
+
+ visible_characters = get_total_character_count() * p_percent;
+ percent_visible = p_percent;
+ }
+ update();
+}
+
+float RichTextLabel::get_percent_visible() const {
+ return percent_visible;
+}
+
void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("_gui_input"), &RichTextLabel::_gui_input);
ClassDB::bind_method(D_METHOD("_scroll_changed"), &RichTextLabel::_scroll_changed);
ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text);
ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text);
+ ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text);
ClassDB::bind_method(D_METHOD("add_image", "image:Texture"), &RichTextLabel::add_image);
ClassDB::bind_method(D_METHOD("newline"), &RichTextLabel::add_newline);
ClassDB::bind_method(D_METHOD("remove_line"), &RichTextLabel::remove_line);
@@ -1873,6 +1898,9 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_visible_characters", "amount"), &RichTextLabel::set_visible_characters);
ClassDB::bind_method(D_METHOD("get_visible_characters"), &RichTextLabel::get_visible_characters);
+ ClassDB::bind_method(D_METHOD("set_percent_visible", "percent_visible"), &RichTextLabel::set_percent_visible);
+ ClassDB::bind_method(D_METHOD("get_percent_visible"), &RichTextLabel::get_percent_visible);
+
ClassDB::bind_method(D_METHOD("get_total_character_count"), &RichTextLabel::get_total_character_count);
ClassDB::bind_method(D_METHOD("set_use_bbcode", "enable"), &RichTextLabel::set_use_bbcode);
@@ -1881,7 +1909,9 @@ void RichTextLabel::_bind_methods() {
ADD_GROUP("BBCode", "bbcode_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "bbcode_text", PROPERTY_HINT_MULTILINE_TEXT), "set_bbcode", "get_bbcode");
+
ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta")));
@@ -1914,7 +1944,6 @@ void RichTextLabel::set_visible_characters(int p_visible) {
}
int RichTextLabel::get_visible_characters() const {
-
return visible_characters;
}
int RichTextLabel::get_total_character_count() const {
@@ -1964,11 +1993,11 @@ RichTextLabel::RichTextLabel() {
selection.enabled = false;
visible_characters = -1;
+ percent_visible = 1;
set_clip_contents(true);
}
RichTextLabel::~RichTextLabel() {
-
memdelete(main);
}
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index eedb7e54db..409a8f6b3f 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -258,6 +258,7 @@ private:
Selection selection;
int visible_characters;
+ float percent_visible;
void _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Point2i &p_click_pos = Point2i(), Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL, int p_char_count = 0);
void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = NULL, int *r_click_char = NULL, bool *r_outside = NULL);
@@ -340,10 +341,15 @@ public:
void set_bbcode(const String &p_bbcode);
String get_bbcode() const;
+ void set_text(const String &p_string);
+
void set_visible_characters(int p_visible);
int get_visible_characters() const;
int get_total_character_count() const;
+ void set_percent_visible(float p_percent);
+ float get_percent_visible() const;
+
RichTextLabel();
~RichTextLabel();
};
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 3a9968d126..4fb4e02148 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -2352,7 +2352,7 @@ void Viewport::unhandled_input(const Ref<InputEvent> &p_event) {
if (physics_object_picking && !get_tree()->input_handled) {
- if (p_event->cast_to<InputEventMouseButton>() || p_event->cast_to<InputEventMouseMotion>() || p_event->cast_to<InputEventScreenDrag>() || p_event->cast_to<InputEventScreenTouch>()) {
+ if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED && (p_event->cast_to<InputEventMouseButton>() || p_event->cast_to<InputEventMouseMotion>() || p_event->cast_to<InputEventScreenDrag>() || p_event->cast_to<InputEventScreenTouch>())) {
physics_picking_events.push_back(p_event);
}
}
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index b9dc428c2d..33e62e3a00 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -471,7 +471,7 @@ bool Environment::is_ssao_blur_enabled() 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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
_change_notify();
}
@@ -489,7 +489,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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
}
bool Environment::is_glow_level_enabled(int p_level) const {
@@ -502,7 +502,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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
}
float Environment::get_glow_intensity() const {
@@ -512,18 +512,18 @@ 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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
}
float Environment::get_glow_strength() const {
return glow_strength;
}
-void Environment::set_glow_bloom(float p_treshold) {
+void Environment::set_glow_bloom(float p_threshold) {
- glow_bloom = p_treshold;
+ 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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
}
float Environment::get_glow_bloom() const {
@@ -534,29 +534,29 @@ 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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
}
Environment::GlowBlendMode Environment::get_glow_blend_mode() const {
return glow_blend_mode;
}
-void Environment::set_glow_hdr_bleed_treshold(float p_treshold) {
+void Environment::set_glow_hdr_bleed_threshold(float p_threshold) {
- glow_hdr_bleed_treshold = p_treshold;
+ 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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
}
-float Environment::get_glow_hdr_bleed_treshold() const {
+float Environment::get_glow_hdr_bleed_threshold() const {
- return glow_hdr_bleed_treshold;
+ return glow_hdr_bleed_threshold;
}
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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
}
float Environment::get_glow_hdr_bleed_scale() const {
@@ -566,7 +566,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_treshold, glow_hdr_bleed_treshold, 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_bicubic_upscale);
}
bool Environment::is_glow_bicubic_upscale_enabled() const {
@@ -1064,8 +1064,8 @@ void Environment::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_glow_blend_mode", "mode"), &Environment::set_glow_blend_mode);
ClassDB::bind_method(D_METHOD("get_glow_blend_mode"), &Environment::get_glow_blend_mode);
- ClassDB::bind_method(D_METHOD("set_glow_hdr_bleed_treshold", "treshold"), &Environment::set_glow_hdr_bleed_treshold);
- ClassDB::bind_method(D_METHOD("get_glow_hdr_bleed_treshold"), &Environment::get_glow_hdr_bleed_treshold);
+ 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_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);
@@ -1087,7 +1087,7 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "glow_strength", PROPERTY_HINT_RANGE, "0.0,2.0,0.01"), "set_glow_strength", "get_glow_strength");
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_treshold", PROPERTY_HINT_RANGE, "0.0,4.0,0.01"), "set_glow_hdr_bleed_treshold", "get_glow_hdr_bleed_treshold");
+ 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_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");
@@ -1185,7 +1185,7 @@ Environment::Environment() {
glow_strength = 1.0;
glow_bloom = 0.0;
glow_blend_mode = GLOW_BLEND_MODE_SOFTLIGHT;
- glow_hdr_bleed_treshold = 1.0;
+ glow_hdr_bleed_threshold = 1.0;
glow_hdr_bleed_scale = 2.0;
glow_bicubic_upscale = false;
diff --git a/scene/resources/environment.h b/scene/resources/environment.h
index 7eda8506b5..a7c0e2a03d 100644
--- a/scene/resources/environment.h
+++ b/scene/resources/environment.h
@@ -121,7 +121,7 @@ private:
float glow_strength;
float glow_bloom;
GlowBlendMode glow_blend_mode;
- float glow_hdr_bleed_treshold;
+ float glow_hdr_bleed_threshold;
float glow_hdr_bleed_scale;
bool glow_bicubic_upscale;
@@ -275,14 +275,14 @@ public:
void set_glow_strength(float p_strength);
float get_glow_strength() const;
- void set_glow_bloom(float p_treshold);
+ void set_glow_bloom(float p_threshold);
float get_glow_bloom() const;
void set_glow_blend_mode(GlowBlendMode p_mode);
GlowBlendMode get_glow_blend_mode() const;
- void set_glow_hdr_bleed_treshold(float p_treshold);
- float get_glow_hdr_bleed_treshold() const;
+ void set_glow_hdr_bleed_threshold(float p_threshold);
+ float get_glow_hdr_bleed_threshold() const;
void set_glow_hdr_bleed_scale(float p_scale);
float get_glow_hdr_bleed_scale() const;
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index 6209f99d9d..705702b8be 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -30,11 +30,36 @@
#include "material.h"
#include "scene/scene_string_names.h"
+void Material::set_next_pass(const Ref<Material> &p_pass) {
+
+ if (next_pass == p_pass)
+ return;
+
+ next_pass = p_pass;
+ RID next_pass_rid;
+ if (next_pass.is_valid())
+ next_pass_rid = next_pass->get_rid();
+ VS::get_singleton()->material_set_next_pass(material, next_pass_rid);
+}
+
+Ref<Material> Material::get_next_pass() const {
+
+ return next_pass;
+}
+
RID Material::get_rid() const {
return material;
}
+void Material::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_next_pass", "next_pass:Material"), &Material::set_next_pass);
+ ClassDB::bind_method(D_METHOD("get_next_pass:Material"), &Material::get_next_pass);
+
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "next_pass", PROPERTY_HINT_RESOURCE_TYPE, "Material"), "set_next_pass", "get_next_pass");
+}
+
Material::Material() {
material = VisualServer::get_singleton()->material_create();
@@ -198,6 +223,8 @@ void SpatialMaterial::init_shaders() {
shader_names->uv1_offset = "uv1_offset";
shader_names->uv2_scale = "uv2_scale";
shader_names->uv2_offset = "uv2_offset";
+ shader_names->uv1_blend_sharpness = "uv1_blend_sharpness";
+ shader_names->uv2_blend_sharpness = "uv2_blend_sharpness";
shader_names->particle_h_frames = "particle_h_frames";
shader_names->particle_v_frames = "particle_v_frames";
@@ -205,6 +232,8 @@ void SpatialMaterial::init_shaders() {
shader_names->depth_min_layers = "depth_min_layers";
shader_names->depth_max_layers = "depth_max_layers";
+ shader_names->grow = "grow";
+
shader_names->texture_names[TEXTURE_ALBEDO] = "texture_albedo";
shader_names->texture_names[TEXTURE_METALLIC] = "texture_metallic";
shader_names->texture_names[TEXTURE_ROUGHNESS] = "texture_roughness";
@@ -289,6 +318,14 @@ void SpatialMaterial::_update_shader() {
case DIFFUSE_HALF_LAMBERT: code += ",diffuse_half_lambert"; break;
case DIFFUSE_OREN_NAYAR: code += ",diffuse_oren_nayar"; break;
case DIFFUSE_BURLEY: code += ",diffuse_burley"; break;
+ case DIFFUSE_TOON: code += ",diffuse_toon"; break;
+ }
+ switch (specular_mode) {
+ case SPECULAR_SCHLICK_GGX: code += ",specular_schlick_ggx"; break;
+ case SPECULAR_BLINN: code += ",specular_blinn"; break;
+ case SPECULAR_PHONG: code += ",specular_phong"; break;
+ case SPECULAR_TOON: code += ",specular_toon"; break;
+ case SPECULAR_DISABLED: code += ",specular_disabled"; break;
}
if (flags[FLAG_UNSHADED]) {
@@ -298,21 +335,23 @@ void SpatialMaterial::_update_shader() {
code += ",ontop";
}
+ if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) {
+ code += ",world_vertex_coords";
+ }
code += ";\n";
code += "uniform vec4 albedo : hint_color;\n";
code += "uniform sampler2D texture_albedo : hint_albedo;\n";
code += "uniform float specular;\n";
code += "uniform float metallic;\n";
+ if (grow_enabled) {
+ code += "uniform float grow;\n";
+ }
code += "uniform float roughness : hint_range(0,1);\n";
code += "uniform float point_size : hint_range(0,128);\n";
code += "uniform sampler2D texture_metallic : hint_white;\n";
code += "uniform sampler2D texture_roughness : hint_white;\n";
- code += "uniform vec2 uv1_scale;\n";
- code += "uniform vec2 uv1_offset;\n";
- code += "uniform vec2 uv2_scale;\n";
- code += "uniform vec2 uv2_offset;\n";
if (billboard_mode == BILLBOARD_PARTICLES) {
code += "uniform int particles_anim_h_frames;\n";
code += "uniform int particles_anim_v_frames;\n";
@@ -371,6 +410,26 @@ void SpatialMaterial::_update_shader() {
code += "uniform int depth_min_layers;\n";
code += "uniform int depth_max_layers;\n";
}
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "varying vec3 uv1_world_pos;\n";
+ }
+ if (flags[FLAG_UV2_USE_TRIPLANAR]) {
+ code += "varying vec3 uv2_world_pos;\n";
+ }
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "uniform float uv1_blend_sharpness;\n";
+ code += "varying vec3 uv1_power_normal;\n";
+ }
+
+ if (flags[FLAG_UV2_USE_TRIPLANAR]) {
+ code += "uniform float uv2_blend_sharpness;\n";
+ code += "varying vec3 uv2_power_normal;\n";
+ }
+
+ code += "uniform vec3 uv1_scale;\n";
+ code += "uniform vec3 uv1_offset;\n";
+ code += "uniform vec3 uv2_scale;\n";
+ code += "uniform vec3 uv2_offset;\n";
code += "\n\n";
@@ -384,7 +443,10 @@ void SpatialMaterial::_update_shader() {
code += "\tPOINT_SIZE=point_size;\n";
}
- code += "\tUV=UV*uv1_scale+uv1_offset;\n";
+
+ if (!flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tUV=UV*uv1_scale.xy+uv1_offset.xy;\n";
+ }
switch (billboard_mode) {
case BILLBOARD_DISABLED: {
@@ -414,7 +476,6 @@ void SpatialMaterial::_update_shader() {
//code += "\tUV+= UV * vec2(float(particle_frame % particles_anim_h_frames),float(particle_frame / particles_anim_v_frames));\n";
//handle rotation
// code += "\tmat4 rotation = mat4("
-
} break;
}
@@ -437,20 +498,65 @@ void SpatialMaterial::_update_shader() {
code += "\t}\n";
}
- if (detail_uv == DETAIL_UV_2) {
+ if (detail_uv == DETAIL_UV_2 && !flags[FLAG_UV2_USE_TRIPLANAR]) {
code += "\tUV2=UV2*uv2_scale+uv2_offset;\n";
}
+ if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) {
+ //generate tangent and binormal in world space
+ code += "\tTANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);\n";
+ code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.y);\n";
+ code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);\n";
+ code += "\tTANGENT = normalize(TANGENT);\n";
+
+ code += "\tBINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);\n";
+ code += "\tBINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);\n";
+ code += "\tBINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);\n";
+ code += "\tBINORMAL = normalize(BINORMAL);\n";
+ }
+
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+
+ code += "\tuv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n";
+ code += "\tuv1_power_normal/=dot(uv1_power_normal,vec3(1.0));\n";
+ code += "\tuv1_world_pos = VERTEX * uv1_scale + uv1_offset;\n";
+ code += "\tuv1_world_pos *= vec3(1.0,-1.0, 1.0);\n";
+ }
+
+ if (flags[FLAG_UV2_USE_TRIPLANAR]) {
+
+ code += "\tuv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n";
+ code += "\tuv2_power_normal/=dot(uv2_power_normal,vec3(1.0));\n";
+ code += "\tuv2_world_pos = VERTEX * uv2_scale + uv2_offset;\n";
+ code += "\tuv2_world_pos *= vec3(1.0,-1.0, 1.0);\n";
+ }
+
+ if (grow_enabled) {
+ code += "\tVERTEX+=NORMAL*grow;\n";
+ }
code += "}\n";
code += "\n\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) {
+ code += "vec4 triplanar_texture(sampler2D p_sampler,vec3 p_weights,vec3 p_world_pos) {\n";
+ code += "\tvec4 samp=vec4(0.0);\n";
+ code += "\tsamp+= texture(p_sampler,p_world_pos.xy) * p_weights.z;\n";
+ code += "\tsamp+= texture(p_sampler,p_world_pos.xz) * p_weights.y;\n";
+ code += "\tsamp+= texture(p_sampler,p_world_pos.zy * vec2(-1.0,1.0)) * p_weights.x;\n";
+ code += "\treturn samp;\n";
+ code += "}\n";
+ }
+ code += "\n\n";
code += "void fragment() {\n";
- code += "\tvec2 base_uv = UV;\n";
- if (features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) {
+ if (!flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tvec2 base_uv = UV;\n";
+ }
+
+ if ((features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) || (features[FEATURE_AMBIENT_OCCLUSION] && flags[FLAG_AO_ON_UV2])) {
code += "\tvec2 base_uv2 = UV2;\n";
}
- if (features[FEATURE_DEPTH_MAPPING]) {
+ 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
@@ -490,7 +596,11 @@ void SpatialMaterial::_update_shader() {
if (flags[FLAG_USE_POINT_SIZE]) {
code += "\tvec4 albedo_tex = texture(texture_albedo,POINT_COORD);\n";
} else {
- code += "\tvec4 albedo_tex = texture(texture_albedo,base_uv);\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tvec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_world_pos);\n";
+ } else {
+ code += "\tvec4 albedo_tex = texture(texture_albedo,base_uv);\n";
+ }
}
if (flags[FLAG_ALBEDO_FROM_VERTEX_COLOR]) {
@@ -498,22 +608,39 @@ void SpatialMaterial::_update_shader() {
}
code += "\tALBEDO = albedo.rgb * albedo_tex.rgb;\n";
- code += "\tfloat metallic_tex = texture(texture_metallic,base_uv).r;\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tfloat metallic_tex = triplanar_texture(texture_metallic,uv1_power_normal,uv1_world_pos).r;\n";
+ } else {
+ code += "\tfloat metallic_tex = texture(texture_metallic,base_uv).r;\n";
+ }
code += "\tMETALLIC = metallic_tex * metallic;\n";
- code += "\tfloat roughness_tex = texture(texture_roughness,base_uv).r;\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tfloat roughness_tex = triplanar_texture(texture_roughness,uv1_power_normal,uv1_world_pos).r;\n";
+ } else {
+ code += "\tfloat roughness_tex = texture(texture_roughness,base_uv).r;\n";
+ }
code += "\tROUGHNESS = roughness_tex * roughness;\n";
code += "\tSPECULAR = specular;\n";
if (features[FEATURE_NORMAL_MAPPING]) {
- code += "\tNORMALMAP = texture(texture_normal,base_uv).rgb;\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tNORMALMAP = triplanar_texture(texture_normal,uv1_power_normal,uv1_world_pos).rgb;\n";
+ } else {
+ code += "\tNORMALMAP = texture(texture_normal,base_uv).rgb;\n";
+ }
code += "\tNORMALMAP_DEPTH = normal_scale;\n";
}
if (features[FEATURE_EMISSION]) {
- code += "\tEMISSION = (emission.rgb+texture(texture_emission,base_uv).rgb)*emission_energy;\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tvec3 emission_tex = triplanar_texture(texture_emission,uv1_power_normal,uv1_world_pos).rgb;\n";
+ } else {
+ code += "\tvec3 emission_tex = texture(texture_emission,base_uv).rgb;\n";
+ }
+ code += "\tEMISSION = (emission.rgb+emission_tex)*emission_energy;\n";
}
- if (features[FEATURE_REFRACTION]) {
+ if (features[FEATURE_REFRACTION] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //refraction not supported with triplanar
if (features[FEATURE_NORMAL_MAPPING]) {
code += "\tvec3 ref_normal = normalize( mix(NORMAL,TANGENT * NORMALMAP.x + BINORMAL * NORMALMAP.y + NORMAL * NORMALMAP.z,NORMALMAP_DEPTH) ) * SIDE;\n";
@@ -532,38 +659,82 @@ void SpatialMaterial::_update_shader() {
}
if (features[FEATURE_RIM]) {
- code += "\tvec2 rim_tex = texture(texture_rim,base_uv).xw;\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tvec2 rim_tex = triplanar_texture(texture_rim,uv1_power_normal,uv1_world_pos).xy;\n";
+ } else {
+ code += "\tvec2 rim_tex = texture(texture_rim,base_uv).xy;\n";
+ }
code += "\tRIM = rim*rim_tex.x;";
code += "\tRIM_TINT = rim_tint*rim_tex.y;\n";
}
if (features[FEATURE_CLEARCOAT]) {
- code += "\tvec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xw;\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tvec2 clearcoat_tex = triplanar_texture(texture_clearcoat,uv1_power_normal,uv1_world_pos).xy;\n";
+ } else {
+ code += "\tvec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xy;\n";
+ }
code += "\tCLEARCOAT = clearcoat*clearcoat_tex.x;";
code += "\tCLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y;\n";
}
if (features[FEATURE_ANISOTROPY]) {
- code += "\tvec4 anisotropy_tex = texture(texture_flowmap,base_uv);\n";
- code += "\tANISOTROPY = anisotropy_ratio*anisotropy_tex.a;\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tvec3 anisotropy_tex = triplanar_texture(texture_flowmap,uv1_power_normal,uv1_world_pos).rga;\n";
+ } else {
+ code += "\tvec3 anisotropy_tex = texture(texture_flowmap,base_uv).rga;\n";
+ }
+ code += "\tANISOTROPY = anisotropy_ratio*anisotropy_tex.b;\n";
code += "\tANISOTROPY_FLOW = anisotropy_tex.rg*2.0-1.0;\n";
}
if (features[FEATURE_AMBIENT_OCCLUSION]) {
- code += "\tAO = texture(texture_ambient_occlusion,base_uv).r;\n";
+ if (flags[FLAG_AO_ON_UV2]) {
+ if (flags[FLAG_UV2_USE_TRIPLANAR]) {
+ code += "\tAO = triplanar_texture(texture_ambient_occlusion,uv2_power_normal,uv2_world_pos).r;\n";
+ } else {
+ code += "\tAO = texture(texture_ambient_occlusion,base_uv2).r;\n";
+ }
+ } else {
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tAO = triplanar_texture(texture_ambient_occlusion,uv1_power_normal,uv1_world_pos).r;\n";
+ } else {
+ code += "\tAO = texture(texture_ambient_occlusion,base_uv).r;\n";
+ }
+ }
}
if (features[FEATURE_SUBSURACE_SCATTERING]) {
- code += "\tfloat sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n";
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+ code += "\tfloat sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_world_pos).r;\n";
+ } else {
+ code += "\tfloat sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n";
+ }
code += "\tSSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n";
}
if (features[FEATURE_DETAIL]) {
- String det_uv = detail_uv == DETAIL_UV_1 ? "base_uv" : "base_uv2";
- code += "\tvec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n";
- code += "\tvec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n";
- code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n";
+
+ bool triplanar = (flags[FLAG_UV1_USE_TRIPLANAR] && detail_uv == DETAIL_UV_1) || (flags[FLAG_UV2_USE_TRIPLANAR] && detail_uv == DETAIL_UV_2);
+
+ if (triplanar) {
+ String tp_uv = detail_uv == DETAIL_UV_1 ? "uv1" : "uv2";
+ code += "\tvec4 detail_tex = triplanar_texture(texture_detail_albedo," + tp_uv + "_power_normal," + tp_uv + "_world_pos);\n";
+ code += "\tvec4 detail_norm_tex = triplanar_texture(texture_detail_normal," + tp_uv + "_power_normal," + tp_uv + "_world_pos);\n";
+
+ } else {
+ String det_uv = detail_uv == DETAIL_UV_1 ? "base_uv" : "base_uv2";
+ code += "\tvec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n";
+ code += "\tvec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n";
+ }
+
+ if (flags[FLAG_UV1_USE_TRIPLANAR]) {
+
+ code += "\tvec4 detail_mask_tex = triplanar_texture(texture_detail_mask,uv1_power_normal);\n";
+ } else {
+ code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n";
+ }
switch (detail_blend_mode) {
case BLEND_MODE_MIX: {
@@ -581,7 +752,6 @@ void SpatialMaterial::_update_shader() {
}
code += "\tvec3 detail_norm = mix(NORMALMAP,detail_norm_tex.rgb,detail_tex.a);\n";
-
code += "\tNORMALMAP = mix(NORMALMAP,detail_norm,detail_mask_tex.r);\n";
code += "\tALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n";
}
@@ -875,6 +1045,19 @@ SpatialMaterial::DiffuseMode SpatialMaterial::get_diffuse_mode() const {
return diffuse_mode;
}
+void SpatialMaterial::set_specular_mode(SpecularMode p_mode) {
+
+ if (specular_mode == p_mode)
+ return;
+
+ specular_mode = p_mode;
+ _queue_shader_change();
+}
+SpatialMaterial::SpecularMode SpatialMaterial::get_specular_mode() const {
+
+ return specular_mode;
+}
+
void SpatialMaterial::set_flag(Flags p_flag, bool p_enabled) {
ERR_FAIL_INDEX(p_flag, FLAG_MAX);
@@ -947,6 +1130,10 @@ void SpatialMaterial::_validate_property(PropertyInfo &property) const {
if (property.name.begins_with("particles_anim_") && billboard_mode != BILLBOARD_PARTICLES) {
property.usage = 0;
}
+
+ if (property.name == "params_grow_amount" && !grow_enabled) {
+ property.usage = 0;
+ }
}
void SpatialMaterial::set_line_width(float p_line_width) {
@@ -971,49 +1158,71 @@ float SpatialMaterial::get_point_size() const {
return point_size;
}
-void SpatialMaterial::set_uv1_scale(const Vector2 &p_scale) {
+void SpatialMaterial::set_uv1_scale(const Vector3 &p_scale) {
uv1_scale = p_scale;
VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_scale, p_scale);
}
-Vector2 SpatialMaterial::get_uv1_scale() const {
+Vector3 SpatialMaterial::get_uv1_scale() const {
return uv1_scale;
}
-void SpatialMaterial::set_uv1_offset(const Vector2 &p_offset) {
+void SpatialMaterial::set_uv1_offset(const Vector3 &p_offset) {
uv1_offset = p_offset;
VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_offset, p_offset);
}
-Vector2 SpatialMaterial::get_uv1_offset() const {
+Vector3 SpatialMaterial::get_uv1_offset() const {
return uv1_offset;
}
-void SpatialMaterial::set_uv2_scale(const Vector2 &p_scale) {
+void SpatialMaterial::set_uv1_triplanar_blend_sharpness(float p_sharpness) {
+
+ uv1_triplanar_sharpness = p_sharpness;
+ VS::get_singleton()->material_set_param(_get_material(), shader_names->uv1_blend_sharpness, p_sharpness);
+}
+
+float SpatialMaterial::get_uv1_triplanar_blend_sharpness() const {
+
+ return uv1_triplanar_sharpness;
+}
+
+void SpatialMaterial::set_uv2_scale(const Vector3 &p_scale) {
uv2_scale = p_scale;
VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_scale, p_scale);
}
-Vector2 SpatialMaterial::get_uv2_scale() const {
+Vector3 SpatialMaterial::get_uv2_scale() const {
return uv2_scale;
}
-void SpatialMaterial::set_uv2_offset(const Vector2 &p_offset) {
+void SpatialMaterial::set_uv2_offset(const Vector3 &p_offset) {
uv2_offset = p_offset;
VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_offset, p_offset);
}
-Vector2 SpatialMaterial::get_uv2_offset() const {
+Vector3 SpatialMaterial::get_uv2_offset() const {
return uv2_offset;
}
+void SpatialMaterial::set_uv2_triplanar_blend_sharpness(float p_sharpness) {
+
+ uv2_triplanar_sharpness = p_sharpness;
+ VS::get_singleton()->material_set_param(_get_material(), shader_names->uv2_blend_sharpness, p_sharpness);
+}
+
+float SpatialMaterial::get_uv2_triplanar_blend_sharpness() const {
+
+ return uv2_triplanar_sharpness;
+}
+
void SpatialMaterial::set_billboard_mode(BillboardMode p_mode) {
billboard_mode = p_mode;
@@ -1063,7 +1272,6 @@ void SpatialMaterial::set_depth_deep_parallax(bool p_enable) {
deep_parallax = p_enable;
_queue_shader_change();
_change_notify();
- ;
}
bool SpatialMaterial::is_depth_deep_parallax_enabled() const {
@@ -1091,6 +1299,26 @@ int SpatialMaterial::get_depth_deep_parallax_max_layers() const {
return deep_parallax_max_layers;
}
+void SpatialMaterial::set_grow_enabled(bool p_enable) {
+ grow_enabled = p_enable;
+ _queue_shader_change();
+ _change_notify();
+}
+
+bool SpatialMaterial::is_grow_enabled() const {
+ return grow_enabled;
+}
+
+void SpatialMaterial::set_grow(float p_grow) {
+ grow = p_grow;
+ VS::get_singleton()->material_set_param(_get_material(), shader_names->grow, p_grow);
+}
+
+float SpatialMaterial::get_grow() const {
+
+ return grow;
+}
+
void SpatialMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_albedo", "albedo"), &SpatialMaterial::set_albedo);
@@ -1159,6 +1387,9 @@ void SpatialMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_diffuse_mode", "diffuse_mode"), &SpatialMaterial::set_diffuse_mode);
ClassDB::bind_method(D_METHOD("get_diffuse_mode"), &SpatialMaterial::get_diffuse_mode);
+ ClassDB::bind_method(D_METHOD("set_specular_mode", "specular_mode"), &SpatialMaterial::set_specular_mode);
+ ClassDB::bind_method(D_METHOD("get_specular_mode"), &SpatialMaterial::get_specular_mode);
+
ClassDB::bind_method(D_METHOD("set_flag", "flag", "enable"), &SpatialMaterial::set_flag);
ClassDB::bind_method(D_METHOD("get_flag"), &SpatialMaterial::get_flag);
@@ -1177,12 +1408,18 @@ void SpatialMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_uv1_offset", "offset"), &SpatialMaterial::set_uv1_offset);
ClassDB::bind_method(D_METHOD("get_uv1_offset"), &SpatialMaterial::get_uv1_offset);
+ ClassDB::bind_method(D_METHOD("set_uv1_triplanar_blend_sharpness", "sharpness"), &SpatialMaterial::set_uv1_triplanar_blend_sharpness);
+ ClassDB::bind_method(D_METHOD("get_uv1_triplanar_blend_sharpness"), &SpatialMaterial::get_uv1_triplanar_blend_sharpness);
+
ClassDB::bind_method(D_METHOD("set_uv2_scale", "scale"), &SpatialMaterial::set_uv2_scale);
ClassDB::bind_method(D_METHOD("get_uv2_scale"), &SpatialMaterial::get_uv2_scale);
ClassDB::bind_method(D_METHOD("set_uv2_offset", "offset"), &SpatialMaterial::set_uv2_offset);
ClassDB::bind_method(D_METHOD("get_uv2_offset"), &SpatialMaterial::get_uv2_offset);
+ ClassDB::bind_method(D_METHOD("set_uv2_triplanar_blend_sharpness", "sharpness"), &SpatialMaterial::set_uv2_triplanar_blend_sharpness);
+ ClassDB::bind_method(D_METHOD("get_uv2_triplanar_blend_sharpness"), &SpatialMaterial::get_uv2_triplanar_blend_sharpness);
+
ClassDB::bind_method(D_METHOD("set_billboard_mode", "mode"), &SpatialMaterial::set_billboard_mode);
ClassDB::bind_method(D_METHOD("get_billboard_mode"), &SpatialMaterial::get_billboard_mode);
@@ -1204,6 +1441,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_grow", "amount"), &SpatialMaterial::set_grow);
+ ClassDB::bind_method(D_METHOD("get_grow"), &SpatialMaterial::get_grow);
+
+ ClassDB::bind_method(D_METHOD("set_grow_enabled", "enable"), &SpatialMaterial::set_grow_enabled);
+ ClassDB::bind_method(D_METHOD("is_grow_enabled"), &SpatialMaterial::is_grow_enabled);
+
ADD_GROUP("Flags", "flags_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_transparent"), "set_feature", "get_feature", FEATURE_TRANSPARENT);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "flags_unshaded"), "set_flag", "get_flag", FLAG_UNSHADED);
@@ -1215,13 +1458,16 @@ void SpatialMaterial::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "vertex_color_is_srgb"), "set_flag", "get_flag", FLAG_SRGB_VERTEX_COLOR);
ADD_GROUP("Parameters", "params_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "params_diffuse_mode", PROPERTY_HINT_ENUM, "Lambert,Lambert Wrap,Oren Nayar,Burley"), "set_diffuse_mode", "get_diffuse_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "params_diffuse_mode", PROPERTY_HINT_ENUM, "Lambert,Lambert Wrap,Oren Nayar,Burley,Toon"), "set_diffuse_mode", "get_diffuse_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "params_specular_mode", PROPERTY_HINT_ENUM, "SchlickGGX,Blinn,Phong,Toon,Disabled"), "set_specular_mode", "get_specular_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "params_blend_mode", PROPERTY_HINT_ENUM, "Mix,Add,Sub,Mul"), "set_blend_mode", "get_blend_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "params_cull_mode", PROPERTY_HINT_ENUM, "Back,Front,Disabled"), "set_cull_mode", "get_cull_mode");
ADD_PROPERTY(PropertyInfo(Variant::INT, "params_depth_draw_mode", PROPERTY_HINT_ENUM, "Opaque Only,Always,Never,Opaque Pre-Pass"), "set_depth_draw_mode", "get_depth_draw_mode");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "params_line_width", PROPERTY_HINT_RANGE, "0.1,128,0.1"), "set_line_width", "get_line_width");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "params_point_size", PROPERTY_HINT_RANGE, "0.1,128,0.1"), "set_point_size", "get_point_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "params_billboard_mode", PROPERTY_HINT_ENUM, "Disabled,Enabled,Y-Billboard,Particle Billboard"), "set_billboard_mode", "get_billboard_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "params_grow"), "set_grow_enabled", "is_grow_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "params_grow_amount", PROPERTY_HINT_RANGE, "-16,10,0.01"), "set_grow", "get_grow");
ADD_GROUP("Particles Anim", "particles_anim_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "particles_anim_h_frames", PROPERTY_HINT_RANGE, "1,128,1"), "set_particles_anim_h_frames", "get_particles_anim_h_frames");
ADD_PROPERTY(PropertyInfo(Variant::INT, "particles_anim_v_frames", PROPERTY_HINT_RANGE, "1,128,1"), "set_particles_anim_v_frames", "get_particles_anim_v_frames");
@@ -1271,6 +1517,7 @@ void SpatialMaterial::_bind_methods() {
ADD_GROUP("Ambient Occlusion", "ao_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_enabled"), "set_feature", "get_feature", FEATURE_AMBIENT_OCCLUSION);
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "ao_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_AMBIENT_OCCLUSION);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "ao_on_uv2"), "set_flag", "get_flag", FLAG_AO_ON_UV2);
ADD_GROUP("Depth", "depth_");
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "depth_enabled"), "set_feature", "get_feature", FEATURE_DEPTH_MAPPING);
@@ -1299,12 +1546,16 @@ void SpatialMaterial::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "detail_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture", TEXTURE_DETAIL_NORMAL);
ADD_GROUP("UV1", "uv1_");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv1_scale"), "set_uv1_scale", "get_uv1_scale");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv1_offset"), "set_uv1_offset", "get_uv1_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv1_scale"), "set_uv1_scale", "get_uv1_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv1_offset"), "set_uv1_offset", "get_uv1_offset");
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "uv1_triplanar"), "set_flag", "get_flag", FLAG_UV1_USE_TRIPLANAR);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "uv1_triplanar_sharpness", PROPERTY_HINT_EXP_EASING), "set_uv1_triplanar_blend_sharpness", "get_uv1_triplanar_blend_sharpness");
ADD_GROUP("UV2", "uv2_");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv2_scale"), "set_uv2_scale", "get_uv2_scale");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "uv2_offset"), "set_uv2_offset", "get_uv2_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv2_scale"), "set_uv2_scale", "get_uv2_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "uv2_offset"), "set_uv2_offset", "get_uv2_offset");
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "uv2_triplanar"), "set_flag", "get_flag", FLAG_UV2_USE_TRIPLANAR);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "uv2_triplanar_sharpness", PROPERTY_HINT_EXP_EASING), "set_uv2_triplanar_blend_sharpness", "get_uv2_triplanar_blend_sharpness");
BIND_CONSTANT(TEXTURE_ALBEDO);
BIND_CONSTANT(TEXTURE_METALLIC);
@@ -1365,6 +1616,13 @@ void SpatialMaterial::_bind_methods() {
BIND_CONSTANT(DIFFUSE_HALF_LAMBERT);
BIND_CONSTANT(DIFFUSE_OREN_NAYAR);
BIND_CONSTANT(DIFFUSE_BURLEY);
+ BIND_CONSTANT(DIFFUSE_TOON);
+
+ BIND_CONSTANT(SPECULAR_SCHLICK_GGX);
+ BIND_CONSTANT(SPECULAR_BLINN);
+ BIND_CONSTANT(SPECULAR_PHONG);
+ BIND_CONSTANT(SPECULAR_TOON);
+ BIND_CONSTANT(SPECULAR_DISABLED);
BIND_CONSTANT(BILLBOARD_DISABLED);
BIND_CONSTANT(BILLBOARD_ENABLED);
@@ -1393,15 +1651,20 @@ SpatialMaterial::SpatialMaterial()
set_refraction(0.05);
set_line_width(1);
set_point_size(1);
- set_uv1_offset(Vector2(0, 0));
- set_uv1_scale(Vector2(1, 1));
- set_uv2_offset(Vector2(0, 0));
- set_uv2_scale(Vector2(1, 1));
+ set_uv1_offset(Vector3(0, 0, 0));
+ set_uv1_scale(Vector3(1, 1, 1));
+ set_uv1_triplanar_blend_sharpness(1);
+ set_uv2_offset(Vector3(0, 0, 0));
+ set_uv2_scale(Vector3(1, 1, 1));
+ set_uv2_triplanar_blend_sharpness(1);
set_billboard_mode(BILLBOARD_DISABLED);
set_particles_anim_h_frames(1);
set_particles_anim_v_frames(1);
set_particles_anim_loop(false);
+ grow_enabled = false;
+ set_grow(0.0);
+
deep_parallax = false;
set_depth_deep_parallax_min_layers(8);
set_depth_deep_parallax_max_layers(32);
@@ -1415,6 +1678,7 @@ SpatialMaterial::SpatialMaterial()
flags[i] = 0;
}
diffuse_mode = DIFFUSE_LAMBERT;
+ specular_mode = SPECULAR_SCHLICK_GGX;
for (int i = 0; i < FEATURE_MAX; i++) {
features[i] = false;
diff --git a/scene/resources/material.h b/scene/resources/material.h
index fb6c5b81d9..276064bce4 100644
--- a/scene/resources/material.h
+++ b/scene/resources/material.h
@@ -47,11 +47,16 @@ class Material : public Resource {
OBJ_SAVE_TYPE(Material)
RID material;
+ Ref<Material> next_pass;
protected:
_FORCE_INLINE_ RID _get_material() const { return material; }
+ static void _bind_methods();
public:
+ void set_next_pass(const Ref<Material> &p_pass);
+ Ref<Material> get_next_pass() const;
+
virtual RID get_rid() const;
Material();
virtual ~Material();
@@ -155,6 +160,9 @@ public:
FLAG_SRGB_VERTEX_COLOR,
FLAG_USE_POINT_SIZE,
FLAG_FIXED_SIZE,
+ FLAG_UV1_USE_TRIPLANAR,
+ FLAG_UV2_USE_TRIPLANAR,
+ FLAG_AO_ON_UV2,
FLAG_MAX
};
@@ -163,6 +171,15 @@ public:
DIFFUSE_HALF_LAMBERT,
DIFFUSE_OREN_NAYAR,
DIFFUSE_BURLEY,
+ DIFFUSE_TOON,
+ };
+
+ enum SpecularMode {
+ SPECULAR_SCHLICK_GGX,
+ SPECULAR_BLINN,
+ SPECULAR_PHONG,
+ SPECULAR_TOON,
+ SPECULAR_DISABLED,
};
enum BillboardMode {
@@ -176,20 +193,22 @@ private:
union MaterialKey {
struct {
- uint32_t feature_mask : 11;
- uint32_t detail_uv : 1;
- uint32_t blend_mode : 2;
- uint32_t depth_draw_mode : 2;
- uint32_t cull_mode : 2;
- uint32_t flags : 6;
- uint32_t detail_blend_mode : 2;
- uint32_t diffuse_mode : 2;
- uint32_t invalid_key : 1;
- uint32_t deep_parallax : 1;
- uint32_t billboard_mode : 2;
+ uint64_t feature_mask : 11;
+ uint64_t detail_uv : 1;
+ uint64_t blend_mode : 2;
+ uint64_t depth_draw_mode : 2;
+ uint64_t cull_mode : 2;
+ uint64_t flags : 9;
+ uint64_t detail_blend_mode : 2;
+ uint64_t diffuse_mode : 3;
+ uint64_t specular_mode : 2;
+ uint64_t invalid_key : 1;
+ uint64_t deep_parallax : 1;
+ uint64_t billboard_mode : 2;
+ uint64_t grow : 1;
};
- uint32_t key;
+ uint64_t key;
bool operator<(const MaterialKey &p_key) const {
return key < p_key.key;
@@ -225,9 +244,10 @@ private:
}
mk.detail_blend_mode = detail_blend_mode;
mk.diffuse_mode = diffuse_mode;
+ mk.specular_mode = specular_mode;
mk.billboard_mode = billboard_mode;
mk.deep_parallax = deep_parallax ? 1 : 0;
- ;
+ mk.grow = grow_enabled;
return mk;
}
@@ -258,6 +278,9 @@ private:
StringName particles_anim_loop;
StringName depth_min_layers;
StringName depth_max_layers;
+ StringName uv1_blend_sharpness;
+ StringName uv2_blend_sharpness;
+ StringName grow;
StringName texture_names[TEXTURE_MAX];
};
@@ -289,15 +312,19 @@ private:
float refraction;
float line_width;
float point_size;
+ bool grow_enabled;
+ float grow;
int particles_anim_h_frames;
int particles_anim_v_frames;
bool particles_anim_loop;
- Vector2 uv1_scale;
- Vector2 uv1_offset;
+ Vector3 uv1_scale;
+ Vector3 uv1_offset;
+ float uv1_triplanar_sharpness;
- Vector2 uv2_scale;
- Vector2 uv2_offset;
+ Vector3 uv2_scale;
+ Vector3 uv2_offset;
+ float uv2_triplanar_sharpness;
DetailUV detail_uv;
@@ -310,6 +337,7 @@ private:
DepthDrawMode depth_draw_mode;
CullMode cull_mode;
bool flags[FLAG_MAX];
+ SpecularMode specular_mode;
DiffuseMode diffuse_mode;
BillboardMode billboard_mode;
@@ -402,6 +430,9 @@ public:
void set_diffuse_mode(DiffuseMode p_mode);
DiffuseMode get_diffuse_mode() const;
+ void set_specular_mode(SpecularMode p_mode);
+ SpecularMode get_specular_mode() const;
+
void set_flag(Flags p_flag, bool p_enabled);
bool get_flag(Flags p_flag) const;
@@ -411,17 +442,23 @@ public:
void set_feature(Feature p_feature, bool p_enabled);
bool get_feature(Feature p_feature) const;
- void set_uv1_scale(const Vector2 &p_scale);
- Vector2 get_uv1_scale() const;
+ void set_uv1_scale(const Vector3 &p_scale);
+ Vector3 get_uv1_scale() const;
- void set_uv1_offset(const Vector2 &p_offset);
- Vector2 get_uv1_offset() const;
+ void set_uv1_offset(const Vector3 &p_offset);
+ Vector3 get_uv1_offset() const;
- void set_uv2_scale(const Vector2 &p_scale);
- Vector2 get_uv2_scale() const;
+ void set_uv1_triplanar_blend_sharpness(float p_sharpness);
+ float get_uv1_triplanar_blend_sharpness() const;
- void set_uv2_offset(const Vector2 &p_offset);
- Vector2 get_uv2_offset() const;
+ void set_uv2_scale(const Vector3 &p_scale);
+ Vector3 get_uv2_scale() const;
+
+ void set_uv2_offset(const Vector3 &p_offset);
+ Vector3 get_uv2_offset() const;
+
+ void set_uv2_triplanar_blend_sharpness(float p_sharpness);
+ float get_uv2_triplanar_blend_sharpness() const;
void set_billboard_mode(BillboardMode p_mode);
BillboardMode get_billboard_mode() const;
@@ -434,6 +471,12 @@ public:
void set_particles_anim_loop(int p_frames);
int get_particles_anim_loop() const;
+ void set_grow_enabled(bool p_enable);
+ bool is_grow_enabled() const;
+
+ void set_grow(float p_grow);
+ float get_grow() const;
+
static void init_shaders();
static void finish_shaders();
static void flush_changes();
@@ -450,6 +493,7 @@ VARIANT_ENUM_CAST(SpatialMaterial::DepthDrawMode)
VARIANT_ENUM_CAST(SpatialMaterial::CullMode)
VARIANT_ENUM_CAST(SpatialMaterial::Flags)
VARIANT_ENUM_CAST(SpatialMaterial::DiffuseMode)
+VARIANT_ENUM_CAST(SpatialMaterial::SpecularMode)
VARIANT_ENUM_CAST(SpatialMaterial::BillboardMode)
//////////////////////
diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp
index 36d2a38b3d..9ec89e4003 100644
--- a/scene/resources/world_2d.cpp
+++ b/scene/resources/world_2d.cpp
@@ -32,7 +32,6 @@
#include "servers/visual_server.h"
//#include "servers/spatial_sound_2d_server.h"
#include "global_config.h"
-#include "global_config.h"
#include "scene/2d/camera_2d.h"
#include "scene/2d/visibility_notifier_2d.h"
#include "scene/main/viewport.h"