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

Outsourced function voxel_particle_weight() into header for shaders

parent 06f5d24c
No related branches found
No related tags found
1 merge request!103Added project wobble_bobble and refactored some parts of the framework
......@@ -13,4 +13,42 @@ struct Particle {
mat4 deformation;
};
float weight_A(float x) {
return max(1.0f - x, 0.0f);
}
float weight_B(float x) {
if (x < 0.5f) {
return 0.75f - x * x;
} else
if (x < 1.5f) {
float y = (1.5f - x);
return 0.5f * y * y;
} else {
return 0.0f;
}
}
float weight_C(float x) {
if (x < 1.0f) {
return (0.5f * x - 1.0f) * x*x + 2.0f / 3.0f;
} else
if (x < 2.0f) {
float y = (2.0f - x);
return 0.5f / 3.0f * y * y * y;
} else {
return 0.0f;
}
}
float voxel_particle_weight(vec3 voxel, ParticleMinimal particle) {
if (particle.size <= 0.0f) {
return 0.0f;
}
vec3 delta = abs(particle.position - voxel) / particle.size;
return weight_C(delta.x) * weight_C(delta.y) * weight_C(delta.z);
}
#endif // PARTICLE_INC
\ No newline at end of file
......@@ -11,34 +11,6 @@ layout(set=0, binding=0, std430) buffer particleBuffer {
layout(set=0, binding=1, rgba32f) restrict writeonly uniform image3D gridImage;
float weight_A(float x) {
return max(1.0f - x, 0.0f);
}
float weight_B(float x) {
if (x < 0.5f) {
return 0.75f - x * x;
} else
if (x < 1.5f) {
float y = (1.5f - x);
return 0.5f * y * y;
} else {
return 0.0f;
}
}
float weight_C(float x) {
if (x < 1.0f) {
return (0.5f * x - 1.0f) * x*x + 2.0f / 3.0f;
} else
if (x < 2.0f) {
float y = (2.0f - x);
return 0.5f / 3.0f * y * y * y;
} else {
return 0.0f;
}
}
#define SHARED_PARTICLES_BATCH_SIZE 64
shared ParticleMinimal shared_particles [SHARED_PARTICLES_BATCH_SIZE];
......@@ -64,12 +36,10 @@ void main() {
memoryBarrierShared();
for (uint i = 0; i < SHARED_PARTICLES_BATCH_SIZE; i++) {
float s = shared_particles[i].size;
float x = distance(shared_particles[i].position, position);
if (x < 2.0f * s) {
gridValue += vec4(shared_particles[i].velocity, shared_particles[i].mass) * weight_C(x / s);
}
gridValue += (
vec4(shared_particles[i].velocity, shared_particles[i].mass) *
voxel_particle_weight(position, shared_particles[i])
);
}
}
......
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