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