@group(0) @binding(0)
var<storage, read_write> positions : array<vec4<f32>>;

@group(0) @binding(1)
var<storage, read_write> velocities : array<vec4<f32>>;


@group(0) @binding(2)
var<uniform> deltaTime : f32;

@group(0) @binding(3)
var<uniform> aspectRatio : f32;

@group(0) @binding(4)
var<uniform> mousePos : vec2<f32>;

@group(0) @binding(5)
var<uniform> hoverRadius : f32;

@group(0) @binding(6)
var<storage, read_write> states : array<u32>;


@compute @workgroup_size(64)
fn main(@builtin(global_invocation_id) id : vec3<u32>) {

	let index = id.x;
let gravity = vec3<f32>(0.0, -29.61, 0.0);

var pos = positions[index];
var vel = velocities[index];

// Apply gravity to velocity


// Integrate position
let dist = distance(vec2<f32>(pos.x*aspectRatio, pos.y), mousePos);

var newPos = pos.xyz;

if (dist < hoverRadius) {

	states[index] = 1;

}

if ( states[index] == 1 ) {

	let newVel = vel.xyz + gravity * deltaTime;

	newPos = pos.xyz + newVel * 0.001;

	velocities[index] = vec4<f32>(newVel, vel.w);

	positions[index]  = vec4<f32>(newPos, pos.w);

} else {

	let newVel = vel.xyz;

	newPos = pos.xyz + newVel * 0.001;

	velocities[index] = vec4<f32>(newVel, vel.w);


	positions[index]  = vec4<f32>(newPos, pos.w);
}

// Store updated values


}
