summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/collision_shape_2d.cpp22
-rw-r--r--scene/2d/cpu_particles_2d.cpp20
-rw-r--r--scene/2d/cpu_particles_2d.h4
-rw-r--r--scene/2d/ray_cast_2d.cpp19
-rw-r--r--scene/3d/cpu_particles.cpp20
-rw-r--r--scene/3d/cpu_particles.h4
-rw-r--r--scene/gui/graph_node.cpp4
-rw-r--r--scene/gui/line_edit.cpp8
-rw-r--r--scene/register_scene_types.cpp1
-rw-r--r--scene/resources/particles_material.cpp30
-rw-r--r--scene/resources/particles_material.h7
-rw-r--r--scene/resources/visual_shader.cpp41
-rw-r--r--scene/resources/visual_shader.h4
-rw-r--r--scene/resources/visual_shader_nodes.cpp92
-rw-r--r--scene/resources/visual_shader_nodes.h19
15 files changed, 267 insertions, 28 deletions
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index 5440a1d8c3..f79d79d039 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -97,15 +97,8 @@ void CollisionShape2D::_notification(int p_what) {
}
owner_id = 0;
parent = NULL;
- } break;
- /*
- case NOTIFICATION_TRANSFORM_CHANGED: {
-
- if (!is_inside_scene())
- break;
- _update_parent();
- } break;*/
+ } break;
case NOTIFICATION_DRAW: {
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint()) {
@@ -131,10 +124,13 @@ void CollisionShape2D::_notification(int p_what) {
rect = rect.grow(3);
if (one_way_collision) {
- Color dcol = get_tree()->get_debug_collisions_color(); //0.9,0.2,0.2,0.4);
- dcol.a = 1.0;
+ // Draw an arrow indicating the one-way collision direction
+ draw_col = get_tree()->get_debug_collisions_color().inverted();
+ if (disabled) {
+ draw_col = draw_col.darkened(0.25);
+ }
Vector2 line_to(0, 20);
- draw_line(Vector2(), line_to, dcol, 3);
+ draw_line(Vector2(), line_to, draw_col, 2, true);
Vector<Vector2> pts;
float tsize = 8;
pts.push_back(line_to + (Vector2(0, tsize)));
@@ -142,9 +138,9 @@ void CollisionShape2D::_notification(int p_what) {
pts.push_back(line_to + (Vector2(-0.707 * tsize, 0)));
Vector<Color> cols;
for (int i = 0; i < 3; i++)
- cols.push_back(dcol);
+ cols.push_back(draw_col);
- draw_primitive(pts, cols, Vector<Vector2>()); //small arrow
+ draw_primitive(pts, cols, Vector<Vector2>());
}
} break;
}
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index 591933d972..1bddc4d22f 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -83,6 +83,10 @@ void CPUParticles2D::set_randomness_ratio(float p_ratio) {
randomness_ratio = p_ratio;
}
+void CPUParticles2D::set_lifetime_randomness(float p_random) {
+
+ lifetime_randomness = p_random;
+}
void CPUParticles2D::set_use_local_coordinates(bool p_enable) {
local_coords = p_enable;
@@ -123,6 +127,10 @@ float CPUParticles2D::get_randomness_ratio() const {
return randomness_ratio;
}
+float CPUParticles2D::get_lifetime_randomness() const {
+
+ return lifetime_randomness;
+}
bool CPUParticles2D::get_use_local_coordinates() const {
@@ -611,6 +619,10 @@ void CPUParticles2D::_particles_process(float p_delta) {
}
}
+ if (p.time * (1.0 - explosiveness_ratio) > p.lifetime) {
+ restart = true;
+ }
+
if (restart) {
if (!emitting) {
@@ -654,6 +666,7 @@ void CPUParticles2D::_particles_process(float p_delta) {
p.custom[3] = 0.0;
p.transform = Transform2D();
p.time = 0;
+ p.lifetime = lifetime * (1.0 - Math::randf() * lifetime_randomness);
p.base_color = Color(1, 1, 1, 1);
switch (emission_shape) {
@@ -696,6 +709,8 @@ void CPUParticles2D::_particles_process(float p_delta) {
} else if (!p.active) {
continue;
+ } else if (p.time > p.lifetime) {
+ p.active = false;
} else {
uint32_t alt_seed = p.seed;
@@ -1153,6 +1168,7 @@ void CPUParticles2D::convert_from_particles(Node *p_particles) {
Vector2 gravity = Vector2(material->get_gravity().x, material->get_gravity().y);
set_gravity(gravity);
+ set_lifetime_randomness(material->get_lifetime_randomness());
#define CONVERT_PARAM(m_param) \
set_param(m_param, material->get_param(ParticlesMaterial::m_param)); \
@@ -1187,6 +1203,7 @@ void CPUParticles2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles2D::set_pre_process_time);
ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles2D::set_explosiveness_ratio);
ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles2D::set_randomness_ratio);
+ ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles2D::set_lifetime_randomness);
ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles2D::set_use_local_coordinates);
ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles2D::set_fixed_fps);
ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles2D::set_fractional_delta);
@@ -1199,6 +1216,7 @@ void CPUParticles2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles2D::get_pre_process_time);
ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles2D::get_explosiveness_ratio);
ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles2D::get_randomness_ratio);
+ ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles2D::get_lifetime_randomness);
ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles2D::get_use_local_coordinates);
ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles2D::get_fixed_fps);
ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles2D::get_fractional_delta);
@@ -1225,6 +1243,7 @@ void CPUParticles2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
ADD_GROUP("Drawing", "");
@@ -1404,6 +1423,7 @@ CPUParticles2D::CPUParticles2D() {
set_pre_process_time(0);
set_explosiveness_ratio(0);
set_randomness_ratio(0);
+ set_lifetime_randomness(0);
set_use_local_coordinates(true);
set_draw_order(DRAW_ORDER_INDEX);
diff --git a/scene/2d/cpu_particles_2d.h b/scene/2d/cpu_particles_2d.h
index 8613a185b4..1cd22df9e7 100644
--- a/scene/2d/cpu_particles_2d.h
+++ b/scene/2d/cpu_particles_2d.h
@@ -96,6 +96,7 @@ private:
float hue_rot_rand;
float anim_offset_rand;
float time;
+ float lifetime;
Color base_color;
uint32_t seed;
@@ -139,6 +140,7 @@ private:
float pre_process_time;
float explosiveness_ratio;
float randomness_ratio;
+ float lifetime_randomness;
float speed_scale;
bool local_coords;
int fixed_fps;
@@ -200,6 +202,7 @@ public:
void set_pre_process_time(float p_time);
void set_explosiveness_ratio(float p_ratio);
void set_randomness_ratio(float p_ratio);
+ void set_lifetime_randomness(float p_random);
void set_visibility_aabb(const Rect2 &p_aabb);
void set_use_local_coordinates(bool p_enable);
void set_speed_scale(float p_scale);
@@ -211,6 +214,7 @@ public:
float get_pre_process_time() const;
float get_explosiveness_ratio() const;
float get_randomness_ratio() const;
+ float get_lifetime_randomness() const;
Rect2 get_visibility_aabb() const;
bool get_use_local_coordinates() const;
float get_speed_scale() const;
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index 57dfe5176d..bf8d008bb2 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -100,6 +100,7 @@ Vector2 RayCast2D::get_collision_normal() const {
void RayCast2D::set_enabled(bool p_enabled) {
enabled = p_enabled;
+ update();
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint())
set_physics_process_internal(p_enabled);
if (!p_enabled)
@@ -167,19 +168,25 @@ void RayCast2D::_notification(int p_what) {
xf.rotate(cast_to.angle());
xf.translate(Vector2(cast_to.length(), 0));
- //Vector2 tip = Vector2(0,s->get_length());
- Color dcol = get_tree()->get_debug_collisions_color(); //0.9,0.2,0.2,0.4);
- draw_line(Vector2(), cast_to, dcol, 3);
+ // Draw an arrow indicating where the RayCast is pointing to
+ Color draw_col = get_tree()->get_debug_collisions_color();
+ if (!enabled) {
+ float g = draw_col.get_v();
+ draw_col.r = g;
+ draw_col.g = g;
+ draw_col.b = g;
+ }
+ draw_line(Vector2(), cast_to, draw_col, 2, true);
Vector<Vector2> pts;
- float tsize = 4;
+ float tsize = 8;
pts.push_back(xf.xform(Vector2(tsize, 0)));
pts.push_back(xf.xform(Vector2(0, 0.707 * tsize)));
pts.push_back(xf.xform(Vector2(0, -0.707 * tsize)));
Vector<Color> cols;
for (int i = 0; i < 3; i++)
- cols.push_back(dcol);
+ cols.push_back(draw_col);
- draw_primitive(pts, cols, Vector<Vector2>()); //small arrow
+ draw_primitive(pts, cols, Vector<Vector2>());
} break;
diff --git a/scene/3d/cpu_particles.cpp b/scene/3d/cpu_particles.cpp
index 86b407b9e6..7ab7363c7c 100644
--- a/scene/3d/cpu_particles.cpp
+++ b/scene/3d/cpu_particles.cpp
@@ -92,6 +92,10 @@ void CPUParticles::set_randomness_ratio(float p_ratio) {
randomness_ratio = p_ratio;
}
+void CPUParticles::set_lifetime_randomness(float p_random) {
+
+ lifetime_randomness = p_random;
+}
void CPUParticles::set_use_local_coordinates(bool p_enable) {
local_coords = p_enable;
@@ -130,6 +134,10 @@ float CPUParticles::get_randomness_ratio() const {
return randomness_ratio;
}
+float CPUParticles::get_lifetime_randomness() const {
+
+ return lifetime_randomness;
+}
bool CPUParticles::get_use_local_coordinates() const {
@@ -583,6 +591,10 @@ void CPUParticles::_particles_process(float p_delta) {
}
}
+ if (p.time * (1.0 - explosiveness_ratio) > p.lifetime) {
+ restart = true;
+ }
+
if (restart) {
if (!emitting) {
@@ -636,6 +648,7 @@ void CPUParticles::_particles_process(float p_delta) {
p.custom[2] = (parameters[PARAM_ANIM_OFFSET] + tex_anim_offset) * Math::lerp(1.0f, p.anim_offset_rand, randomness[PARAM_ANIM_OFFSET]); //animation offset (0-1)
p.transform = Transform();
p.time = 0;
+ p.lifetime = lifetime * (1.0 - Math::randf() * lifetime_randomness);
p.base_color = Color(1, 1, 1, 1);
switch (emission_shape) {
@@ -701,6 +714,8 @@ void CPUParticles::_particles_process(float p_delta) {
} else if (!p.active) {
continue;
+ } else if (p.time > p.lifetime) {
+ p.active = false;
} else {
uint32_t alt_seed = p.seed;
@@ -1221,6 +1236,7 @@ void CPUParticles::convert_from_particles(Node *p_particles) {
set_emission_box_extents(material->get_emission_box_extents());
set_gravity(material->get_gravity());
+ set_lifetime_randomness(material->get_lifetime_randomness());
#define CONVERT_PARAM(m_param) \
set_param(m_param, material->get_param(ParticlesMaterial::m_param)); \
@@ -1255,6 +1271,7 @@ void CPUParticles::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pre_process_time", "secs"), &CPUParticles::set_pre_process_time);
ClassDB::bind_method(D_METHOD("set_explosiveness_ratio", "ratio"), &CPUParticles::set_explosiveness_ratio);
ClassDB::bind_method(D_METHOD("set_randomness_ratio", "ratio"), &CPUParticles::set_randomness_ratio);
+ ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "random"), &CPUParticles::set_lifetime_randomness);
ClassDB::bind_method(D_METHOD("set_use_local_coordinates", "enable"), &CPUParticles::set_use_local_coordinates);
ClassDB::bind_method(D_METHOD("set_fixed_fps", "fps"), &CPUParticles::set_fixed_fps);
ClassDB::bind_method(D_METHOD("set_fractional_delta", "enable"), &CPUParticles::set_fractional_delta);
@@ -1267,6 +1284,7 @@ void CPUParticles::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_pre_process_time"), &CPUParticles::get_pre_process_time);
ClassDB::bind_method(D_METHOD("get_explosiveness_ratio"), &CPUParticles::get_explosiveness_ratio);
ClassDB::bind_method(D_METHOD("get_randomness_ratio"), &CPUParticles::get_randomness_ratio);
+ ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &CPUParticles::get_lifetime_randomness);
ClassDB::bind_method(D_METHOD("get_use_local_coordinates"), &CPUParticles::get_use_local_coordinates);
ClassDB::bind_method(D_METHOD("get_fixed_fps"), &CPUParticles::get_fixed_fps);
ClassDB::bind_method(D_METHOD("get_fractional_delta"), &CPUParticles::get_fractional_delta);
@@ -1290,6 +1308,7 @@ void CPUParticles::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "speed_scale", PROPERTY_HINT_RANGE, "0,64,0.01"), "set_speed_scale", "get_speed_scale");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness_ratio", "get_explosiveness_ratio");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_randomness_ratio", "get_randomness_ratio");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_fps", PROPERTY_HINT_RANGE, "0,1000,1"), "set_fixed_fps", "get_fixed_fps");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fract_delta"), "set_fractional_delta", "get_fractional_delta");
ADD_GROUP("Drawing", "");
@@ -1472,6 +1491,7 @@ CPUParticles::CPUParticles() {
set_pre_process_time(0);
set_explosiveness_ratio(0);
set_randomness_ratio(0);
+ set_lifetime_randomness(0);
set_use_local_coordinates(true);
set_draw_order(DRAW_ORDER_INDEX);
diff --git a/scene/3d/cpu_particles.h b/scene/3d/cpu_particles.h
index 517df8490d..71de56f59e 100644
--- a/scene/3d/cpu_particles.h
+++ b/scene/3d/cpu_particles.h
@@ -95,6 +95,7 @@ private:
float hue_rot_rand;
float anim_offset_rand;
float time;
+ float lifetime;
Color base_color;
uint32_t seed;
@@ -137,6 +138,7 @@ private:
float pre_process_time;
float explosiveness_ratio;
float randomness_ratio;
+ float lifetime_randomness;
float speed_scale;
bool local_coords;
int fixed_fps;
@@ -200,6 +202,7 @@ public:
void set_pre_process_time(float p_time);
void set_explosiveness_ratio(float p_ratio);
void set_randomness_ratio(float p_ratio);
+ void set_lifetime_randomness(float p_random);
void set_visibility_aabb(const AABB &p_aabb);
void set_use_local_coordinates(bool p_enable);
void set_speed_scale(float p_scale);
@@ -211,6 +214,7 @@ public:
float get_pre_process_time() const;
float get_explosiveness_ratio() const;
float get_randomness_ratio() const;
+ float get_lifetime_randomness() const;
AABB get_visibility_aabb() const;
bool get_use_local_coordinates() const;
float get_speed_scale() const;
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 6463ee5ad5..222c75b21d 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -599,6 +599,8 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
Vector2 mpos = Vector2(mb->get_position().x, mb->get_position().y);
if (close_rect.size != Size2() && close_rect.has_point(mpos)) {
+ //send focus to parent
+ get_parent_control()->grab_focus();
emit_signal("close_request");
accept_event();
return;
@@ -615,9 +617,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) {
return;
}
- //send focus to parent
emit_signal("raise_request");
- get_parent_control()->grab_focus();
}
if (!mb->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 3dcbf64e7c..d5347edb87 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -999,6 +999,8 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
Ref<StyleBox> style = get_stylebox("normal");
int pixel_ofs = 0;
Size2 size = get_size();
+ bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled;
+ int r_icon_width = Control::get_icon("clear")->get_width();
switch (align) {
@@ -1013,10 +1015,16 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) {
pixel_ofs = int(style->get_offset().x);
else
pixel_ofs = int(size.width - (cached_width)) / 2;
+
+ if (display_clear_icon)
+ pixel_ofs -= int(r_icon_width / 2 + style->get_margin(MARGIN_RIGHT));
} break;
case ALIGN_RIGHT: {
pixel_ofs = int(size.width - style->get_margin(MARGIN_RIGHT) - (cached_width));
+
+ if (display_clear_icon)
+ pixel_ofs -= int(r_icon_width + style->get_margin(MARGIN_RIGHT));
} break;
}
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index 9a21da7479..2533d91156 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -522,6 +522,7 @@ void register_scene_types() {
ClassDB::register_class<VisualShaderNodeVec3Uniform>();
ClassDB::register_class<VisualShaderNodeTransformUniform>();
ClassDB::register_class<VisualShaderNodeTextureUniform>();
+ ClassDB::register_class<VisualShaderNodeTextureUniformTriplanar>();
ClassDB::register_class<VisualShaderNodeCubeMapUniform>();
ClassDB::register_class<VisualShaderNodeIf>();
ClassDB::register_class<VisualShaderNodeSwitch>();
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index b4818755b4..dc6ef2b49c 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -101,6 +101,8 @@ void ParticlesMaterial::init_shaders() {
shader_names->trail_color_modifier = "trail_color_modifier";
shader_names->gravity = "gravity";
+
+ shader_names->lifetime_randomness = "lifetime_randomness";
}
void ParticlesMaterial::finish_shaders() {
@@ -173,6 +175,7 @@ void ParticlesMaterial::_update_shader() {
code += "uniform float hue_variation_random;\n";
code += "uniform float anim_speed_random;\n";
code += "uniform float anim_offset_random;\n";
+ code += "uniform float lifetime_randomness;\n";
switch (emission_shape) {
case EMISSION_SHAPE_POINT: {
@@ -285,7 +288,11 @@ void ParticlesMaterial::_update_shader() {
code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
}
- code += " if (RESTART) {\n";
+ code += " bool restart = false;\n";
+ code += " if (CUSTOM.y > CUSTOM.w) {\n";
+ code += " restart = true;\n";
+ code += " }\n\n";
+ code += " if (RESTART || restart) {\n";
if (tex_parameters[PARAM_INITIAL_LINEAR_VELOCITY].is_valid())
code += " float tex_linear_velocity = textureLod(linear_velocity_texture, vec2(0.0, 0.0), 0.0).r;\n";
@@ -325,6 +332,7 @@ void ParticlesMaterial::_update_shader() {
code += " float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random);\n";
code += " CUSTOM.x = base_angle * degree_to_rad;\n"; // angle
code += " CUSTOM.y = 0.0;\n"; // phase
+ code += " CUSTOM.w = LIFETIME * (1.0 - lifetime_randomness * rand_from_seed(alt_seed));\n";
code += " CUSTOM.z = (anim_offset + tex_anim_offset) * mix(1.0, anim_offset_rand, anim_offset_random);\n"; // animation offset (0-1)
switch (emission_shape) {
@@ -576,6 +584,9 @@ void ParticlesMaterial::_update_shader() {
code += " VELOCITY.z = 0.0;\n";
code += " TRANSFORM[3].z = 0.0;\n";
}
+ code += " if (CUSTOM.y > CUSTOM.w) {";
+ code += " ACTIVE = false;\n";
+ code += " }\n";
code += "}\n";
code += "\n";
@@ -1014,6 +1025,17 @@ Vector3 ParticlesMaterial::get_gravity() const {
return gravity;
}
+void ParticlesMaterial::set_lifetime_randomness(float p_lifetime) {
+
+ lifetime_randomness = p_lifetime;
+ VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->lifetime_randomness, lifetime_randomness);
+}
+
+float ParticlesMaterial::get_lifetime_randomness() const {
+
+ return lifetime_randomness;
+}
+
RID ParticlesMaterial::get_shader_rid() const {
ERR_FAIL_COND_V(!shader_map.has(current_key), RID());
@@ -1118,6 +1140,11 @@ void ParticlesMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_gravity"), &ParticlesMaterial::get_gravity);
ClassDB::bind_method(D_METHOD("set_gravity", "accel_vec"), &ParticlesMaterial::set_gravity);
+ ClassDB::bind_method(D_METHOD("set_lifetime_randomness", "randomness"), &ParticlesMaterial::set_lifetime_randomness);
+ ClassDB::bind_method(D_METHOD("get_lifetime_randomness"), &ParticlesMaterial::get_lifetime_randomness);
+
+ ADD_GROUP("Time", "");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "lifetime_randomness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_lifetime_randomness", "get_lifetime_randomness");
ADD_GROUP("Trail", "trail_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "trail_divisor", PROPERTY_HINT_RANGE, "1,1000000,1"), "set_trail_divisor", "get_trail_divisor");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "trail_size_modifier", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_trail_size_modifier", "get_trail_size_modifier");
@@ -1240,6 +1267,7 @@ ParticlesMaterial::ParticlesMaterial() :
set_emission_box_extents(Vector3(1, 1, 1));
set_trail_divisor(1);
set_gravity(Vector3(0, -9.8, 0));
+ set_lifetime_randomness(0);
emission_point_count = 1;
for (int i = 0; i < PARAM_MAX; i++) {
diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h
index 7f11bd794b..6fe381db0a 100644
--- a/scene/resources/particles_material.h
+++ b/scene/resources/particles_material.h
@@ -185,6 +185,8 @@ private:
StringName trail_color_modifier;
StringName gravity;
+
+ StringName lifetime_randomness;
};
static ShaderNames *shader_names;
@@ -225,6 +227,8 @@ private:
Vector3 gravity;
+ float lifetime_randomness;
+
//do not save emission points here
protected:
@@ -287,6 +291,9 @@ public:
void set_gravity(const Vector3 &p_gravity);
Vector3 get_gravity() const;
+ void set_lifetime_randomness(float p_lifetime);
+ float get_lifetime_randomness() const;
+
static void init_shaders();
static void finish_shaders();
static void flush_changes();
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index 7265c9b457..8475a34818 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -67,6 +67,14 @@ String VisualShaderNode::generate_global(Shader::Mode p_mode, VisualShader::Type
return String();
}
+String VisualShaderNode::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+ return String();
+}
+
+String VisualShaderNode::generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+ return String();
+}
+
Vector<StringName> VisualShaderNode::get_editable_properties() const {
return Vector<StringName>();
}
@@ -449,7 +457,10 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
ERR_FAIL_COND_V(node->get_output_port_type(p_port) == VisualShaderNode::PORT_TYPE_TRANSFORM, String());
StringBuilder global_code;
+ StringBuilder global_code_per_node;
+ Map<Type, StringBuilder> global_code_per_func;
StringBuilder code;
+ Set<StringName> classes;
global_code += String() + "shader_type canvas_item;\n";
@@ -474,7 +485,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
code += "\nvoid fragment() {\n";
Set<int> processed;
- Error err = _write_node(p_type, global_code, code, default_tex_params, input_connections, output_connections, p_node, processed, true);
+ Error err = _write_node(p_type, global_code, global_code_per_node, global_code_per_func, code, default_tex_params, input_connections, output_connections, p_node, processed, true, classes);
ERR_FAIL_COND_V(err != OK, String());
if (node->get_output_port_type(p_port) == VisualShaderNode::PORT_TYPE_SCALAR) {
@@ -489,6 +500,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
//set code secretly
global_code += "\n\n";
String final_code = global_code;
+ final_code += global_code_per_node;
final_code += code;
return final_code;
}
@@ -833,7 +845,7 @@ void VisualShader::_get_property_list(List<PropertyInfo> *p_list) const {
}
}
-Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBuilder &code, Vector<VisualShader::DefaultTextureParam> &def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &output_connections, int node, Set<int> &processed, bool for_preview) const {
+Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBuilder &global_code_per_node, Map<Type, StringBuilder> &global_code_per_func, StringBuilder &code, Vector<VisualShader::DefaultTextureParam> &def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &output_connections, int node, Set<int> &processed, bool for_preview, Set<StringName> &r_classes) const {
const Ref<VisualShaderNode> vsnode = graph[type].nodes[node].node;
@@ -850,7 +862,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
continue;
}
- Error err = _write_node(type, global_code, code, def_tex_params, input_connections, output_connections, from_node, processed, for_preview);
+ Error err = _write_node(type, global_code, global_code_per_node, global_code_per_func, code, def_tex_params, input_connections, output_connections, from_node, processed, for_preview, r_classes);
if (err)
return err;
}
@@ -958,6 +970,14 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
if (!skip_global) {
global_code += vsnode->generate_global(get_mode(), type, node);
+
+ if (!r_classes.has(vsnode->get_class_name())) {
+ global_code_per_node += vsnode->generate_global_per_node(get_mode(), type, node);
+ for (int i = 0; i < TYPE_MAX; i++) {
+ global_code_per_func[Type(i)] += vsnode->generate_global_per_func(get_mode(), Type(i), node);
+ }
+ r_classes.insert(vsnode->get_class_name());
+ }
}
//handle normally
@@ -976,8 +996,12 @@ void VisualShader::_update_shader() const {
dirty = false;
StringBuilder global_code;
+ StringBuilder global_code_per_node;
+ Map<Type, StringBuilder> global_code_per_func;
StringBuilder code;
Vector<VisualShader::DefaultTextureParam> default_tex_params;
+ Set<StringName> classes;
+ List<int> insertion_pos;
static const char *shader_mode_str[Shader::MODE_MAX] = { "spatial", "canvas_item", "particles" };
global_code += String() + "shader_type " + shader_mode_str[shader_mode] + ";\n";
@@ -1056,8 +1080,9 @@ void VisualShader::_update_shader() const {
code += "\nvoid " + String(func_name[i]) + "() {\n";
Set<int> processed;
- Error err = _write_node(Type(i), global_code, code, default_tex_params, input_connections, output_connections, NODE_ID_OUTPUT, processed, false);
+ Error err = _write_node(Type(i), global_code, global_code_per_node, global_code_per_func, code, default_tex_params, input_connections, output_connections, NODE_ID_OUTPUT, processed, false, classes);
ERR_FAIL_COND(err != OK);
+ insertion_pos.push_back(code.get_string_length());
code += "}\n";
}
@@ -1065,7 +1090,13 @@ void VisualShader::_update_shader() const {
//set code secretly
global_code += "\n\n";
String final_code = global_code;
- final_code += code;
+ final_code += global_code_per_node;
+ String tcode = code;
+ for (int i = 0; i < TYPE_MAX; i++) {
+ tcode = tcode.insert(insertion_pos[i], global_code_per_func[Type(i)]);
+ }
+ final_code += tcode;
+
const_cast<VisualShader *>(this)->set_code(final_code);
for (int i = 0; i < default_tex_params.size(); i++) {
const_cast<VisualShader *>(this)->set_default_texture_param(default_tex_params[i].name, default_tex_params[i].param);
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index 83db51b1b0..b3c0ab6e0b 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -103,7 +103,7 @@ private:
}
};
- Error _write_node(Type p_type, StringBuilder &global_code, StringBuilder &code, Vector<DefaultTextureParam> &def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &output_connections, int node, Set<int> &processed, bool for_preview) const;
+ Error _write_node(Type p_type, StringBuilder &global_code, StringBuilder &global_code_per_node, Map<Type, StringBuilder> &global_code_per_func, StringBuilder &code, Vector<DefaultTextureParam> &def_tex_params, const VMap<ConnectionKey, const List<Connection>::Element *> &input_connections, const VMap<ConnectionKey, const List<Connection>::Element *> &output_connections, int node, Set<int> &processed, bool for_preview, Set<StringName> &r_classes) const;
void _input_type_changed(Type p_type, int p_id);
@@ -208,6 +208,8 @@ public:
virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
+ virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
+ virtual String generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const = 0; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
virtual String get_warning(Shader::Mode p_mode, VisualShader::Type p_type) const;
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 235b56b0ce..06f18472ce 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -2968,6 +2968,98 @@ VisualShaderNodeTextureUniform::VisualShaderNodeTextureUniform() {
color_default = COLOR_DEFAULT_WHITE;
}
+////////////// Texture Uniform (Triplanar)
+
+String VisualShaderNodeTextureUniformTriplanar::get_caption() const {
+ return "TextureUniformTriplanar";
+}
+
+int VisualShaderNodeTextureUniformTriplanar::get_input_port_count() const {
+ return 2;
+}
+
+VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniformTriplanar::get_input_port_type(int p_port) const {
+ if (p_port == 0) {
+ return PORT_TYPE_VECTOR;
+ } else if (p_port == 1) {
+ return PORT_TYPE_VECTOR;
+ }
+ return PORT_TYPE_SCALAR;
+}
+
+String VisualShaderNodeTextureUniformTriplanar::get_input_port_name(int p_port) const {
+ if (p_port == 0) {
+ return "weights";
+ } else if (p_port == 1) {
+ return "pos";
+ }
+ return "";
+}
+
+String VisualShaderNodeTextureUniformTriplanar::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+
+ String code;
+
+ code += "// TRIPLANAR FUNCTION GLOBAL CODE\n";
+ code += "\tvec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) {\n";
+ code += "\t\tvec4 samp = vec4(0.0);\n";
+ code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z;\n";
+ code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y;\n";
+ code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x;\n";
+ code += "\t\treturn samp;\n";
+ code += "\t}\n";
+ code += "\n";
+ code += "\tuniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0);\n";
+ code += "\tuniform vec3 triplanar_offset;\n";
+ code += "\tuniform float triplanar_sharpness = 0.5;\n";
+ code += "\n";
+ code += "\tvarying vec3 triplanar_power_normal;\n";
+ code += "\tvarying vec3 triplanar_pos;\n";
+
+ return code;
+}
+
+String VisualShaderNodeTextureUniformTriplanar::generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+
+ String code;
+
+ if (p_type == VisualShader::TYPE_VERTEX) {
+
+ code += "\t// TRIPLANAR FUNCTION VERTEX CODE\n";
+ code += "\t\ttriplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness));\n";
+ code += "\t\ttriplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0));\n";
+ code += "\t\ttriplanar_pos = VERTEX * triplanar_scale + triplanar_offset;\n";
+ code += "\t\ttriplanar_pos *= vec3(1.0, -1.0, 1.0);\n";
+ }
+
+ return code;
+}
+
+String VisualShaderNodeTextureUniformTriplanar::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
+
+ String id = get_uniform_name();
+ String code = "\t{\n";
+
+ if (p_input_vars[0] == String() && p_input_vars[1] == String()) {
+ code += "\t\tvec4 n_tex_read = triplanar_texture( " + id + ", triplanar_power_normal, triplanar_pos );\n";
+ } else if (p_input_vars[0] != String() && p_input_vars[1] == String()) {
+ code += "\t\tvec4 n_tex_read = triplanar_texture( " + id + ", " + p_input_vars[0] + ", triplanar_pos );\n";
+ } else if (p_input_vars[0] == String() && p_input_vars[1] != String()) {
+ code += "\t\tvec4 n_tex_read = triplanar_texture( " + id + ", triplanar_power_normal," + p_input_vars[1] + " );\n";
+ } else {
+ code += "\t\tvec4 n_tex_read = triplanar_texture( " + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + " );\n";
+ }
+
+ code += "\t\t" + p_output_vars[0] + " = n_tex_read.rgb;\n";
+ code += "\t\t" + p_output_vars[1] + " = n_tex_read.a;\n";
+ code += "\t}\n";
+
+ return code;
+}
+
+VisualShaderNodeTextureUniformTriplanar::VisualShaderNodeTextureUniformTriplanar() {
+}
+
////////////// CubeMap Uniform
String VisualShaderNodeCubeMapUniform::get_caption() const {
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index dca0ebe033..cafc7a0f00 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -1425,6 +1425,25 @@ VARIANT_ENUM_CAST(VisualShaderNodeTextureUniform::ColorDefault)
///////////////////////////////////////
+class VisualShaderNodeTextureUniformTriplanar : public VisualShaderNodeTextureUniform {
+ GDCLASS(VisualShaderNodeTextureUniformTriplanar, VisualShaderNodeTextureUniform);
+
+public:
+ virtual String get_caption() const;
+
+ virtual int get_input_port_count() const;
+ virtual PortType get_input_port_type(int p_port) const;
+ virtual String get_input_port_name(int p_port) const;
+
+ virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
+ virtual String generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
+ virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const; //if no output is connected, the output var passed will be empty. if no input is connected and input is NIL, the input var passed will be empty
+
+ VisualShaderNodeTextureUniformTriplanar();
+};
+
+///////////////////////////////////////
+
class VisualShaderNodeCubeMapUniform : public VisualShaderNode {
GDCLASS(VisualShaderNodeCubeMapUniform, VisualShaderNode);