261130 - 렌더링 파이프라인 실습

매콤개발코딩
매콤개발코딩
∙∙조회 6
261130 - 렌더링 파이프라인 실습

1. Unity Statistics(통계)

렌더링 통계는 플레이 모드 중 애플리케이션 실시간 렌더링 정보를 나타낸다.
플레이 모드 중의 게임 뷰에서 Stats 버튼을 눌러 확인할 수 있다.

Graphics 섹션 창에 표시되는 렌더링 통계는 성능 최적화에 유용한 정보를 포함한다.

2. Frame Debugger(분석)

프레임 디버거는 실행 중인 게임을 특정 프레임에서 중지하고
해당 프레임을 렌더링하는 데 사용되는 개별 드로우 콜을 볼 수 있다.

디버거는 드로우 콜의 리스트를 제공하고,
씬이 그래픽 요소에서 어떻게 구성되는지 하나씩 단계별로 볼 수 있게 해준다.

Window > Analysis > Frame Debugger 메뉴에서 불러올 수 있다.

3. 실습 기록

- Statistics와 Frame Debugger 내용 파악하기

1개의 바닥(Plane)과 50개의 몬스터 프리팹(Capsule, clone)을 생성한 상태

칸(가) 같은 머티리얼
Batches219 ~ 221
Saved by batching0
SetPass calls13
Shadow casters112
DrawOpaqueObjects 아래 SRP Batch 개수1
그 SRP Batch의 Draw Calls51
그 SRP Batch의 Batch cause 문구First call from ScriptableRenderLoopJob

- 프레임 디버거의 메인 리스트의 이벤트 별 표시

  • Draw Main Light Shadowmap

  • DrawDepthNormalPrepass

  • Clear (color)

  • SSAO

  • DrawOpaqueObjects

  • DrawSkybox

  • CopyColor

  • BlitFinalToBackBuffer

- 스크립트로 머티리얼 사본을 생성해 오브젝트마다 입힌 후 관측

csharp
using UnityEngine;

public class EnemyTint : MonoBehaviour
{
    [SerializeField] private Color _tint = Color.red;

    private Renderer _renderer;

    private void Awake()
    {
        CacheRenderer();
    }

    private void Start()
    {
        ApplyTint();
    }

    private void CacheRenderer()
    {
        _renderer = GetComponent<Renderer>();
    }

    private void ApplyTint()
    {
        _renderer.material.color = _tint;
    }
}

칸(나) 머티리얼 사본
Batches221
Saved by batching0
SetPass calls13
Shadow casters112
DrawOpaqueObjects 아래 SRP Batch 개수1
그 SRP Batch의 Draw Calls51
그 SRP Batch의 Batch cause 문구First call from ScriptableRenderLoopJob

- 결과

  • 머티리얼 사본 50개가 생겨도 관측한 값에 변경이 없다.
  • Batches가 드로우 콜 횟수 51보다 큰 이유는
    정적 배치, 동적 배치, 인스턴스 배치를 포함하기 때문이다.

- 추가 실습 1

추가 머리티얼을 생성, 셰이더를 바꾸어 런타임 중 일부 몬스터에 적용시킨다.

  • SRP Batch 수가 2로 늘었다.
  • Batch cause 문구가 SRP : Node have different shaders 으로 변경된다.
    현재 객체의 셰이더가 직전 SRP 배치와 달라 새 SRP 배치가 생성되었음을 의미한다.

- 추가 실습 2

EnemyTint 내 ApplyTint 메서드를 MaterialPropertyBlock을 사용하는 메서드로 바꾼다.

csharp
private void ApplyTint()
    {
        MaterialPropertyBlock block = new MaterialPropertyBlock();
        block.SetColor("_BaseColor", _tint);
        _renderer.SetPropertyBlock(block);
    }

  • Frame Debugger 내에서 적들이 그려지는 이벤트가 RenderLoop.Draw 로 변경되었다.