Moving Work to the GPU

This commit is contained in:
2021-01-31 11:17:44 +08:00
parent 8f4b9e2ae2
commit a64346ee62
6 changed files with 170 additions and 4 deletions

View 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));
}