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.

57 lines
1006 B

#define NUM_THREADS 8
float _Radius, _Amount, _DeltaTime, _Extinguishment;
float4 _Pos, _Size;
RWStructuredBuffer<float> _Write;
StructuredBuffer<float> _Read, _Reaction;
#pragma kernel GaussImpulse
[numthreads(NUM_THREADS,NUM_THREADS,NUM_THREADS)]
void GaussImpulse(uint3 id : SV_DispatchThreadID)
{
float3 pos = id/(_Size.xyz-1.0f) - _Pos.xyz;
float mag = pos.x*pos.x + pos.y*pos.y + pos.z*pos.z;
float rad2 = _Radius*_Radius;
float amount = exp(-mag/rad2) * _Amount * _DeltaTime;
int idx = id.x + id.y*_Size.x + id.z*_Size.x*_Size.y;
_Write[idx] = _Read[idx] + amount;
}
#pragma kernel ExtinguishmentImpluse
[numthreads(NUM_THREADS,NUM_THREADS,NUM_THREADS)]
void ExtinguishmentImpluse(uint3 id : SV_DispatchThreadID)
{
int idx = id.x + id.y*_Size.x + id.z*_Size.x*_Size.y;
float amount = 0.0;
float reaction = _Reaction[idx];
if(reaction > 0.0 && reaction < _Extinguishment)
amount = _Amount * reaction;
_Write[idx] = _Read[idx] + amount;
}