From 85ce4a67ed37a2b38bc6d9e3f0211a9b73a8516d Mon Sep 17 00:00:00 2001 From: JFonS Date: Thu, 27 Sep 2018 13:05:57 +0200 Subject: Remove animation loop from ParticlesMaterial + improvements to CPUParticles2D Remove animation loop from ParticlesMaterial and move it to SpatialMaterial for 3D particles and Particles2D for the 2D case. Added animation to CPUParticles2D as well as the "Convert to CPUParticles2D" to the PAarticles2D menu. --- scene/resources/material.cpp | 12 ++++++------ scene/resources/material.h | 4 ++-- scene/resources/particles_material.cpp | 7 ------- scene/resources/particles_material.h | 1 - 4 files changed, 8 insertions(+), 16 deletions(-) (limited to 'scene/resources') diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index c3030ee741..a9d7b2adf7 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -612,7 +612,7 @@ void SpatialMaterial::_update_shader() { //handle animation code += "\tfloat particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n"; code += "\tfloat particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; - code += "\tif (particles_anim_loop) particle_frame=clamp(particle_frame,0.0,particle_total_frames-1.0); else particle_frame=mod(particle_frame,float(particle_total_frames));\n"; + code += "\tif (!particles_anim_loop) particle_frame=clamp(particle_frame,0.0,particle_total_frames-1.0); else particle_frame=mod(particle_frame,float(particle_total_frames));\n"; code += "\tUV /= vec2(float(particles_anim_h_frames),float(particles_anim_v_frames));\n"; code += "\tUV += vec2(mod(particle_frame,float(particles_anim_h_frames)) / float(particles_anim_h_frames), floor(particle_frame / float(particles_anim_h_frames)) / float(particles_anim_v_frames));\n"; } break; @@ -1541,13 +1541,13 @@ int SpatialMaterial::get_particles_anim_v_frames() const { return particles_anim_v_frames; } -void SpatialMaterial::set_particles_anim_loop(int p_frames) { +void SpatialMaterial::set_particles_anim_loop(bool p_loop) { - particles_anim_loop = p_frames; - VS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, p_frames); + particles_anim_loop = p_loop; + VS::get_singleton()->material_set_param(_get_material(), shader_names->particles_anim_loop, particles_anim_loop); } -int SpatialMaterial::get_particles_anim_loop() const { +bool SpatialMaterial::get_particles_anim_loop() const { return particles_anim_loop; } @@ -1898,7 +1898,7 @@ void SpatialMaterial::_bind_methods() { ClassDB::bind_method(D_METHOD("set_particles_anim_v_frames", "frames"), &SpatialMaterial::set_particles_anim_v_frames); ClassDB::bind_method(D_METHOD("get_particles_anim_v_frames"), &SpatialMaterial::get_particles_anim_v_frames); - ClassDB::bind_method(D_METHOD("set_particles_anim_loop", "frames"), &SpatialMaterial::set_particles_anim_loop); + ClassDB::bind_method(D_METHOD("set_particles_anim_loop", "loop"), &SpatialMaterial::set_particles_anim_loop); ClassDB::bind_method(D_METHOD("get_particles_anim_loop"), &SpatialMaterial::get_particles_anim_loop); ClassDB::bind_method(D_METHOD("set_depth_deep_parallax", "enable"), &SpatialMaterial::set_depth_deep_parallax); diff --git a/scene/resources/material.h b/scene/resources/material.h index cf4d19b5a7..49b4a79d92 100644 --- a/scene/resources/material.h +++ b/scene/resources/material.h @@ -574,8 +574,8 @@ public: void set_particles_anim_v_frames(int p_frames); int get_particles_anim_v_frames() const; - void set_particles_anim_loop(int p_frames); - int get_particles_anim_loop() const; + void set_particles_anim_loop(bool p_loop); + bool get_particles_anim_loop() const; void set_grow_enabled(bool p_enable); bool is_grow_enabled() const; diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp index ba48982fda..dacbe168fd 100644 --- a/scene/resources/particles_material.cpp +++ b/scene/resources/particles_material.cpp @@ -463,12 +463,6 @@ void ParticlesMaterial::_update_shader() { code += " base_angle += CUSTOM.y * LIFETIME * (angular_velocity + tex_angular_velocity) * mix(1.0, rand_from_seed(alt_seed) * 2.0 - 1.0, angular_velocity_random);\n"; code += " CUSTOM.x = base_angle * degree_to_rad;\n"; // angle code += " CUSTOM.z = (anim_offset + tex_anim_offset) * mix(1.0, anim_offset_rand, anim_offset_random) + CUSTOM.y * (anim_speed + tex_anim_speed) * mix(1.0, rand_from_seed(alt_seed), anim_speed_random);\n"; // angle - if (flags[FLAG_ANIM_LOOP]) { - code += " CUSTOM.z = mod(CUSTOM.z, 1.0);\n"; // loop - - } else { - code += " CUSTOM.z = clamp(CUSTOM.z, 0.0, 1.0);\n"; // 0 to 1 only - } code += " }\n"; // apply color // apply hue rotation @@ -1175,7 +1169,6 @@ void ParticlesMaterial::_bind_methods() { ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anim_offset", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param", "get_param", PARAM_ANIM_OFFSET); ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anim_offset_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", PARAM_ANIM_OFFSET); ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "anim_offset_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", PARAM_ANIM_OFFSET); - ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "anim_loop"), "set_flag", "get_flag", FLAG_ANIM_LOOP); BIND_ENUM_CONSTANT(PARAM_INITIAL_LINEAR_VELOCITY); BIND_ENUM_CONSTANT(PARAM_ANGULAR_VELOCITY); diff --git a/scene/resources/particles_material.h b/scene/resources/particles_material.h index 91fdcc0346..06ebb3c4dc 100644 --- a/scene/resources/particles_material.h +++ b/scene/resources/particles_material.h @@ -60,7 +60,6 @@ public: FLAG_ALIGN_Y_TO_VELOCITY, FLAG_ROTATE_Y, FLAG_DISABLE_Z, - FLAG_ANIM_LOOP, FLAG_MAX }; -- cgit v1.2.3