스크립터블 렌더 파이프라인(SRP)에서 C# 스크립트를 사용하여 렌더링 커맨드를 설정하고 예약할 수 있습니다. 그런 다음 Unity의 저수준 그래픽스 아키텍처에 이를 실행하도록 지시하여 그래픽스 API에 명령어를 전송할 수 있습니다.
이를 수행하는 주요 방법은 Scriptable Render Context를 사용하는 것이지만, 커맨드 버퍼를 직접 실행할 수도 있습니다.
Scriptable Render Context는 C# 코드와 Unity의 저수준 그래픽스 코드 간의 인터페이스 역할을 합니다. SRP에서 렌더링은 지연된 실행을 사용하여 작동합니다. 즉 Scriptable Render Context를 사용하여 렌더링 커맨드 리스트를 빌드한 후 Unity에 실행을 지시합니다. 그러면 Unity의 저수준 그래픽스 아키텍처가 그래픽스 API에 명령어를 전송합니다.
렌더링 커맨드를 예약하기 위해 다음을 수행할 수 있습니다. * ScriptableRenderContext.ExecuteCommandBuffer()를 사용하여 CommandBuffers를 Scriptable Render Context에 전달합니다. * ScriptableRenderContext.Cull() 또는 ScriptableRenderContext.DrawRenderers() 등과 같은 스크립터블 렌더 컨텍스트에 대해 직접 API 호출을 수행합니다.
예약한 커맨드를 실행하도록 Unity에 지시하려면 ScriptableRenderContext.Submit()를 호출하십시오. 단, 커맨드 버퍼를 사용하여 커맨드를 예약했는지, 또는 API를 호출하여 예약했는지 여부는 중요하지 않습니다. Unity는 Scriptable Render Context에 대한 모든 렌더링 커맨드를 동일한 방식으로 예약하며 Submit()
를 호출하기 전까지는 어떠한 커맨드도 실행하지 않습니다.
다음 예제 코드는 커맨드 버퍼를 사용하여 현재 렌더 타겟을 지우는 커맨드를 예약하고 실행하는 방법을 보여줍니다.
using UnityEngine;
using UnityEngine.Rendering;
public class ExampleRenderPipelineInstance : RenderPipeline
{
public ExampleRenderPipelineInstance() {
}
protected void Render(ScriptableRenderContext context, Camera[] cameras) {
// Create and schedule a command to clear the current render target
var cmd = new CommandBuffer();
cmd.ClearRenderTarget(true, true, Color.black);
context.ExecuteCommandBuffer(cmd);
cmd.Release();
// Tell the Scriptable Render Context to tell the graphics API to perform the scheduled commands
context.Submit();
}
}
Graphics.ExecuteCommandBuffer()를 호출하면 Scriptable Render Context를 사용하지 않고도 커맨드 버퍼를 즉시 실행할 수 있습니다. 이 API에 대한 호출은 렌더 파이프라인 밖에서 발생합니다.
커맨드 버퍼를 사용하여 예약할 수 있는 커맨드에 대한 자세한 내용은 커맨드 버퍼 API 문서를 참조하십시오.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.