summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRémi Verschelde <remi@verschelde.fr>2023-10-24 11:39:17 +0200
committerGitHub <noreply@github.com>2023-10-24 11:39:17 +0200
commite8d57afaeccf0d9f9726746f49936eb93aa0039b (patch)
tree2b8e63d61438b0ddc82ce1aa3aae75687f1a7654
parentea0ab441c836091f3ede370d88b5fe1453b7a653 (diff)
parent49fee5bc288c0264728940213d26bb38c54b4b8d (diff)
downloadredot-engine-e8d57afaeccf0d9f9726746f49936eb93aa0039b.tar.gz
Merge pull request #83831 from QbieShay/qbe/fix-normal-point
Particles: Fix directed points not working, and fix friction formula
-rw-r--r--scene/resources/particle_process_material.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/scene/resources/particle_process_material.cpp b/scene/resources/particle_process_material.cpp
index ed87468db6..9ceddbc7b1 100644
--- a/scene/resources/particle_process_material.cpp
+++ b/scene/resources/particle_process_material.cpp
@@ -850,6 +850,27 @@ void ParticleProcessMaterial::_update_shader() {
code += " }\n";
code += " if (RESTART_VELOCITY) {\n";
code += " VELOCITY = get_random_direction_from_spread(alt_seed, spread) * dynamic_params.initial_velocity_multiplier;\n";
+ if (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";
+ code += " ivec2 emission_tex_size = textureSize(emission_texture_points, 0);\n";
+ code += " ivec2 emission_tex_ofs = ivec2(point % emission_tex_size.x, point / emission_tex_size.x);\n";
+ if (particle_flags[PARTICLE_FLAG_DISABLE_Z]) {
+ code += " {\n";
+ code += " mat2 rotm;";
+ 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 += " VELOCITY.xy = rotm * VELOCITY.xy;\n";
+ code += " }\n";
+ } else {
+ code += " {\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 tangent = normalize(cross(v0, normal));\n";
+ code += " vec3 bitangent = normalize(cross(tangent, normal));\n";
+ code += " VELOCITY = mat3(tangent, bitangent, normal) * VELOCITY;\n";
+ code += " }\n";
+ }
+ }
code += " }\n";
code += " process_display_param(params, 0.);\n";
code += "// process_dynamic_parameters(dynamic_params, 0., alt_seed, TRANSFORM, EMISSION_TRANSFORM, DELTA);\n";
@@ -939,7 +960,9 @@ void ParticleProcessMaterial::_update_shader() {
code += " if (physics_params.damping > 0.0) {\n";
if (!particle_flags[PARTICLE_FLAG_DAMPING_AS_FRICTION]) {
code += " float v = length(VELOCITY);\n";
- code += " v -= physics_params.damping * DELTA;\n";
+ code += " // Realistic friction formula. We assume the mass of a particle to be 0.05kg.\n";
+ code += " float damp = v * v * physics_params.damping * 0.05 * DELTA;\n";
+ code += " v -= damp;\n";
code += " if (v < 0.0) {\n";
code += " VELOCITY = vec3(0.0);\n";
code += " } else {\n";