반응형
URP 16.0.3 기준, ScriptableRenderFeature & Pass API가 변경되면서 이전 버전 코드를 수정하지 않으면 에러가 발생합니다.
참고자료
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);
}
}
반응형
'Unity > TA' 카테고리의 다른 글
SRP Batcher GLES & Vulkan 비교 (0) | 2023.11.14 |
---|---|
CustomInspector CategoryHeaderGUI - 어두운 폴드바GUI (0) | 2023.10.12 |
URP 15 데칼 레이어 분석 & 구현 방법 (1) | 2023.08.31 |
URP 15.0.5 데칼 레이어 렌더링 이슈 (0) | 2023.07.25 |
[번역] Arm Mali GPU Training Series Ep 2.6 : Shader best practices (0) | 2023.07.24 |
WRITTEN BY
- CatDarkGame
Technical Artist dhwlgn12@gmail.com
,