|
|
|
|
|
// Each #kernel tells which function to compile; you can have many kernels
|
|
|
|
|
|
#pragma kernel CSMain
|
|
|
|
|
|
|
|
|
|
|
|
RWStructuredBuffer<float4> KinectPositionBuffer;
|
|
|
|
|
|
RWStructuredBuffer<float4> KinectVelocityBuffer;
|
|
|
|
|
|
RWStructuredBuffer<float4> KinectGridBuffer;
|
|
|
|
|
|
|
|
|
|
|
|
AppendStructuredBuffer<float4> HomePositionBuffer;
|
|
|
|
|
|
AppendStructuredBuffer<float4> HomeVelocityBuffer;
|
|
|
|
|
|
|
|
|
|
|
|
Texture2D<float4> PositionTexture;
|
|
|
|
|
|
Texture2D<float4> VelocityTexture;
|
|
|
|
|
|
|
|
|
|
|
|
float4 ClipMin;
|
|
|
|
|
|
float4 ClipMax;
|
|
|
|
|
|
float4x4 ModelMatrix;
|
|
|
|
|
|
float4 FluidSize;
|
|
|
|
|
|
float4 FluidRoot;
|
|
|
|
|
|
float4 FluidDim;
|
|
|
|
|
|
int flipX;
|
|
|
|
|
|
|
|
|
|
|
|
[numthreads(512,1,1)]
|
|
|
|
|
|
void CSMain (uint3 id : SV_DispatchThreadID)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint2 tex_coord = uint2(id.x % 424, id.x / 424);
|
|
|
|
|
|
|
|
|
|
|
|
float4 pos = float4(PositionTexture[tex_coord].xyz, 1);
|
|
|
|
|
|
//pos.y *= -1;
|
|
|
|
|
|
pos.z *= -1;
|
|
|
|
|
|
pos.x = lerp(pos.x, -pos.x, flipX);
|
|
|
|
|
|
|
|
|
|
|
|
float pos_mag = length(pos.xyz);
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
pos = mul(pos, ModelMatrix);
|
|
|
|
|
|
|
|
|
|
|
|
float4 vel = VelocityTexture[tex_coord];
|
|
|
|
|
|
//vel.y *= -1;
|
|
|
|
|
|
vel.z *= -1;
|
|
|
|
|
|
vel.x = lerp(vel.x, -vel.x, flipX);
|
|
|
|
|
|
|
|
|
|
|
|
float3 grid_pos = (pos.xyz - FluidRoot.xyz) / FluidSize.xyz;
|
|
|
|
|
|
int grid_index = -1;
|
|
|
|
|
|
if (grid_pos.x > 0 && grid_pos.x < 1 &&
|
|
|
|
|
|
grid_pos.y > 0 && grid_pos.y < 1 &&
|
|
|
|
|
|
grid_pos.z > 0 && grid_pos.z < 1 &&
|
|
|
|
|
|
pos_mag > 0.0f)// && length(pos) > 10.0f)
|
|
|
|
|
|
{
|
|
|
|
|
|
grid_pos *= FluidDim.xyz;
|
|
|
|
|
|
grid_index = (int)grid_pos.x + (int)grid_pos.y * FluidDim.x + (int)grid_pos.z * FluidDim.x * FluidDim.y;
|
|
|
|
|
|
KinectGridBuffer[grid_index] += float4(vel.xyz, 1);
|
|
|
|
|
|
|
|
|
|
|
|
if (pos_mag > 1.0f)
|
|
|
|
|
|
{
|
|
|
|
|
|
HomePositionBuffer.Append(float4(pos.xyz, 0));
|
|
|
|
|
|
HomeVelocityBuffer.Append(float4(vel.xyz, 0));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KinectPositionBuffer[id.x] = float4(pos.xyz, grid_index);
|
|
|
|
|
|
KinectVelocityBuffer[id.x] = float4((pos_mag == 0.0f) ? float3(0, 0, 0) : vel.xyz, 0);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|