Convert C# script to compute shader to run on ngpu instead of cpu

Hi so I feel kinda dumb saying that but I have no idea how compute shaders work. All I know is that they run on gpu instead of cpu and here I shot myself in the foot. I have downloaded a low poly water model from the asset store but after some backtracking I noticed it the waves are generated using a c# script. I an attempt to optimize I wanted to open a new thread though I can’t read the position then, so now I am here. If someone could optimize it or post resources for me I would love that.

This is the asset I use and here is the code for the waves:

for (int i = 0; i < vertices.Length; i++)
            {
                Vector3 v = vertices[i];

                //Initially set the wave height to 0
                v.y = 0.0f;

                //Get the distance between wave origin position and the current vertex
                float distance = Vector3.Distance(v, waveOriginPosition);
                distance = (distance % waveLength) / waveLength;

                //Oscilate the wave height via sine to create a wave effect
                v.y = waveHeight * Mathf.Sin(Time.time * Mathf.PI * 2.0f * waveFrequency
                + (Mathf.PI * 2.0f * distance));
               
                //Update the vertex
                vertices[i] = v;
            }

            //Update the mesh properties
            mesh.vertices = vertices;
            mesh.RecalculateNormals();
            mesh.MarkDynamic();
            meshFilter.mesh = mesh;

Thats the entire wave code thats causing trouble. In Update is nothing but this method.

I just use this asset… it’s less than five bucks:

Works on mobile just fine.

Thanks for the reply but this is practically what the asset that I have does right now I guess I just have to look into shaders

No, it actually offers to use C# to optionally generate the mesh… ONCE. After that it is entirely shader driven. You are welcome to put your own 3D mesh into place and put this shader on it, as long as it has enough vertices for your needs.

Source: I actually use it and have it in front of me now. It does what it says on the tin: shader-computed water. Here’s his blurb. Well worth five bucks:

6797705--788174--Screen Shot 2021-02-03 at 7.26.40 AM.png