Version: Unity 6.0 (6000.0)
언어 : 한국어
URP의 렌더 패스에서 컴퓨트 셰이더 실행
URP에서 렌더 그래프 분석

URP에서 컴퓨트 셰이더에 대한 입력 데이터 생성

렌더 패스에서 컴퓨트 셰이더를 실행할 때 버퍼를 할당하여 컴퓨트 셰이더에 대한 입력 데이터를 제공할 수 있습니다.

다음 과정을 따르십시오.

  1. 그래픽스 버퍼를 생성한 다음 패스 데이터에서 그에 대한 핸들을 추가합니다. 예시:

    // Declare an input buffer
    public GraphicsBuffer inputBuffer;
    
    // Add a handle to the input buffer in your pass data
    class PassData
    {
        ...
        public BufferHandle input;
    }
    
    // Create the buffer in the render pass constructor
    public ComputePass(ComputeShader computeShader)
    {
        // Create the input buffer as a structured buffer
        // Create the buffer with a length of 5 integers, so you can input 5 values.
        inputBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, 5, sizeof(int));
    }
    
  2. 버퍼의 데이터를 설정합니다. 예시:

    var inputValues = new List<int> { 1, 2, 3, 4, 5 };
    inputBuffer.SetData(inputValues);
    
  3. ImportBuffer 렌더 그래프 API를 사용하여 버퍼를 렌더 그래프 시스템이 사용할 수 있는 핸들로 전환한 다음 패스 데이터에서 BufferHandle 필드를 설정합니다. 예시:

    BufferHandle inputHandleRG = renderGraph.ImportBuffer(inputBuffer);
    passData.input = inputHandleRG;
    
  4. UseBuffer 메서드를 사용하여 렌더 그래프 시스템에서 버퍼를 읽을 수 있는 버퍼로 설정합니다. 예시:

    builder.UseBuffer(passData.input, AccessFlags.Read);
    
  5. SetRenderFunc 메서드에서 SetComputeBufferParam API를 사용하여 버퍼를 컴퓨트 셰이더에 연결합니다. 예시:

    // The first parameter is the compute shader
    // The second parameter is the function that uses the buffer
    // The third parameter is the RWStructuredBuffer input variable to attach the buffer to
    // The fourth parameter is the handle to the input buffer
    context.cmd.SetComputeBufferParam(passData.computeShader, passData.computeShader.FindKernel("Main"), "inputData", passData.input);
    

예제

전체 예시는 URP(유니버설 렌더 파이프라인) 패키지 샘플Compute라는 예시를 참고하십시오.

추가 리소스

URP의 렌더 패스에서 컴퓨트 셰이더 실행
URP에서 렌더 그래프 분석
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961