summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-05-31 14:16:46 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-05-31 14:16:46 +0200
commit8b044da3967b654e97c769b2222b713bf4992bc2 (patch)
tree07be38f3bad87e31ab2e165f91c0a0ce65bedbe6 /drivers
parent138f334316d4d2ef6c1c1bdb53cb57a005282395 (diff)
parentf666c76a9cd19b1e9b8d45d6c069e65d6fd6ec3f (diff)
downloadredot-engine-8b044da3967b654e97c769b2222b713bf4992bc2.tar.gz
Merge pull request #92474 from Rudolph-B/fix-collided-particles-jittering
Fix collided 3D GPU particles sometimes jittering
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gles3/shaders/particles.glsl14
1 files changed, 8 insertions, 6 deletions
diff --git a/drivers/gles3/shaders/particles.glsl b/drivers/gles3/shaders/particles.glsl
index 096f0a57ae..2591937a1d 100644
--- a/drivers/gles3/shaders/particles.glsl
+++ b/drivers/gles3/shaders/particles.glsl
@@ -372,10 +372,10 @@ void main() {
float d = vec4_to_float(texture(height_field_texture, uv_pos)) * SDF_MAX_LENGTH;
+ // Allowing for a small epsilon to allow particle just touching colliders to count as collided
+ const float EPSILON = 0.001;
d -= sdf_particle_size;
-
- if (d < 0.0) {
- const float EPSILON = 0.001;
+ if (d < EPSILON) {
vec2 n = normalize(vec2(
vec4_to_float(texture(height_field_texture, uv_pos + vec2(EPSILON, 0.0))) - vec4_to_float(texture(height_field_texture, uv_pos - vec2(EPSILON, 0.0))),
vec4_to_float(texture(height_field_texture, uv_pos + vec2(0.0, EPSILON))) - vec4_to_float(texture(height_field_texture, uv_pos - vec2(0.0, EPSILON)))));
@@ -400,10 +400,12 @@ void main() {
vec3 rel_vec = xform[3].xyz - colliders[i].transform[3].xyz;
vec3 local_pos = rel_vec * mat3(colliders[i].transform);
+ // Allowing for a small epsilon to allow particle just touching colliders to count as collided
+ const float EPSILON = 0.001;
if (colliders[i].type == COLLIDER_TYPE_SPHERE) {
float d = length(rel_vec) - (particle_size + colliders[i].extents.x);
- if (d < 0.0) {
+ if (d < EPSILON) {
col = true;
depth = -d;
normal = normalize(rel_vec);
@@ -418,7 +420,7 @@ void main() {
vec3 closest = min(abs_pos, colliders[i].extents.xyz);
vec3 rel = abs_pos - closest;
depth = length(rel) - particle_size;
- if (depth < 0.0) {
+ if (depth < EPSILON) {
col = true;
normal = mat3(colliders[i].transform) * (normalize(rel) * sgn_pos);
depth = -depth;
@@ -453,7 +455,7 @@ void main() {
float y = 1.0 - texture(height_field_texture, uvw_pos.xz).r;
- if (y > uvw_pos.y) {
+ if (y + EPSILON > uvw_pos.y) {
//inside heightfield
vec3 pos1 = (vec3(uvw_pos.x, y, uvw_pos.z) * 2.0 - 1.0) * colliders[i].extents.xyz;