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
2.1 KiB
72 lines
2.1 KiB
// Each #kernel tells which function to compile; you can have many kernels
|
|
#pragma kernel CSMain
|
|
|
|
RWStructuredBuffer<float4> PositionBuffer;
|
|
RWStructuredBuffer<float4> VelocityBuffer;
|
|
RWStructuredBuffer<float4> KinectGridBuffer;
|
|
//RWStructuredBuffer<float4> FullPositionBuffer;
|
|
//RWStructuredBuffer<float4> FullVelocityBuffer;
|
|
|
|
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);
|
|
|
|
//const int layer = 0;
|
|
//for (int i = 0; i < layer; i++)
|
|
//{
|
|
// grid_index += FluidDim.x * FluidDim.y;
|
|
// KinectGridBuffer[grid_index] += float4(vel.xyz, 1);
|
|
//}
|
|
|
|
///PositionBuffer.Append(float4(pos.xyz, grid_index));
|
|
///VelocityBuffer.Append(float4(vel.xyz, 0));
|
|
}
|
|
|
|
PositionBuffer[id.x] = float4(pos.xyz, grid_index);
|
|
VelocityBuffer[id.x] = float4((pos_mag == 0.0f) ? float3(0, 0, 0) : vel.xyz, 0);
|
|
|
|
//FullPositionBuffer[id.x] = float4(pos.xyz, grid_index);
|
|
//FullVelocityBuffer[id.x] = float4((pos_mag == 0.0f) ? float3(0, 0, 0) : vel.xyz, 0);
|
|
}
|
|
|
|
//PositionBuffer.Append(float4(0, 0, 0, 1));
|
|
//Result[id.xy] = float4(id.x & id.y, (id.x & 15)/15.0, (id.y & 15)/15.0, 0.0);
|
|
}
|
|
|