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.
80 lines
2.0 KiB
80 lines
2.0 KiB
#define WIDTH 512
|
|
#define HEIGHT 424
|
|
|
|
#pragma kernel CSMain
|
|
|
|
#include "UnityCG.cginc"
|
|
|
|
RWStructuredBuffer<float4> KinectPositionBuffer;
|
|
RWStructuredBuffer<float4> KinectVelocityBuffer;
|
|
RWStructuredBuffer<float4> KinectGridBuffer;
|
|
//RWStructuredBuffer<float4> KinectOpticalBuffer;
|
|
RWStructuredBuffer<float4> FinalPositionBuffer;
|
|
RWStructuredBuffer<float4> FinalVelocityBuffer;
|
|
|
|
AppendStructuredBuffer<float4> HomePositionBuffer;
|
|
AppendStructuredBuffer<float4> HomeVelocityBuffer;
|
|
|
|
//Texture2D<float4> PositionTexture;
|
|
//Texture2D<float4> VelocityTexture;
|
|
//Texture2D<float4> MotionTexture;
|
|
//Texture2DArray<float4> MotionTextureArray;
|
|
|
|
float4 ClipMin;
|
|
float4 ClipMax;
|
|
float4x4 ModelMatrix;
|
|
float4 FluidSize;
|
|
float4 FluidRoot;
|
|
float4 FluidDim;
|
|
int flipX;
|
|
int NumKinects;
|
|
|
|
[numthreads(512, 1, 1)]
|
|
void CSMain (uint3 id : SV_DispatchThreadID)
|
|
{
|
|
//uint2 tex_coord = uint2(id.x % WIDTH, id.x / WIDTH);
|
|
|
|
float4 pos = FinalPositionBuffer[id.x];
|
|
//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 = FinalVelocityBuffer[id.x];
|
|
//vel = float4(0, 0, 0.01, 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);
|
|
|
|
}
|
|
|
|
}
|
|
|