Version: 2021.2
언어: 한국어
스크립터블 렌더 파이프라인을 기반으로 커스텀 렌더 파이프라인 생성
커스텀 렌더 파이프라인에서 단순한 렌더 루프 생성

커스텀 렌더 파이프라인에서 렌더 파이프라인 에셋과 렌더 파이프라인 인스턴스 생성

스크립터블 렌더 파이프라인(SRP)을 기반으로 자체 렌더 파이프라인을 생성하려는 경우 프로젝트에 다음이 포함되어 있어야 합니다.

  • RenderPipelineAsset에서 상속되고 해당 CreatePipeline() 메서드를 오버라이드하는 스크립트. 이 스크립트는 렌더 파이프라인 에셋을 정의합니다.
  • RenderPipeline에서 상속되고 해당 Render() 메서드를 오버라이드하는 스크립트. 이 스크립트는 렌더 파이프라인 인스턴스를 정의하며, 여기에서 커스텀 렌더링 코드를 작성합니다.
  • RenderPipelineAsset 스크립트에서 생성한 렌더 파이프라인 에셋. 이 에셋은 렌더 파이프라인 인스턴스의 팩토리 클래스 역할을 합니다.

이러한 요소들은 매우 밀접하게 관련되어 있으므로 동시에 생성해야 합니다.

기본 렌더 파이프라인 에셋과 렌더 파이프라인 인스턴스 생성

다음 예제는 렌더 파이프라인 인스턴스를 인스턴스화하는 기본 커스텀 렌더 파이프라인 에셋용 스크립트, 렌더 파이프라인 인스턴스를 정의하는 스크립트, 그리고 렌더 파이프라인 에셋 자체를 생성하는 방법을 보여줍니다.

  1. ExampleRenderPipelineAsset.cs 라는 C# 스크립트를 생성합니다.

  2. 다음 코드를 복사하여 새로운 스크립트에 붙여 넣습니다.

    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();
        }
    }
    
  3. ExampleRenderPipelineInstance.cs 라는 C# 스크립트를 생성합니다.

  4. 다음 코드를 복사하여 새로운 스크립트에 붙여 넣습니다.

    using UnityEngine;
    using UnityEngine.Rendering;
    
    public class ExampleRenderPipelineInstance : RenderPipeline
    {
        public ExampleRenderPipelineInstance() {
        }
    
        protected override void Render (ScriptableRenderContext context, Camera[] cameras) {
            // This is where you can write custom rendering code. Customize this method to customize your SRP.
        }
    }
    
  5. 프로젝트 뷰에서 추가(+) 버튼을 클릭하거나, 컨텍스트 메뉴를 열고 Create로 이동한 후 Rendering > Example Render Pipeline Asset을 선택합니다. Unity는 프로젝트 뷰에서 새로운 렌더 파이프라인 에셋을 생성합니다.

설정 가능한 렌더 파이프라인 에셋과 렌더 파이프라인 인스턴스 생성

기본적으로 렌더 파이프라인 에셋은 렌더링에 사용할 렌더 파이프라인 인스턴스와 에디터에서 사용할 기본 머티리얼 및 셰이더에 대한 정보를 저장합니다. RenderPipelineAsset 스크립트에서 추가 데이터 저장을 위해 렌더 파이프라인 에셋을 확장할 수 있으며, 프로젝트에서 서로 다른 설정의 여러 렌더 파이프라인 에셋을 보유할 수 있습니다. 예를 들어 렌더 파이프라인 에셋을 사용하여 서로 다른 하드웨어 계층에 대한 설정 데이터를 보관할 수 있습니다. 고해상도 렌더 파이프라인(HDRP)과 유니버설 렌더 파이프라인(URP)에는 이러한 예제가 포함되어 있습니다.

다음 예제는 인스펙터를 사용하여 각 인스턴스에 대해 설정할 수 있는 공용 데이터로 렌더 파이프라인 에셋을 정의하는 RenderPipelineAsset 스크립트, 그리고 해당 생성자에서 렌더 파이프라인 에셋을 수신하고 해당 렌더 파이프라인 에셋의 데이터를 사용하는 렌더 파이프라인 인스턴스를 생성하는 방법을 보여줍니다.

  1. ExampleRenderPipelineAsset.cs 라는 C# 스크립트를 생성합니다.

  2. 다음 코드를 복사하여 새로운 스크립트에 붙여 넣습니다.

    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);
        }
    }
    
  3. ExampleRenderPipelineInstance.cs 라는 C# 스크립트를 생성합니다.

  4. 다음 코드를 복사하여 새로운 스크립트에 붙여 넣습니다.

    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;
        }
    
        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.
        }
    }
    
    
  5. 프로젝트 뷰에서 추가(+) 버튼을 클릭하거나, 컨텍스트 메뉴를 열고 Create로 이동한 후 Rendering > Example Render Pipeline Asset을 선택합니다. Unity는 프로젝트 뷰에서 새로운 렌더 파이프라인 에셋을 생성합니다.

스크립터블 렌더 파이프라인을 기반으로 커스텀 렌더 파이프라인 생성
커스텀 렌더 파이프라인에서 단순한 렌더 루프 생성
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961