[MetaballsKit] Finish off Metal compute stuff for the simulation

This commit is contained in:
Eryn Wells 2017-08-04 08:06:33 -07:00
parent 467f9d4123
commit da5c664ee6
2 changed files with 95 additions and 18 deletions

View file

@ -9,6 +9,12 @@
#include <metal_stdlib>
using namespace metal;
typedef struct {
int2 size;
int numberOfBalls;
} Parameters;
// TODO: This is a dupe of the Ball struct. Is there a way to DRY this?
typedef struct {
float radius;
float2 position;
@ -16,14 +22,15 @@ typedef struct {
} Ball;
kernel void
sampleFieldKernel(constant Ball* balls [[buffer(0)]],
texture2d<half, access::write> samples [[texture(1)]],
sampleFieldKernel(constant Parameters& parameters [[buffer(0)]],
constant Ball* balls [[buffer(1)]],
texture2d<half, access::write> samples [[texture(0)]],
uint2 gid [[thread_position_in_grid]])
{
float sample = 0.0;
// TODO: Get number of metaballs.
for (int i = 0; i < 2; i++) {
constant Ball& ball = metaballs[i];
constant Ball& ball = balls[i];
float r2 = ball.radius * ball.radius;
float xDiff = gid[0] - ball.position[0];
float yDiff = gid[1] - ball.position[1];