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

Added pic method to update particle velocity

parent c7d03d50
No related branches found
No related tags found
1 merge request!103Added project wobble_bobble and refactored some parts of the framework
...@@ -17,19 +17,29 @@ void main() { ...@@ -17,19 +17,29 @@ void main() {
memoryBarrierImage(); memoryBarrierImage();
if (gl_GlobalInvocationID.x < particles.length()) { if (gl_GlobalInvocationID.x < particles.length()) {
vec3 position = particles[gl_GlobalInvocationID.x].minimal.position; ParticleMinimal minimal = particles[gl_GlobalInvocationID.x].minimal;
float mass = particles[gl_GlobalInvocationID.x].minimal.mass;
vec3 offset = position; ivec3 gridResolution = textureSize(sampler3D(gridImage, gridSampler), 0);
ivec3 gridWindow = ivec3(minimal.size * 2.0f * gridResolution);
vec4 gridSample = texture(sampler3D(gridImage, gridSampler), offset); vec3 velocity_pic = vec3(0.0f);
uint i, j, k;
vec3 gridVelocity = gridSample.xyz; for (i = -gridWindow.x; i <= gridWindow.x; i++) {
float gridMass = gridSample.w; for (j = -gridWindow.y; j <= gridWindow.y; j++) {
for (k = -gridWindow.z; k <= gridWindow.z; k++) {
vec3 voxel = minimal.position + vec3(i, j, k) / gridResolution;
if (gridMass > 0.0f) { if (distance(voxel, minimal.position) < minimal.size * 2.0f) {
particles[gl_GlobalInvocationID.x].minimal.velocity = gridVelocity * mass / gridMass; vec4 gridSample = texture(sampler3D(gridImage, gridSampler), voxel);
velocity_pic += voxel_particle_weight(voxel, minimal) * gridSample.xyz;
}
}
}
} }
particles[gl_GlobalInvocationID.x].minimal.velocity = velocity_pic;
} }
memoryBarrierBuffer(); memoryBarrierBuffer();
......
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