BRG를 사용하여 렌더링하는 첫 번째 단계는 BatchRendererGroup의 인스턴스를 생성하고 이를 OnPerformCulling 구현으로 초기화하는 것입니다.
OnPerformCulling 콜백은 BRG의 주요 엔트리 포인트로, 표시되는 오브젝트를 컬링할 때마다 Unity가 호출합니다. 수신하는 파라미터에 대한 자세한 내용은 OnPerformCulling을 참조하십시오. 일반적으로 OnPerformCulling 콜백이 수행해야 하는 두 가지 작업이 있습니다.
간단한 구현에서는 OnPerformCulling 콜백에서 직접 이러한 작업을 수행할 수 있지만, 고성능 구현의 경우 대부분의 작업을 버스트 잡에서 수행하는 것이 가장 좋습니다. OnPerformCulling 콜백은 잡이 출력을 BatchCullingOutput 파라미터에 작성한 후 완료되는 JobHandle을 반환해야 합니다. 구현에 잡을 사용하지 않는 경우 빈 JobHandle을 반환할 수 있습니다.
BatchRendererGroup 오브젝트를 생성한 후, 컴파일을 담당하는 최소 OnPerformCulling 콜백으로 이를 초기화하는 방법에 대한 예시를 아래 코드 샘플에서 확인하십시오.
using System;
using Unity.Collections;
using Unity.Collections.LowLevel.Unsafe;
using Unity.Jobs;
using UnityEngine;
using UnityEngine.Rendering;
public class SimpleBRGExample : MonoBehaviour
{
private BatchRendererGroup m_BRG;
private void Start()
{
m_BRG = new BatchRendererGroup(this.OnPerformCulling, IntPtr.Zero);
}
private void OnDisable()
{
m_BRG.Dispose();
}
public unsafe JobHandle OnPerformCulling(
BatchRendererGroup rendererGroup,
BatchCullingContext cullingContext,
BatchCullingOutput cullingOutput,
IntPtr userContext)
{
// This example doesn't use jobs, so it can return an empty JobHandle.
// Performance-sensitive applications should use Burst jobs to implement
// culling and draw command output. In this case, this function would return a
// handle here that completes when the Burst jobs finish.
return new JobHandle();
}
}
OnPerformCulling을 사용하여 드로우 커맨드를 생성하기 전에 드로우하려는 메시와 사용하려는 머티리얼을 BatchRendererGroup 오브젝트에 제공해야 합니다. 자세한 내용은 다음 주제인 메시 및 머티리얼 등록을 참조하십시오.