스크립터블 렌더 파이프라인(SRP)을 직접 생성하려는 경우 프로젝트에 반드시 다음을 포함해야 합니다.
CreatePipeline()
메서드를 오버라이드하는 스크립트. 이 스크립트는 렌더 파이프라인 에셋을 정의합니다.Render()
메서드를 오버라이드하는 스크립트. 이 스크립트는 렌더 파이프라인 인스턴스를 정의합니다.이러한 요소들은 매우 밀접하게 관련되어 있으므로 동시에 생성해야 합니다.
다음 예제는 렌더 파이프라인 인스턴스를 인스턴스화하는 기본 커스텀 렌더 파이프라인 에셋용 스크립트, 렌더 파이프라인 인스턴스를 정의하는 스크립트, 그리고 렌더 파이프라인 에셋 자체를 생성하는 방법을 보여줍니다.
ExampleRenderPipelineAsset.cs 라는 C# 스크립트를 생성합니다.
다음 코드를 복사하여 새로운 스크립트에 붙여 넣습니다.
using UnityEngine;
using UnityEngine.Rendering;
// The CreateAssetMenu attribute lets you create instances of this class in the Unity Editor.
[CreateAssetMenu(menuName = "Rendering/ExampleRenderPipelineAsset")]
public class ExampleRenderPipelineAsset : RenderPipelineAsset
{
// Unity calls this method before rendering the first frame.
// If a setting on the Render Pipeline Asset changes, Unity destroys the current Render Pipeline Instance and calls this method again before rendering the next frame.
protected override RenderPipeline CreatePipeline() {
// Instantiate the Render Pipeline that this custom SRP uses for rendering.
return new ExampleRenderPipelineInstance();
}
}
ExampleRenderPipelineInstance.cs 라는 C# 스크립트를 생성합니다.
다음 코드를 복사하여 새로운 스크립트에 붙여 넣습니다.
using UnityEngine;
using UnityEngine.Rendering;
public class ExampleRenderPipelineInstance : RenderPipeline
{
public ExampleRenderPipelineInstance() {
}
// Unity calls this method once per frame for each CameraType that is currently rendering.
protected override void Render (ScriptableRenderContext context, Camera[] cameras) {
// This is where you can write custom rendering code. Customize this method to customize your SRP.
}
}
프로젝트 뷰에서 추가(+) 버튼을 클릭하거나, 컨텍스트 메뉴를 열고 Create로 이동한 후 Rendering > Example Render Pipeline Asset을 선택합니다. Unity가 프로젝트 뷰에서 새로운 렌더 파이프라인 에셋을 생성합니다.
기본적으로 렌더 파이프라인 에셋은 렌더링에 사용할 렌더 파이프라인 인스턴스와 에디터에서 사용할 기본 머티리얼 및 셰이더에 대한 정보를 저장합니다. RenderPipelineAsset
스크립트에서 추가 데이터 저장을 위해 렌더 파이프라인 에셋을 확장할 수 있으며, 프로젝트에서 서로 다른 설정의 여러 렌더 파이프라인 에셋을 보유할 수 있습니다. 예를 들어 렌더 파이프라인 에셋을 사용하여 서로 다른 하드웨어 계층에 대한 설정 데이터를 보관할 수 있습니다. 고해상도 렌더 파이프라인(HDRP)과 유니버설 렌더 파이프라인(URP)에는 이러한 예제가 포함되어 있습니다.
다음 예제는 인스펙터를 사용하여 각 인스턴스에 대해 설정할 수 있는 공용 데이터로 렌더 파이프라인 에셋을 정의하는 RenderPipelineAsset
스크립트, 그리고 해당 생성자에서 렌더 파이프라인 에셋을 수신하고 해당 렌더 파이프라인 에셋의 데이터를 사용하는 렌더 파이프라인 인스턴스를 생성하는 방법을 보여줍니다.
C# 스크립트 ExampleRenderPipelineAsset.cs 를 생성합니다.
새로 만든 스크립트에 다음 코드를 복사해서 붙여넣습니다.
using UnityEngine;
using UnityEngine.Rendering;
// The CreateAssetMenu attribute lets you create instances of this class in the Unity Editor.
[CreateAssetMenu(menuName = "Rendering/ExampleRenderPipelineAsset")]
public class ExampleRenderPipelineAsset : RenderPipelineAsset
{
// This data can be defined in the Inspector for each Render Pipeline Asset
public Color exampleColor;
public string exampleString;
// Unity calls this method before rendering the first frame.
// If a setting on the Render Pipeline Asset changes, Unity destroys the current Render Pipeline Instance and calls this method again before rendering the next frame.
protected override RenderPipeline CreatePipeline() {
// Instantiate the Render Pipeline that this custom SRP uses for rendering, and pass a reference to this Render Pipeline Asset.
// The Render Pipeline Instance can then access the configuration data defined above.
return new ExampleRenderPipelineInstance(this);
}
}
C# 스크립트 ExampleRenderPipelineInstance.cs 를 생성합니다.
새로 만든 스크립트에 다음 코드를 복사해서 붙여넣습니다.
using UnityEngine;
using UnityEngine.Rendering;
public class ExampleRenderPipelineInstance : RenderPipeline
{
// Use this variable to a reference to the Render Pipeline Asset that was passed to the constructor
private ExampleRenderPipelineAsset renderPipelineAsset;
// The constructor has an instance of the ExampleRenderPipelineAsset class as its parameter.
public ExampleRenderPipelineInstance(ExampleRenderPipelineAsset asset) {
renderPipelineAsset = asset;
}
// Unity calls this method once per frame for each CameraType that is currently rendering.
protected override void Render(ScriptableRenderContext context, Camera[] cameras) {
// This is an example of using the data from the Render Pipeline Asset.
Debug.Log(renderPipelineAsset.exampleString);
// This is where you can write custom rendering code. Customize this method to customize your SRP.
}
}
프로젝트 뷰에서 추가(+) 버튼을 클릭하거나, 컨텍스트 메뉴를 열고 Create로 이동한 후 Rendering > Example Render Pipeline Asset을 선택합니다. Unity가 프로젝트 뷰에서 새로운 렌더 파이프라인 에셋을 생성합니다.
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.