Only update particle velocity when it changes

(cherry picked from commit cb0a37f61a)
This commit is contained in:
kobewi 2023-12-23 18:04:24 +01:00 committed by Yuri Sizov
parent 89fd2c30e1
commit a1c32a9462
4 changed files with 16 additions and 6 deletions

View File

@ -712,12 +712,15 @@ void GPUParticles2D::_notification(int p_what) {
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
RS::get_singleton()->particles_set_emitter_velocity(particles,
Vector3((get_global_position() - previous_position).x,
(get_global_position() - previous_position).y,
0.0) /
get_process_delta_time());
const Vector3 velocity = Vector3((get_global_position() - previous_position).x, (get_global_position() - previous_position).y, 0.0) /
get_process_delta_time();
if (velocity != previous_velocity) {
RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
previous_velocity = velocity;
}
previous_position = get_global_position();
if (one_shot) {
time += get_process_delta_time();
if (time > emission_time) {

View File

@ -64,6 +64,7 @@ private:
bool fractional_delta = false;
bool interpolate = true;
float interp_to_end_factor = 0;
Vector3 previous_velocity;
Vector2 previous_position;
#ifdef TOOLS_ENABLED
bool show_visibility_rect = false;

View File

@ -460,7 +460,12 @@ void GPUParticles3D::_notification(int p_what) {
// Use internal process when emitting and one_shot is on so that when
// the shot ends the editor can properly update.
case NOTIFICATION_INTERNAL_PROCESS: {
RS::get_singleton()->particles_set_emitter_velocity(particles, (get_global_position() - previous_position) / get_process_delta_time());
const Vector3 velocity = (get_global_position() - previous_position) / get_process_delta_time();
if (velocity != previous_velocity) {
RS::get_singleton()->particles_set_emitter_velocity(particles, velocity);
previous_velocity = velocity;
}
previous_position = get_global_position();
if (one_shot) {

View File

@ -95,6 +95,7 @@ private:
double emission_time = 0.0;
double active_time = 0.0;
float interp_to_end_factor = 0;
Vector3 previous_velocity;
Vector3 previous_position;
void _attach_sub_emitter();