Fixed division by zero in particle process, initial ramp, and amount ratio+scale

This commit is contained in:
QbieShay 2023-10-17 12:06:55 +02:00
parent fd33c7b32f
commit cbf75f9076
1 changed files with 14 additions and 14 deletions

View File

@ -564,7 +564,7 @@ void ParticleProcessMaterial::_update_shader() {
code += " params.lifetime = (1.0 - lifetime_randomness * rand_from_seed(alt_seed));\n";
code += " params.color = color_value;\n";
if (color_initial_ramp.is_valid()) {
code += " params.color = texture(color_initial_ramp, vec2(rand_from_seed(alt_seed)));\n";
code += " params.color *= texture(color_initial_ramp, vec2(rand_from_seed(alt_seed)));\n";
}
if (emission_color_texture.is_valid() && (emission_shape == EMISSION_SHAPE_POINTS || emission_shape == EMISSION_SHAPE_DIRECTED_POINTS)) {
code += " int point = min(emission_texture_point_count - 1, int(rand_from_seed(alt_seed) * float(emission_texture_point_count)));\n";
@ -663,7 +663,7 @@ void ParticleProcessMaterial::_update_shader() {
// No reason to run all these expensive calculation below if we have no orbit velocity
// HOWEVER
// May be a bad idea for fps consistency?
code += "if(abs(param.orbit_velocity) < 0.01){ return vec3(0.0);}\n";
code += "if(abs(param.orbit_velocity) < 0.01 || delta < 0.001){ return vec3(0.0);}\n";
code += "\n";
code += " vec3 displacement = vec3(0.);\n";
code += " float pi = 3.14159;\n";
@ -678,7 +678,7 @@ void ParticleProcessMaterial::_update_shader() {
code += " vec3 pos = transform[3].xyz;\n";
code += " vec3 org = emission_transform[3].xyz;\n";
code += " vec3 diff = pos - org;\n";
code += " float ang = orbit_amount * delta * pi * 2.0;\n";
code += " float ang = orbit_amount * pi * 2.0;\n";
code += " mat2 rot = mat2(vec2(cos(ang), -sin(ang)), vec2(sin(ang), cos(ang)));\n";
code += " displacement.xy -= diff.xy;\n";
code += " displacement.xy += rot * diff.xy;\n";
@ -727,7 +727,7 @@ void ParticleProcessMaterial::_update_shader() {
code += " displacement += new_pos - local_pos;\n";
code += "\n";
}
code += " return (emission_transform * vec4(displacement, 0.0)).xyz;\n";
code += " return (emission_transform * vec4(displacement/delta, 0.0)).xyz;\n";
code += "}\n";
code += "\n";
code += "\n";
@ -758,7 +758,7 @@ void ParticleProcessMaterial::_update_shader() {
code += "}\n";
code += "vec3 process_radial_displacement(DynamicsParameters param, float lifetime, inout uint alt_seed, mat4 transform, mat4 emission_transform, float delta){\n";
code += "vec3 process_radial_displacement(DynamicsParameters param, float lifetime, inout uint alt_seed, mat4 transform, mat4 emission_transform){\n";
code += " vec3 radial_displacement = vec3(0.0);\n";
code += " float radial_displacement_multiplier = 1.0;\n";
if (tex_parameters[PARAM_RADIAL_VELOCITY].is_valid()) {
@ -773,10 +773,10 @@ void ParticleProcessMaterial::_update_shader() {
code += " radial_displacement = normalize(radial_displacement) * min(abs((radial_displacement_multiplier * param.radial_velocity)), length(transform[3].xyz - global_pivot));\n";
code += " }\n";
code += " \n";
code += " return radial_displacement * delta;\n";
code += " return radial_displacement;\n";
code += "}\n";
if (tex_parameters[PARAM_DIRECTIONAL_VELOCITY].is_valid()) {
code += "vec3 process_directional_displacement(DynamicsParameters param, float lifetime_percent,mat4 transform, mat4 emission_transform, float delta){\n";
code += "vec3 process_directional_displacement(DynamicsParameters param, float lifetime_percent,mat4 transform, mat4 emission_transform){\n";
code += " vec3 displacement = vec3(0.);\n";
if (directional_velocity_global) {
code += " displacement = texture(directional_velocity_curve, vec2(lifetime_percent)).xyz * param.directional_velocity;\n";
@ -784,7 +784,7 @@ void ParticleProcessMaterial::_update_shader() {
} else {
code += " displacement = texture(directional_velocity_curve, vec2(lifetime_percent)).xyz * param.directional_velocity;\n";
}
code += " return displacement * delta;\n";
code += " return displacement;\n";
code += "}\n";
}
@ -809,9 +809,6 @@ void ParticleProcessMaterial::_update_shader() {
code += "void start() {\n";
code += " uint base_number = NUMBER;\n";
code += " uint alt_seed = hash(base_number + uint(1) + RANDOM_SEED);\n";
code += " if (rand_from_seed(alt_seed) > AMOUNT_RATIO) {\n";
code += " ACTIVE = false;\n";
code += " }\n";
code += " DisplayParameters params;\n";
code += " calculate_initial_display_params(params, alt_seed);\n";
code += " // reset alt seed?\n";
@ -821,6 +818,9 @@ void ParticleProcessMaterial::_update_shader() {
code += " PhysicalParameters physics_params;\n";
code += " calculate_initial_physical_params(physics_params, alt_seed);\n";
code += " process_display_param(params, 0.0);\n";
code += " if (rand_from_seed(alt_seed) > AMOUNT_RATIO) {\n";
code += " ACTIVE = false;\n";
code += " }\n";
code += " \n";
code += " float pi = 3.14159;\n";
code += " float degree_to_rad = pi / 180.0;\n";
@ -898,10 +898,10 @@ void ParticleProcessMaterial::_update_shader() {
}
code += " // calculate all velocity\n";
code += " \n";
code += " controlled_displacement += process_radial_displacement(dynamic_params, lifetime_percent, alt_seed, TRANSFORM, EMISSION_TRANSFORM, DELTA);\n";
code += " controlled_displacement += process_radial_displacement(dynamic_params, lifetime_percent, alt_seed, TRANSFORM, EMISSION_TRANSFORM);\n";
code += " \n";
if (tex_parameters[PARAM_DIRECTIONAL_VELOCITY].is_valid()) {
code += " controlled_displacement += process_directional_displacement(dynamic_params, lifetime_percent, TRANSFORM, EMISSION_TRANSFORM, DELTA);\n";
code += " controlled_displacement += process_directional_displacement(dynamic_params, lifetime_percent, TRANSFORM, EMISSION_TRANSFORM);\n";
}
code += " \n";
code += " process_physical_parameters(physics_params, lifetime_percent);\n";
@ -973,7 +973,7 @@ void ParticleProcessMaterial::_update_shader() {
code += " ACTIVE = false;\n";
code += " }\n";
}
code += " vec3 final_velocity = controlled_displacement/DELTA + VELOCITY;\n";
code += " vec3 final_velocity = controlled_displacement + VELOCITY;\n";
code += " \n";
code += " // turbulence before limiting\n";
if (turbulence_enabled) {