Merge pull request #51553 from mortarroad/3.x-fix-particle-spread-regressions

[3.x] Fix regressions caused by recent particle spread refactor
This commit is contained in:
Rémi Verschelde 2021-08-12 12:49:04 +02:00 committed by GitHub
commit 9532dc56a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 37 additions and 29 deletions

View File

@ -332,20 +332,23 @@ void ParticlesMaterial::_update_shader() {
code += " float spread_rad = spread * degree_to_rad;\n"; code += " float spread_rad = spread * degree_to_rad;\n";
if (flags[FLAG_DISABLE_Z]) { if (flags[FLAG_DISABLE_Z]) {
code += " {\n";
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 += " angle1_rad += direction.x != 0.0 ? atan(direction.y, direction.x) : sign(direction.y) * (pi / 2.0);\n"; code += " angle1_rad += direction.x != 0.0 ? atan(direction.y, direction.x) : sign(direction.y) * (pi / 2.0);\n";
code += " vec3 rot = vec3(cos(angle1_rad), sin(angle1_rad), 0.0);\n"; code += " vec3 rot = vec3(cos(angle1_rad), sin(angle1_rad), 0.0);\n";
code += " VELOCITY = rot * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);\n"; code += " VELOCITY = rot * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);\n";
code += " }\n";
} else { } else {
//initiate velocity spread in 3D //initiate velocity spread in 3D
code += " {\n";
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";
code += " vec3 direction_yz = vec3(0.0, sin(angle2_rad), cos(angle2_rad));\n"; code += " vec3 direction_yz = vec3(0.0, sin(angle2_rad), cos(angle2_rad));\n";
code += " direction_yz.z = direction_yz.z / max(0.0001,sqrt(abs(direction_yz.z))); // better uniform distribution\n"; code += " direction_yz.z = direction_yz.z / max(0.0001,sqrt(abs(direction_yz.z))); // better uniform distribution\n";
code += " vec3 spread_direction = vec3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);\n"; code += " vec3 spread_direction = vec3(direction_xz.x * direction_yz.z, direction_yz.y, direction_xz.z * direction_yz.z);\n";
code += " vec3 direction_nrm = normalize(direction);\n"; code += " vec3 direction_nrm = length(direction) > 0.0 ? normalize(direction) : vec3(0.0, 0.0, 1.0);\n";
code += " // rotate spread to direction\n"; code += " // rotate spread to direction\n";
code += " vec3 binormal = cross(vec3(0.0, 1.0, 0.0), direction_nrm);\n"; code += " vec3 binormal = cross(vec3(0.0, 1.0, 0.0), direction_nrm);\n";
code += " if (length(binormal) < 0.0001) {\n"; code += " if (length(binormal) < 0.0001) {\n";
@ -356,6 +359,7 @@ void ParticlesMaterial::_update_shader() {
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 += " VELOCITY = spread_direction * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);\n"; code += " VELOCITY = spread_direction * initial_linear_velocity * mix(1.0, rand_from_seed(alt_seed), initial_linear_velocity_random);\n";
code += " }\n";
} }
code += " float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random);\n"; code += " float base_angle = (initial_angle + tex_angle) * mix(1.0, angle_rand, initial_angle_random);\n";
@ -383,16 +387,20 @@ void ParticlesMaterial::_update_shader() {
if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) { if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
if (flags[FLAG_DISABLE_Z]) { if (flags[FLAG_DISABLE_Z]) {
code += " {\n";
code += " mat2 rotm;"; code += " mat2 rotm;";
code += " rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xy;\n"; code += " rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xy;\n";
code += " rotm[1] = rotm[0].yx * vec2(1.0, -1.0);\n"; code += " rotm[1] = rotm[0].yx * vec2(1.0, -1.0);\n";
code += " VELOCITY.xy = rotm * VELOCITY.xy;\n"; code += " VELOCITY.xy = rotm * VELOCITY.xy;\n";
code += " }\n";
} else { } else {
code += " {\n";
code += " vec3 normal = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xyz;\n"; code += " vec3 normal = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xyz;\n";
code += " vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);\n"; code += " vec3 v0 = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(0.0, 1.0, 0.0);\n";
code += " vec3 tangent = normalize(cross(v0, normal));\n"; code += " vec3 tangent = normalize(cross(v0, normal));\n";
code += " vec3 bitangent = normalize(cross(tangent, normal));\n"; code += " vec3 bitangent = normalize(cross(tangent, normal));\n";
code += " VELOCITY = mat3(tangent, bitangent, normal) * VELOCITY;\n"; code += " VELOCITY = mat3(tangent, bitangent, normal) * VELOCITY;\n";
code += " }\n";
} }
} }
} break; } break;