Hi all,
I’m not really used to ask for help as i prefer roaming the docs and already proposed solutions but here i’m getting quite stucked
Here it is i have a compute shader and the C# script which goes with it used to modify an array of vertices on the y axis simple enough to be clear.
but despite the fact that it runs fine the shader seems to forget the first vertex of my shape (except when that shape is a closed volume?)
so here it is the C# class :
Mesh m;
public bool stopProcess = false;
MeshCollider coll;
public ComputeShader csFile;
Vector3[] arrayToProcess;
ComputeBuffer cbf;
ComputeBuffer cbfOut;
int vertexLength;
// Use this for initialization
void Awake() {
coll = gameObject.GetComponent<MeshCollider>();
m = GetComponent<MeshFilter>().sharedMesh;
vertexLength = m.vertices.Length;
arrayToProcess = m.vertices;
}
void Start () {
cbf = new ComputeBuffer(vertexLength,32);
cbfOut = new ComputeBuffer(vertexLength,32);
csFile.SetBuffer(0,"Board",cbf);
csFile.SetBuffer(0,"BoardOut",cbfOut);
}
// Update is called once per frame
void Update () {
csFile.SetFloat("time",Time.time);
cbf.SetData(m.vertices);
csFile.Dispatch(0,vertexLength,vertexLength,1);
cbfOut.GetData(arrayToProcess);
m.vertices = arrayToProcess;
coll.sharedMesh = m;
}
And my compute shader script :
#pragma kernel CSMain
RWStructuredBuffer<float3> Board : register(s[0]);
RWStructuredBuffer<float3> BoardOut : register(s[1]);
float time;
[numthreads(1,1,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
float valx = (sin((time*4)+Board[id.x].x));
float valz = (cos((time*2)+Board[id.x].z));
Board[id.x].y = (valx + valz)/5;
BoardOut[id.x] = Board[id.x];
}
At the beginning i was reading an writing from the same buffer but as i had my issue i tried having separate buffers, but no success still the same…
Maybe i misunderstood the way compute shaders are supposed to be used (and i know i could use a vertex shader but i just want to try compute shaders for further improvements…)