Skip to content
Snippets Groups Projects
Verified Commit f74c7a39 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Replaced check for zero with checks for NaN

parent 15be258b
No related branches found
No related tags found
1 merge request!103Added project wobble_bobble and refactored some parts of the framework
...@@ -56,76 +56,27 @@ float weight_C(float x) { ...@@ -56,76 +56,27 @@ float weight_C(float x) {
} }
float voxel_particle_weight(vec3 voxel, ParticleMinimal particle) { float voxel_particle_weight(vec3 voxel, ParticleMinimal particle) {
if (particle.size <= 0.0f) { vec3 delta = abs(particle.position - voxel) / particle.size;
if (any(isnan(delta)) || any(isinf(delta))) {
return 0.0f; return 0.0f;
} }
vec3 delta = abs(particle.position - voxel) / particle.size;
vec3 weight = vec3( vec3 weight = vec3(
weight_C(delta.x), weight_C(delta.x),
weight_C(delta.y), weight_C(delta.y),
weight_C(delta.z) weight_C(delta.z)
); );
return ( float result = (
weight.x * weight.y * weight.z weight.x * weight.y * weight.z
) / particle.weight_sum; ) / particle.weight_sum;
}
if ((isnan(result)) || (isinf(result))) {
float grad_weight_A(float x) {
return -1.0f;
}
float grad_weight_B(float x) {
if (x < 0.5f) {
return -2.0f * x;
} else
if (x < 1.5f) {
return -1.5f + x;
} else {
return 0.0f; return 0.0f;
}
}
float grad_weight_C(float x) {
if (x < 1.0f) {
return 1.5f * x * x - 2.0f * x;
} else
if (x < 2.0f) {
float y = (2.0f - x);
return -0.5f * y * y;
} else { } else {
return 0.0f; return result;
} }
} }
vec3 voxel_particle_grad_weight(vec3 voxel, ParticleMinimal particle) {
if (particle.size <= 0.0f) {
return vec3(0.0f);
}
vec3 sign_delta = (particle.position - voxel) / particle.size;
vec3 delta = abs(sign_delta);
vec3 sign = sign(sign_delta);
vec3 weight = vec3(
weight_C(delta.x),
weight_C(delta.y),
weight_C(delta.z)
);
vec3 grad_weight = vec3(
grad_weight_C(delta.x),
grad_weight_C(delta.y),
grad_weight_C(delta.z)
) * sign / particle.size;
return vec3(
grad_weight.x * weight.y * weight.z,
grad_weight.y * weight.z * weight.x,
grad_weight.z * weight.x * weight.y
) / particle.weight_sum;
}
#endif // PARTICLE_INC #endif // PARTICLE_INC
\ No newline at end of file
...@@ -61,8 +61,10 @@ void main() { ...@@ -61,8 +61,10 @@ void main() {
memoryBarrierShared(); memoryBarrierShared();
} }
if (gridValue.w > 0.0f) { gridValue.xyz /= gridValue.w;
gridValue.xyz /= gridValue.w;
if (any(isnan(gridValue.xyz)) || any(isinf(gridValue.xyz))) {
gridValue.xyz = vec3(0.0f);
} }
barrier(); barrier();
......
...@@ -33,7 +33,6 @@ void main() { ...@@ -33,7 +33,6 @@ void main() {
const vec3 gridResolution = vec3(imageSize(gridImage)); const vec3 gridResolution = vec3(imageSize(gridImage));
const vec3 position = (vec3(gl_GlobalInvocationID) + vec3(0.5f)) / gridResolution; const vec3 position = (vec3(gl_GlobalInvocationID) + vec3(0.5f)) / gridResolution;
const float h3 = 1.0f / gridResolution.x / gridResolution.y / gridResolution.z;
vec4 gridSample = imageLoad( vec4 gridSample = imageLoad(
gridImage, gridImage,
...@@ -47,7 +46,7 @@ void main() { ...@@ -47,7 +46,7 @@ void main() {
memoryBarrierBuffer(); memoryBarrierBuffer();
if (mass > 0.0f) { if (mass > 0.0f) {
velocity += vec3(0.0f, -9.81f * dt * 0.0f, 0.0f); velocity += vec3(0.0f, -9.81f * dt, 0.0f);
} }
bvec3 lowerID = lessThanEqual(gl_GlobalInvocationID, ivec3(0)); bvec3 lowerID = lessThanEqual(gl_GlobalInvocationID, ivec3(0));
......
...@@ -79,12 +79,12 @@ void main() { ...@@ -79,12 +79,12 @@ void main() {
mat3 D_inv = inverse(affine_D); mat3 D_inv = inverse(affine_D);
float J = determinant(F); float J = determinant(F);
if ((J > 0.0f) && (mass > 0.0f)) { if (J > 0.0f) {
mat3 F_T = transpose(F); mat3 F_T = transpose(F);
mat3 delta = lame2 * (F * F_T - mat3(1.0f)) + lame1 * log(J); mat3 delta = lame2 * (F * F_T - mat3(1.0f)) + lame1 * log(J);
mls_Q += beta * dt * volume * delta * D_inv; mls_Q -= beta * dt * volume * delta * D_inv;
} }
affine_C = affine_B * D_inv; affine_C = affine_B * D_inv;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment