This kernel is designed to simulate the effect of wind on a set of velocity vectors (vel_1, vel_2, vel_3). It does this by adding a “wind force” to each velocity, which is calculated based on the direction and magnitude of the wind.
kernel void wind(
int stride_x,
int stride_y,
int stride_z,
int stride_offset,
float timeinc,
global float * vel_1, global float * vel_2, global float * vel_3,
float3 wind_dir,
float wind_mag
)
{
int gidx = get_global_id(0);
int gidy = get_global_id(1);
int gidz = get_global_id(2);
int idx = stride_offset + stride_x * gidx + stride_y * gidy + stride_z * gidz;
float3 v = (float3)(vel_1[idx], vel_2[idx], vel_3[idx]);
float3 w = normalize(wind_dir) * wind_mag;
float3 r = ( dot(v,w) / pow( length(w),2 ) ) * w;
float3 remainder = w - w * clamp( dot(w,r), 0.0f, 1.0f);
vel_1[idx] += remainder.x;
vel_2[idx] += remainder.y;
vel_3[idx] += remainder.z;
}