diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2023-10-26 08:57:59 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-10-26 08:57:59 +0200 |
| commit | 8835db5f37bd06e3186a5122ac11c81d82103afd (patch) | |
| tree | 6f5f1a60aadbec79165d875e0633211cda65de6b | |
| parent | 79e9e201e89a0bc0bf971b275124a3b7dfc33b58 (diff) | |
| parent | cc14e0092a980ed096efc757ed4b6f60d3acefd1 (diff) | |
| download | redot-engine-8835db5f37bd06e3186a5122ac11c81d82103afd.tar.gz | |
Merge pull request #83881 from jsjtxietian/fix-generated-particle-shader-use-noise-direction-before-define
Fix `noise_direction` variable used before initialized in particle shader when using turbulence with collisions
| -rw-r--r-- | scene/resources/particle_process_material.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/scene/resources/particle_process_material.cpp b/scene/resources/particle_process_material.cpp index 9ceddbc7b1..6075db4ffb 100644 --- a/scene/resources/particle_process_material.cpp +++ b/scene/resources/particle_process_material.cpp @@ -985,10 +985,6 @@ void ParticleProcessMaterial::_update_shader() { code += " VELOCITY = mix(VELOCITY,vec3(0.0),clamp(collision_friction, 0.0, 1.0));\n"; code += " } else {\n"; code += " VELOCITY = vec3(0.0);\n"; - // If turbulence is enabled, set the noise direction to up so the turbulence color is "neutral" - if (turbulence_enabled) { - code += " noise_direction = vec3(1.0, 0.0, 0.0);\n"; - } code += " }\n"; code += " }\n"; } else if (collision_mode == COLLISION_HIDE_ON_CONTACT) { @@ -1007,14 +1003,16 @@ void ParticleProcessMaterial::_update_shader() { } code += " \n"; code += " vec3 noise_direction = get_noise_direction(TRANSFORM[3].xyz);\n"; - // The following snippet causes massive performance hit. We don't need it as long as collision is disabled. - // Refer to GH-83744 for more info. - if (collision_mode != COLLISION_DISABLED) { + + // Godot detects when the COLLIDED keyword is used. If it's used anywhere in the shader then Godot will generate the screen space SDF for collisions. + // We don't need it as long as collision is disabled. Refer to GH-83744 for more info. + if (collision_mode == COLLISION_RIGID) { code += " if (!COLLIDED) {\n"; - code += " \n"; - code += " float vel_mag = length(final_velocity);\n"; - code += " float vel_infl = clamp(dynamic_params.turb_influence * turbulence_influence, 0.0,1.0);\n"; - code += " final_velocity = mix(final_velocity, normalize(noise_direction) * vel_mag * (1.0 + (1.0 - vel_infl) * 0.2), vel_infl);\n"; + } + code += " float vel_mag = length(final_velocity);\n"; + code += " float vel_infl = clamp(dynamic_params.turb_influence * turbulence_influence, 0.0,1.0);\n"; + code += " final_velocity = mix(final_velocity, normalize(noise_direction) * vel_mag * (1.0 + (1.0 - vel_infl) * 0.2), vel_infl);\n"; + if (collision_mode == COLLISION_RIGID) { code += " }\n"; } } |
