Unity Custom SRP

etherovo / 2023-08-20 / 原文

Custom Render Pipeline

Project Setup

我们需要在线性空间计算光照,所以设置为Linear。

Pipeline Asset

  • Unity默认使用默认渲染管线,而在这里,我们通过Pipeline Asset来管理自定义管线。进一步的,我们将资产的文件格式写成默认渲染管线的路径格式。
  • 默认的Csharp文件是游戏逻辑的文件格式,我们引入命名空间UnityEngine.Renderring,并且把类实现部分删掉,继承RenderPipelineAsset类来实现我们的自定义管线资产类CustomRenderPipelineAsset
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CustomRenderPipelineAsset : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class CustomRenderPipelineAsset: RenderPipelineAsset
{
    
}
  • RenderPipelineAsset渲染管线资产类的作用是,指定一个渲染管线RenderPipeline实例,这个指定是需要重写CreatePipeline来实现的。
protected override RenderPipeline CreatePipeline()
{
   return null;
}
  • 最终的,我们需要实现能够在界面菜单中选中一个渲染管线资产。这个通过CreateAssetMenu来实现。
[CreateAssetMenu(menuName ="Rendering/Custom Render Pipeline")]
public class CustomRenderPipelineAsset : RenderPipelineAsset