URP 16.0.3 기준, ScriptableRenderFeature & Pass API가 변경되면서 이전 버전 코드를 수정하지 않으면 에러가 발생합니다.

 

참고자료

https://forum.unity.com/threads/rendertargethandle-is-obsolete-deprecated-in-favor-of-rthandle.1211052/

https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@16.0/manual/upgrade-guide-2023-2.html


RTHandle System도입으로 인한 ScriptableRenderPass 클래스 API 주요 변경 코드

(빨강 = Before, 초록 = After)

 

1. Change render target type

  • RenderTargetHandle renderTarget;
  • RTHandle renderTarget;

2. Associate the shader property with the render target using RTHandles.Alloc instead of renderTarget.Init

  • renderTarget.Init("_ShaderProperty");
  • renderTarget = RTHandles.Alloc("_ShaderProperty", name: "_ShaderProperty");

3. Assign temporary render texture using the shader property identifier

  • cmd.GetTemporaryRT(renderTarget.id, targetDescriptor, filterMode);
  • cmd.GetTemporaryRT(Shader.PropertyToID(renderTarget.name), targetDescriptor, filterMode);

4. Modify ConfigureTarget to use the new RTHandle instead of the old RenderTargetIdentifier

  • ConfigureTarget(renderTarget.id);
  • ConfigureTarget(renderTarget);

5. Get the render texture identifier from the shader property

  • cmd.ReleaseTemporaryRT(renderTarget.id);
  • cmd.ReleaseTemporaryRT(Shader.PropertyToID(renderTarget.name));

 

클래스 코드 예제

RTHandle 도입 이전

public class CustomPass : ScriptableRenderPass
{
    RenderTargetHandle m_Handle;
    // With the old API, RenderTargetIdentifier might combine color and depth
    RenderTargetIdentifier m_Destination;

    public CustomPass()
    {
        m_Handle.Init("_CustomPassHandle");
    }

    public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    {
        var desc = renderingData.cameraData.cameraTargetDescriptor;
        cmd.GetTemporaryRT(m_Handle.id, desc, FilterMode.Point);
    }

    public override void OnCameraCleanup(CommandBuffer cmd)
    {
        cmd.ReleaseTemporaryRT(m_Handle.id);
    }

    public void Setup(RenderTargetIdentifier destination)
    {
        m_Destination = destination;
    }

    public override void Execute(ScriptableRenderContext context,
                                    ref RenderingData renderingData)
    {
        CommandBuffer cmd = CommandBufferPool.Get();
        // Set the same target for color and depth
        ScriptableRenderer.SetRenderTarget(cmd, m_Destination, m_Destination, clearFlag,
                                              clearColor);
        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }
}

 

RTHandle 도입 후

public class CustomPass : ScriptableRenderPass
{
    RTHandle m_Handle;
    // Then using RTHandles, the color and the depth properties must be separate
    RTHandle m_DestinationColor;
    RTHandle m_DestinationDepth;

    void Dispose()
    {
        m_Handle?.Release();
    }

    public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    {
        var desc = renderingData.cameraData.cameraTargetDescriptor;
        // Then using RTHandles, the color and the depth properties must be separate
        desc.depthBufferBits = 0;
        RenderingUtils.ReAllocateIfNeeded(ref m_Handle, desc, FilterMode.Point,
                                         TextureWrapMode.Clamp, name: "_CustomPassHandle");
    }

    public override void OnCameraCleanup(CommandBuffer cmd)
    {
        m_DestinationColor = null;
        m_DestinationDepth = null;
    }

    public void Setup(RTHandle destinationColor, RTHandle destinationDepth)
    {
        m_DestinationColor = destinationColor;
        m_DestinationDepth = destinationDepth;
    }

    public override void Execute(ScriptableRenderContext context,
                                    ref RenderingData renderingData)
    {
        CommandBuffer cmd = CommandBufferPool.Get();
        ScriptableRenderer.SetRenderTarget(cmd, m_DestinationColor, m_DestinationDepth,
                                              clearFlag, clearColor);
        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
     }
  }

 

 

 

 

 

 

 

 

 

 

 


WRITTEN BY
CatDarkGame
Technical Artist dhwlgn12@gmail.com

,