This repository has been archived on 2024-11-16. You can view files and clone it, but cannot push or open issues or pull requests.
CatlikeCoding-Unity/Assets/Script/FunctionLibrary.compute

40 lines
657 B
Plaintext
Raw Normal View History

2021-01-31 11:17:44 +08:00
#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));
}