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.
62 lines
1.8 KiB
62 lines
1.8 KiB
#pragma kernel CSMain
|
|
#define NUM_THREADS 8
|
|
|
|
RWStructuredBuffer<float4> KinectGridBuffer;
|
|
RWStructuredBuffer<float3> VelocityBuffer;
|
|
RWStructuredBuffer<float> TemperatureBuffer;
|
|
RWStructuredBuffer<float> ObstacleBuffer;
|
|
RWStructuredBuffer<float> DensityBuffer;
|
|
|
|
float4 FluidDim;
|
|
float timeStep;
|
|
float temperatureAmount;
|
|
float densityAmount;
|
|
float kinectAmount;
|
|
|
|
[numthreads(NUM_THREADS, NUM_THREADS, NUM_THREADS)]
|
|
void CSMain(uint3 id : SV_DispatchThreadID)
|
|
{
|
|
int idx = id.x + id.y*FluidDim.x + id.z*FluidDim.x*FluidDim.y;
|
|
|
|
float4 value = KinectGridBuffer[idx];
|
|
float3 vel = lerp(value.xyz, float3(0, 0, 0), 0.05f);
|
|
float obs = lerp(value.w, 0, 0.2f);
|
|
|
|
KinectGridBuffer[idx] = float4(vel, obs);
|
|
//KinectGridBuffer[idx] = float4(1, 0, 0, 1);
|
|
|
|
float obstacle = 0;
|
|
|
|
// boundary
|
|
{
|
|
if ((int)id.x - 1 < 0) obstacle = 1;
|
|
if ((int)id.x + 1 > (int)FluidDim.x - 1) obstacle = 1;
|
|
|
|
if ((int)id.y - 1 < 0) obstacle = 1;
|
|
if ((int)id.y + 1 > (int)FluidDim.y - 1) obstacle = 1;
|
|
|
|
if ((int)id.z - 1 < 0) obstacle = 1;
|
|
if ((int)id.z + 1 > (int)FluidDim.z - 1) obstacle = 1;
|
|
}
|
|
|
|
//
|
|
obstacle = max(obstacle, KinectGridBuffer[idx].w);
|
|
obstacle = saturate(obstacle);
|
|
|
|
//ObstacleBuffer[idx] = obstacle;
|
|
float3 velocity = VelocityBuffer[idx];
|
|
|
|
float density = DensityBuffer[idx];
|
|
//if (id.y == 1) density += 10.0f * timeStep;
|
|
density += KinectGridBuffer[idx].w * kinectAmount * densityAmount * timeStep * length(velocity);
|
|
density = max(density, 0);
|
|
//DensityBuffer[idx] = density;
|
|
|
|
float temperature = TemperatureBuffer[idx];
|
|
temperature += KinectGridBuffer[idx].w * kinectAmount * temperatureAmount * timeStep * length(velocity);
|
|
temperature = max(temperature, 0);
|
|
TemperatureBuffer[idx] = temperature;
|
|
|
|
velocity += KinectGridBuffer[idx].xyz * kinectAmount * 10.0;
|
|
VelocityBuffer[idx] = velocity;
|
|
} |