I'm having a tough time phrasing this question, so I'll do my best. I'd be happy to provide more details if necessary.
Currently I have a kernel that is calculating a force within a certain radius around a certain point in a 3D grid like so ("_GridSize" is (128, 128, 128)):
RWStructuredBuffer _VelocityWrite;
StructuredBuffer _VelocityRead;
float3 _Velocity;
float _Radius, _DeltaTime;
float4 _ForcePosition, _GridSize;
#pragma kernel VelocityImpulse
[numthreads(NUM_THREADS, NUM_THREADS, NUM_THREADS)]
void VelocityImpulse(uint3 cellPosition : SV_DispatchThreadID)
{
float3 cellDistanceFromForce = cellPosition / (_GridSize.xyz - 1.0f) - _ForcePosition.xyz;
float mag = cellDistanceFromForce.x*cellDistanceFromForce.x + cellDistanceFromForce.y*cellDistanceFromForce.y + cellDistanceFromForce.z*cellDistanceFromForce.z;
float rad2 = _Radius*_Radius;
float3 forceAmount = exp(-mag / rad2) * _Velocity * _DeltaTime;
int idx = id.x + id.y*_Size.x + id.z*_Size.x*_Size.y;
_VelocityWrite[idx] = _VelocityRead[idx] + forceAmount;
}
This is working well. It can be visualized like this:

What I'm looking to do is calculate the force around "_Radius" along the entire length of the "_Velocity" vector. In other words, I'm looking to get a non-zero "forceAmount" value for grid cell points that fall within the radius along the "_Velocity" vector.
What I'm looking for might be visualized as:

Honestly, I'm not even sure where to start.
Thanks for any help!
↧