Moving Work to the GPU
This commit is contained in:
39
Assets/Script/FunctionLibrary.compute
Normal file
39
Assets/Script/FunctionLibrary.compute
Normal file
@ -0,0 +1,39 @@
|
||||
#pragma kernel FuncationKernel
|
||||
|
||||
RWStructuredBuffer<float3> _Positions;
|
||||
|
||||
uint _Resolution;
|
||||
|
||||
float _Step;
|
||||
float _Time;
|
||||
|
||||
float2 GetUV(uint3 id)
|
||||
{
|
||||
return (id.xy + 0.5) * _Step - 1.0;
|
||||
}
|
||||
|
||||
void SetPositions(uint3 id, float3 positions)
|
||||
{
|
||||
if (id.x < _Resolution && id.y < _Resolution)
|
||||
{
|
||||
_Positions[id.x + id.y * _Resolution] = positions;
|
||||
}
|
||||
}
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
|
||||
float3 Wave(float u, float v, float t)
|
||||
{
|
||||
float3 p;
|
||||
p.x = u;
|
||||
p.y = sin(PI * (u + v + t));
|
||||
p.z = v;
|
||||
return p;
|
||||
}
|
||||
|
||||
[numthreads(8, 8, 1)]
|
||||
void FuncationKernel(uint3 id : SV_DISPATCHTHREADID)
|
||||
{
|
||||
float2 uv = GetUV(id);
|
||||
SetPositions(id, Wave(uv.x, uv.y, _Time));
|
||||
}
|
Reference in New Issue
Block a user