i did tried GetIndexBuffer and GetVertexBuffer for it, but the result looks not right.
mesh.indexBufferTarget |= GraphicsBuffer.Target.Raw;
var vertexBuffer = mesh.GetVertexBuffer(0);
var indexBuffer = mesh.GetIndexBuffer();
computeShader.SetBuffer(kernel, "indexBuffer",indexBuffer);
computeShader.SetBuffer(kernel, "vertexBuffer",vertexBuffer);
if i use the StructuredBuffer to handle indexBuffer, then the sum of the list in buffer will be 0, while if i use the ByteAddressBuffer like the doc shows, the value of index will be extra huge.
how can i use those? or any other way to pass mesh into compute shader?
Hmmm… that’s close to what I’m doing and not having any problems. Are you sure everything is being bound correctly?
You should not need to fetch them every frame. Instead just fetch them once and check if they’re valid or not, eg…
public GraphicsBuffer unskinnedVertices
{
get
{
checkValid();
if(_isSkinned)
throw new Exception("unskinnedVertices is only valid for unskinned meshes");
if(_unskinnedVertices == null || !_unskinnedVertices.IsValid())
{
// unity seems to invalide this at random times
_unskinnedVertices?.Dispose(); // non-null but invalid case
_mesh.vertexBufferTarget |= GraphicsBuffer.Target.Raw;
_unskinnedVertices = _mesh.GetVertexBuffer(0);
}
return _unskinnedVertices;
}
}
public GraphicsBuffer indices
{
get
{
checkValid();
if(_indices == null || !_indices.IsValid())
{
_indices?.Dispose(); // non-null but invalid case
_mesh.indexBufferTarget |= GraphicsBuffer.Target.Raw;
_indices = _mesh.GetIndexBuffer();
}
return _indices;
}
}
Also try setting them via the command buffer instead of the compute shader instance immediately before dispatching, eg…
thanks for reply 0-0,
actually i have forgotten that i asked this question before, and i met it again (found this post from google XD) ,
the way i avoid this problem is to set new buffers from cpu side, but this way is quite costly: