Version: 2023.2
언어: 한국어
밉맵 소개
밉맵 스트리밍 시스템 API

밉맵 스트리밍 시스템

밉맵 스트리밍 시스템을 사용하여 Unity가 밉맵을 로드하는 방법을 제어할 수 있습니다.

이 페이지는 다음에 관한 정보를 제공합니다.

API를 사용하여 텍스처 스트리밍 시스템의 기능을 확장하는 방법에 대한 자세한 내용은 밉맵 스트리밍 시스템 API를 참조하십시오.

개요

This system forces Unity to only load the mipmap levels needed to render the current Camera position, instead of loading all of them by default. It trades a small amount of CPU resources to save a potentially large amount of GPU memory.

You can set a total memory limit for all textures in an application, and the system automatically reduces mipmap levels to stay within this budget.

Unity의 Viking Village 데모 프로젝트에서는 밉맵 스트리밍 시스템이 카메라 위치에 따라 텍스처 메모리를 25–30% 절감합니다.

시작

밉맵 스트리밍 활성화

밉맵 스트리밍을 활성화하려면 Unity의 품질 설정(Edit > Project Settings > Quality)으로 이동하여 Texture Streaming 체크박스를 활성화합니다.

이 설정을 활성화하면 품질 설정 창에 밉맵 스트리밍 시스템과 관련된 설정이 표시됩니다. 각 설정에 대한 자세한 내용은 품질 설정 문서를 참조하십시오.

기본적으로 이 설정은 프로젝트에서 모든 카메라에 대한 밉맵 스트리밍을 활성화합니다.

밉맵 스트리밍 시스템과 함께 작동하는 텍스처 생성

이제 개별 텍스처에 밉맵 스트리밍을 설정할 수 있습니다.텍스처 에셋을 선택하고 인스펙터 창으로 이동하여 텍스처 임포트 설정을 확인합니다.Advanced 설정을 열고 Mip Streaming 체크박스를 활성화합니다.

Android용 개발인 경우 빌드 설정을 열어 Compression MethodLZ4 또는 LZ4HC 로 설정해야 합니다. 이 압축 방식 중 하나를 밉맵 스트리밍 시스템이 기반을 두는 비동기 텍스처 로딩에 사용해야 합니다.

Unity loads mipmap levels at the highest resolution possible while observing the memory budget. You can configure the priority of a texture with the Mip Streaming > Priority setting in the Texture Import Settings.

Unity는 이 설정을 사용하여 다음을 결정합니다.

  • 리소스를 할당할 때 텍스처의 우선순위
  • As a mipmap bias value when choosing a mipmap level that fits in the memory budget. For example, with a priority of 2, the mipmap streaming system tries to use a mipmap two levels higher than Textures with a priority of 0.

양수는 더 높은 우선순위를 부여합니다. 유효한 값의 범위는 –128에서 127 사이입니다.

스트리밍 라이트맵

You can use the Mipmap Streaming system to stream mipmap levels for lightmaps.

다른 텍스처와 동일한 방식으로 라이트맵 에셋의 밉맵 스트리밍 설정을 편집할 수 있지만 Unity가 라이트맵을 다시 생성하면 기본값으로 재설정됩니다. 이 문제를 해결하려면 Unity가 라이트맵을 생성할 때 이러한 값을 적용하도록 지시할 수 있습니다. 플레이어 설정(Edit > Project Settings > Player)은 생성된 라이트맵에 대해 스트리밍과 우선 순위를 설정할 수 있도록 두 가지 제어 옵션, 즉 Lightmap Streaming EnabledStreaming Priority 를 제공합니다.

밉맵 스트리밍을 활성화하고 우선순위를 설정하면 일반 텍스처와 동일한 방식으로 라이트맵에 작동합니다.

밉맵 스트리밍 설정

Unity 에디터에서 기본 설정으로 설정한 다음 필요한 경우 밉맵 스트리밍 API를 사용하여 이 설정을 오버라이드할 수 있습니다.

메모리 할당량 설정

Memory Budget 프로퍼티는 Unity가 텍스처에 소모하는 최대 메모리 양을 정합니다. 가용 메모리 할당량이 너무 작으면 Unity가 씬 내 텍스처의 해상도를 낮추며, 이로 인해 텍스처가 건너뛰기되거나 느리게 로드될 수 있습니다. 단, 가용 메모리는 다른 리소스에게도 메모리가 돌아가도록 가능한 한 작게 설정해야 합니다.

Texture Streaming > Memory Budget 프로퍼티를 사용하여 Quality Settings 창에서 메모리 할당량을 설정합니다.

메모리 할당량이 가득 차면 Unity는 사용하지 않는 밉맵을 폐기하여 사용할 공간을 확보합니다. Max Level Reduction 으로 사용하지 않은 밉맵을 얼마나 많이 폐기할지 제어할 수 있습니다.

이 값은 밉맵 스트리밍 시스템이 시작할 때 처음 로드하는 밉맵 레벨이기도 합니다. 예를 들어 이 값을 2로 설정하면 Unity는 첫 번째 로드 시 가장 높은 두 개의 밉맵을 건너뜁니다.

Texture Streaming > Max Level Reduction 프로퍼티를 사용하여 Quality Settings 창에서 이 값을 설정합니다.

참고: Unity는 메모리 할당량보다 Max Level Reduction 값을 우선합니다. 텍스처 메모리가 할당량을 초과하더라도 Max Level Reduction 값보다 더 많은 밉맵을 폐기하지 않습니다.

메모리 할당량에는 밉맵 스트리밍을 사용하지 않는 텍스처가 포함됩니다. 예를 들어 메모리 할당량이 100MB이고 밉맵 스트리밍을 사용하지 않는 텍스처가 90MB인 경우 Unity는 나머지 10MB에 모든 스트리밍 밉맵을 맞추려고 합니다. 그렇지 않으면 낮은 해상도로 로드합니다. Unity는 메모리 할당량을 초과하더라도 전체 해상도에서 밉맵 스트리밍을 사용하지 않는 텍스처를 항상 로드합니다.

적절한 가용 메모리를 파악하려면 다음을 수행하십시오.

  1. 프로젝트 실행 중 Texture.desiredTextureMemory 값을 확인합니다.
  2. Memory Budget 값을 Texture.desiredTextureMemory 값보다 조금 더 높게 설정합니다.

이렇게 하면 씬에서 가장 리소스가 많이 소요되는 영역을 위한 텍스처 메모리를 충분히 확보할 수 있으며, 텍스처의 해상도가 저하되는 일을 방지할 수 있습니다. 여유 메모리가 있다면 Unity가 씬에서 보이지 않는 텍스처 데이터를 스트리밍 캐시 내에 유지할 수 있도록 가용 메모리를 좀 더 크게 설정해도 됩니다.

카메라 설정

기본적으로 밉맵 스트리밍 시스템을 활성화하면 Unity가 모든 카메라에 대해 활성화합니다. 원하는 경우 이 설정을 비활성화할 수 있습니다.

Unity가 Texture Streaming > Add All Cameras 프로퍼티를 사용하여 Quality Settings 창에서 모든 카메라에 대한 밉맵 스트리밍을 활성화할지를 설정합니다.

특정 카메라를 제외하려면 해당 카메라에 Streaming Controller 컴포넌트를 추가한 다음 비활성화합니다.

Add All Cameras를 비활성화하면 카메라별 밉맵 스트리밍을 활성화해야 합니다. 이렇게 하려면 Streaming Controller 컴포넌트를 Camera 컴포넌트와 동일한 게임 오브젝트에 추가합니다.

This component also allows you to adjust the mipmap bias setting per-Camera.

Streaming Controller 컴포넌트
Streaming Controller 컴포넌트

에디터 스트리밍 설정 지정

Edit > Project Settings > Editor에 있는 스트리밍 설정
Edit > Project Settings > Editor에 있는 스트리밍 설정

에디터의 밉맵 스트리밍(텍스처 스트리밍이라고도 함)은 기본적으로 활성화되어 있지만, Quality Settings에서 Texture Streaming을 활성화하고 텍스처 에셋의 임포트 설정 중 하나 이상에서 Mipmap Streaming을 활성화한 경우에만 효과가 나타납니다.

Unity가 에디터에서 플레이 모드와 편집 모드 모두에서 밉맵 스트리밍을 사용할지를 개별적으로 제어할 수 있습니다.이렇게 하려면 Project Settings > Editor > Streaming Settings로 이동합니다.

에디터에서 밉맵 스트리밍을 한 모드에서만 활성화하고 다른 모드에서는 활성화하지 않은 경우, 플레이 모드를 시작하고 종료하는 데 시간이 약간 더 걸립니다.밉맵 스트리밍을 두 모드에서 모두 활성화하면 Unity가 밉맵 데이터를 언로드 및 재로드하지 않아도 되며, 플레이 모드를 시작하고 종료하는 속도가 빨라집니다.

The “Load texture data on demand” setting enables further optimizations in the Editor for textures which have mipmap streaming enabled, which:

  • 디스크에서 메모리에 텍스처 데이터를 비동기적으로 로드
  • Only loads the mipmap levels required by current camera views
  • 현재 품질 설정에 대한 텍스처 스트리밍 메모리 할당량 내에서 작업을 시도

These optimizations avoid some stalls, make loading slightly faster, and reduce the amount of CPU memory used. However, this setting can cause mipmapped textures to temporarily appear at a lower resolution than they should while a higher resolution version is loaded in. This feature incurs some overhead on the CPU, so you might want to leave this disabled if your textures all fit in memory at once, or you don’t have any textures set up to stream.

밉맵 스트리밍 디버깅

Unity에는 빌트인 밉맵 스트리밍 디버깅 뷰 모드가 있습니다. 이 모드에 액세스하려면 씬 뷰 컨트롤 드롭다운을 클릭한 후 Texture Streaming 을 선택하십시오. 이 뷰 모드는 밉맵 스트리밍 시스템의 상태에 따라 게임 오브젝트에 다음 컬러를 입힙니다.

  • 녹색 : 밉맵 스트리밍 시스템으로 인해 밉맵 수가 감소한 텍스처.
  • 빨간색: 밉맵 스트리밍 시스템에 모든 밉맵을 로드할 만큼 리소스가 충분하지 않아서 적은 수의 밉맵을 가진 텍스처.
  • Blue for Textures that are not set to stream, or if there is no renderer calculating the mipmap levels.

디버깅 API를 사용하여 직접 커스텀 디버그 툴 및 시각화를 작성할 수도 있습니다.

중요 :MainTexture 속성을 사용하여 설정된 메인 텍스처는 텍스처 스트리밍 디버깅 뷰 모드 또는 커스텀 디버그 툴을 사용하는 경우 게임 뷰에 표시되지 않습니다.

How Unity calculates the required mipmap level

For textures that use Mipmap Streaming, Unity calculates the correct mipmap level using one of the following methods:

  • If you assign the texture to a material that is used by a Unity Renderer componennt, Unity calculates the mipmap level automatically.
  • Otherwise, you must request mipmap levels manually using Texture2D.requestedMipmapLevel.

If you don’t do this, Unity can’t calculate the correct mipmap level, and it loads the texture using low-resolution mipmap levels. These can appear blurry.

Note: The following systems don’t use standard Renderer components. This means you must manually set the requested mipmap levels for these systems:

  • 데칼 프로젝터 텍스처.
  • Reflection probe textures: Lower resolution mipmap levels are a lookup table for roughness. Therefore, if Unity uses a lower mipmap level, it renders materials using the wrong roughness.
  • Mesh.uv(UV0이라고도 함) 이외의 채널에서 UV 텍스처 좌표를 사용하는 셰이더 또는 셰이더에서 텍스처 좌표를 변경하는 셰이더. 단, 스케일 및 변환 변경은 예외입니다(아래 참조).

제한 사항

  • Unity는 터레인 텍스처에서 밉맵 스트리밍을 지원하지 않습니다. Unity가 터레인 텍스처를 타일화하고 블렌딩하려면 터레인 텍스처가 항시 전체 해상도로 제공되어야 하기 때문입니다.
  • When a Renderer component is active, its mesh requires valid UV distribution metrics to calculate the desired mipmap level. Unity calculates distribution metrics automatically as part of the mesh importing process.

    If you create a mesh from code, Unity does not calculate distribution metrics automatically and therefore it loads the wrong mipmap levels. To manually trigger the UV distribution metric calculation use Mesh.RecalculateUVDistributionMetrics.
  • When Unity renders a streamed Texture directly with an API (such as Graphics.DrawMeshNow) the system has no renderer bounds or other information to calculate the mipmap level. This means you need to set the Texture mipmap level manually or disable Mipmap Streaming on this Texture. See Texture2D.requestedMipmapLevel for more details on how to manually set which mipmap level Unity loads.
  • Unity는 텍스처의 밉 레벨을 계산할 때 셰이더에서 플래그된 텍스처와 이름이 같은 _ST 값에서 해당 텍스처의 스케일과 변환을 찾습니다. 예를 들어 _MainTex를 사용하여 셰이더에 있는 텍스처를 레퍼런스하면 Unity는 _MainTex_ST를 찾습니다.
밉맵 소개
밉맵 스트리밍 시스템 API