Skip to content

Commit

Permalink
Change curve range for particle multipliers
Browse files Browse the repository at this point in the history
Fixes godotengine#91404
Curves are applied as a multiplier, so ranges [-1, 1] or [0, 1] make much more sense than ranges like [-360, 360] or [0, 100]. The actual range is selected with separate min and max parameters.
  • Loading branch information
aXu-AP committed May 4, 2024
1 parent 7ebc866 commit 302a20e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 82 deletions.
45 changes: 14 additions & 31 deletions scene/2d/cpu_particles_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,42 +342,25 @@ void CPUParticles2D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curv
curve_parameters[p_param] = p_curve;

switch (p_param) {
case PARAM_INITIAL_LINEAR_VELOCITY: {
//do none for this one
} break;
case PARAM_ANGULAR_VELOCITY: {
_adjust_curve_range(p_curve, -360, 360);
} break;
case PARAM_ORBIT_VELOCITY: {
_adjust_curve_range(p_curve, -500, 500);
} break;
case PARAM_LINEAR_ACCEL: {
_adjust_curve_range(p_curve, -200, 200);
} break;
case PARAM_RADIAL_ACCEL: {
_adjust_curve_range(p_curve, -200, 200);
} break;
case PARAM_TANGENTIAL_ACCEL: {
_adjust_curve_range(p_curve, -200, 200);
} break;
case PARAM_DAMPING: {
_adjust_curve_range(p_curve, 0, 100);
} break;
case PARAM_ANGLE: {
_adjust_curve_range(p_curve, -360, 360);
} break;
case PARAM_SCALE: {
} break;
case PARAM_ANGULAR_VELOCITY:
case PARAM_ORBIT_VELOCITY:
case PARAM_LINEAR_ACCEL:
case PARAM_RADIAL_ACCEL:
case PARAM_TANGENTIAL_ACCEL:
case PARAM_ANGLE:
case PARAM_HUE_VARIATION: {
_adjust_curve_range(p_curve, -1, 1);
} break;
case PARAM_ANIM_SPEED: {
_adjust_curve_range(p_curve, 0, 200);
} break;
case PARAM_DAMPING:
case PARAM_SCALE:
case PARAM_ANIM_SPEED:
case PARAM_ANIM_OFFSET: {
_adjust_curve_range(p_curve, 0, 1);
} break;
case PARAM_INITIAL_LINEAR_VELOCITY:
case PARAM_MAX: {
// No curve available.
} break;
default: {
}
}

update_configuration_warnings();
Expand Down
45 changes: 14 additions & 31 deletions scene/3d/cpu_particles_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,42 +324,25 @@ void CPUParticles3D::set_param_curve(Parameter p_param, const Ref<Curve> &p_curv
curve_parameters[p_param] = p_curve;

switch (p_param) {
case PARAM_INITIAL_LINEAR_VELOCITY: {
//do none for this one
} break;
case PARAM_ANGULAR_VELOCITY: {
_adjust_curve_range(p_curve, -360, 360);
} break;
case PARAM_ORBIT_VELOCITY: {
_adjust_curve_range(p_curve, -500, 500);
} break;
case PARAM_LINEAR_ACCEL: {
_adjust_curve_range(p_curve, -200, 200);
} break;
case PARAM_RADIAL_ACCEL: {
_adjust_curve_range(p_curve, -200, 200);
} break;
case PARAM_TANGENTIAL_ACCEL: {
_adjust_curve_range(p_curve, -200, 200);
} break;
case PARAM_DAMPING: {
_adjust_curve_range(p_curve, 0, 100);
} break;
case PARAM_ANGLE: {
_adjust_curve_range(p_curve, -360, 360);
} break;
case PARAM_SCALE: {
} break;
case PARAM_ANGULAR_VELOCITY:
case PARAM_ORBIT_VELOCITY:
case PARAM_LINEAR_ACCEL:
case PARAM_RADIAL_ACCEL:
case PARAM_TANGENTIAL_ACCEL:
case PARAM_ANGLE:
case PARAM_HUE_VARIATION: {
_adjust_curve_range(p_curve, -1, 1);
} break;
case PARAM_ANIM_SPEED: {
_adjust_curve_range(p_curve, 0, 200);
} break;
case PARAM_DAMPING:
case PARAM_SCALE:
case PARAM_ANIM_SPEED:
case PARAM_ANIM_OFFSET: {
_adjust_curve_range(p_curve, 0, 1);
} break;
case PARAM_INITIAL_LINEAR_VELOCITY:
case PARAM_MAX: {
// No curve available.
} break;
default: {
}
}

update_configuration_warnings();
Expand Down
38 changes: 18 additions & 20 deletions scene/resources/particle_process_material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,37 +1407,34 @@ void ParticleProcessMaterial::set_param_texture(Parameter p_param, const Ref<Tex
Variant tex_rid = p_texture.is_valid() ? Variant(p_texture->get_rid()) : Variant();

switch (p_param) {
case PARAM_INITIAL_LINEAR_VELOCITY: {
//do none for this one
} break;
case PARAM_ANGULAR_VELOCITY: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angular_velocity_texture, tex_rid);
_adjust_curve_range(p_texture, -360, 360);
_adjust_curve_range(p_texture, -1, 1);
} break;
case PARAM_ORBIT_VELOCITY: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->orbit_velocity_texture, tex_rid);
_adjust_curve_range(p_texture, -2, 2);
_adjust_curve_range(p_texture, -1, 1);
notify_property_list_changed();
} break;
case PARAM_LINEAR_ACCEL: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->linear_accel_texture, tex_rid);
_adjust_curve_range(p_texture, -200, 200);
_adjust_curve_range(p_texture, -1, 1);
} break;
case PARAM_RADIAL_ACCEL: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_accel_texture, tex_rid);
_adjust_curve_range(p_texture, -200, 200);
_adjust_curve_range(p_texture, -1, 1);
} break;
case PARAM_TANGENTIAL_ACCEL: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->tangent_accel_texture, tex_rid);
_adjust_curve_range(p_texture, -200, 200);
_adjust_curve_range(p_texture, -1, 1);
} break;
case PARAM_DAMPING: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->damping_texture, tex_rid);
_adjust_curve_range(p_texture, 0, 100);
_adjust_curve_range(p_texture, 0, 1);
} break;
case PARAM_ANGLE: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_texture, tex_rid);
_adjust_curve_range(p_texture, -360, 360);
_adjust_curve_range(p_texture, -1, 1);
} break;
case PARAM_SCALE: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_texture, tex_rid);
Expand All @@ -1449,35 +1446,36 @@ void ParticleProcessMaterial::set_param_texture(Parameter p_param, const Ref<Tex
} break;
case PARAM_ANIM_SPEED: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_speed_texture, tex_rid);
_adjust_curve_range(p_texture, 0, 200);
_adjust_curve_range(p_texture, 0, 1);
} break;
case PARAM_ANIM_OFFSET: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->anim_offset_texture, tex_rid);
_adjust_curve_range(p_texture, 0, 1);
} break;
case PARAM_TURB_INFLUENCE_OVER_LIFE: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->turbulence_influence_over_life, tex_rid);
_adjust_curve_range(p_texture, 0, 1);
} break;
case PARAM_TURB_VEL_INFLUENCE: {
// Can't happen, but silences warning
} break;
case PARAM_TURB_INIT_DISPLACEMENT: {
// Can't happen, but silences warning
} break;
case PARAM_RADIAL_VELOCITY: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->radial_velocity_texture, tex_rid);
_adjust_curve_range(p_texture, 0, 1);
} break;
case PARAM_SCALE_OVER_VELOCITY: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_over_velocity_texture, tex_rid);
_adjust_curve_range(p_texture, 0, 3);
_adjust_curve_range(p_texture, 0, 1);
notify_property_list_changed();
} break;
case PARAM_DIRECTIONAL_VELOCITY: {
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->directional_velocity_texture, tex_rid);
_adjust_curve_range(p_texture, 0, 1);
notify_property_list_changed();
} break;
case PARAM_MAX:
break; // Can't happen, but silences warning
case PARAM_INITIAL_LINEAR_VELOCITY:
case PARAM_TURB_VEL_INFLUENCE:
case PARAM_TURB_INIT_DISPLACEMENT:
case PARAM_MAX: {
// No curve available.
} break;
}

_queue_shader_change();
Expand Down

0 comments on commit 302a20e

Please sign in to comment.