Fixed particle spread values effecting particle velocity

This commit is contained in:
Rudolph Bester 2023-12-07 06:30:19 +02:00
parent 2f73a059ce
commit 6b2a1b4fdc

View file

@ -740,8 +740,15 @@ void ParticleProcessMaterial::_update_shader() {
code += "vec3 get_random_direction_from_spread(inout uint alt_seed, float spread_angle){\n"; code += "vec3 get_random_direction_from_spread(inout uint alt_seed, float spread_angle){\n";
code += " float pi = 3.14159;\n"; code += " float pi = 3.14159;\n";
code += " float degree_to_rad = pi / 180.0;\n"; code += " float degree_to_rad = pi / 180.0;\n";
code += " vec3 velocity = vec3(0.);\n";
code += " float spread_rad = spread_angle * degree_to_rad;\n"; code += " float spread_rad = spread_angle * degree_to_rad;\n";
if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
// Spread calculation for 2D.
code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
code += " angle1_rad += direction.x != 0.0 ? atan(direction.y, direction.x) : sign(direction.y) * (pi / 2.0);\n";
code += " vec3 spread_direction = vec3(cos(angle1_rad), sin(angle1_rad), 0.0);\n";
code += " return spread_direction;\n";
} else {
// Spread calculation for 3D.
code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n"; code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
code += " float angle2_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad * (1.0 - flatness);\n"; code += " float angle2_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad * (1.0 - flatness);\n";
code += " vec3 direction_xz = vec3(sin(angle1_rad), 0.0, cos(angle1_rad));\n"; code += " vec3 direction_xz = vec3(sin(angle1_rad), 0.0, cos(angle1_rad));\n";
@ -758,8 +765,8 @@ void ParticleProcessMaterial::_update_shader() {
code += " binormal = normalize(binormal);\n"; code += " binormal = normalize(binormal);\n";
code += " vec3 normal = cross(binormal, direction_nrm);\n"; code += " vec3 normal = cross(binormal, direction_nrm);\n";
code += " spread_direction = binormal * spread_direction.x + normal * spread_direction.y + direction_nrm * spread_direction.z;\n"; code += " spread_direction = binormal * spread_direction.x + normal * spread_direction.y + direction_nrm * spread_direction.z;\n";
code += " return spread_direction;\n"; code += " return normalize(spread_direction);\n";
}
code += "}\n"; 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, float delta){\n";