Quantcast
Channel: Questions in topic: "compute shader"
Viewing all articles
Browse latest Browse all 287

Math Question: Calculating force around Vector3 length inside a 3D Grid (compute shader)

$
0
0
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: ![Radius around a point](https://i.imgur.com/uyOtJEh.png) 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: ![Radius around a vector](https://i.imgur.com/dmtxHK5.png) Honestly, I'm not even sure where to start. Thanks for any help!

Viewing all articles
Browse latest Browse all 287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>