Mesh GPU 索引缓冲区的预期目标用途。
默认情况下,Mesh 索引缓冲区具有 GraphicsBuffer.Target.Index 使用目标。如果要从计算着色器访问网格索引缓冲区,则需要请求其他目标,例如 GraphicsBuffer.Target.Raw。
using UnityEngine;
public class ExampleScript : MonoBehaviour { public Mesh mesh; public ComputeShader computeShader; void Start() { // Mark the index buffer as needing "Raw" // (ByteAddressBuffer, RWByteAddressBuffer in HLSL shaders) // access. mesh.indexBufferTarget |= GraphicsBuffer.Target.Raw; // Get the index buffer of the Mesh, and set it up // as a buffer parameter to a compute shader. var indexBuffer = mesh.GetIndexBuffer(); computeShader.SetBuffer(0, "MeshIndexBuffer", indexBuffer); indexBuffer.Dispose(); } }
其他资源: Target, GetIndexBuffer, vertexBufferTarget.