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.
37 lines
1.1 KiB
37 lines
1.1 KiB
|
|
#pragma kernel CSMain
|
|
#define NUM_THREADS 8
|
|
|
|
float4 _Size;
|
|
|
|
RWStructuredBuffer<float3> _Write;
|
|
StructuredBuffer<float3> _Velocity;
|
|
|
|
[numthreads(NUM_THREADS,NUM_THREADS,NUM_THREADS)]
|
|
void CSMain (int3 id : SV_DispatchThreadID)
|
|
{
|
|
|
|
int idxL = max(0, id.x-1) + id.y*_Size.x + id.z*_Size.x*_Size.y;
|
|
int idxR = min(_Size.x-1, id.x+1) + id.y*_Size.x + id.z*_Size.x*_Size.y;
|
|
|
|
int idxB = id.x + max(0, id.y-1)*_Size.x + id.z*_Size.x*_Size.y;
|
|
int idxT = id.x + min(_Size.y-1, id.y+1)*_Size.x + id.z*_Size.x*_Size.y;
|
|
|
|
int idxD = id.x + id.y*_Size.x + max(0, id.z-1)*_Size.x*_Size.y;
|
|
int idxU = id.x + id.y*_Size.x + min(_Size.z-1, id.z+1)*_Size.x*_Size.y;
|
|
|
|
float3 L = _Velocity[ idxL ];
|
|
float3 R = _Velocity[ idxR ];
|
|
|
|
float3 B = _Velocity[ idxB ];
|
|
float3 T = _Velocity[ idxT ];
|
|
|
|
float3 D = _Velocity[ idxD ];
|
|
float3 U = _Velocity[ idxU ];
|
|
|
|
float3 vorticity = 0.5 * float3( (( T.z - B.z ) - ( U.y - D.y )) , (( U.x - D.x ) - ( R.z - L.z )) , (( R.y - L.y ) - ( T.x - B.x )) );
|
|
|
|
int idx = id.x + id.y*_Size.x + id.z*_Size.x*_Size.y;
|
|
|
|
_Write[idx] = vorticity;
|
|
}
|
|
|