You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.8 KiB
72 lines
1.8 KiB
#define WIDTH 512
|
|
#define HEIGHT 424
|
|
|
|
#pragma kernel CSMain
|
|
|
|
RWStructuredBuffer<float4> KinectPositionBuffer;
|
|
RWStructuredBuffer<float4> KinectVelocityBuffer;
|
|
RWStructuredBuffer<float4> KinectGridBuffer;
|
|
|
|
AppendStructuredBuffer<float4> HomePositionBuffer;
|
|
AppendStructuredBuffer<float4> HomeVelocityBuffer;
|
|
|
|
//Texture2D<float4> PositionTexture;
|
|
//Texture2D<float4> VelocityTexture;
|
|
Texture2D<float4> MotionTexture;
|
|
|
|
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 % HEIGHT, id.x / HEIGHT);
|
|
|
|
float4 pos = float4(MotionTexture[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 = MotionTexture[tex_coord + uint2(WIDTH, 0)];
|
|
//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 > 0.1f)// && pos.y < 0.5f)
|
|
{
|
|
pos.y = 0.0f;
|
|
vel.xyz = float3(0, 0, 0);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|