Version: 2018.4
Optimizing shader variants
Streaming Controller

Texture Streaming

The Texture Streaming system gives you control over which mipmap levels Unity loads into memory. This system reduces the total amount of memory Unity needs for Textures, because it only loads the mipmaps Unity needs to render the current CameraA component which creates an image of a particular viewpoint in your scene. The output is either drawn to the screen or captured as a texture. More info
See in Glossary
position in a SceneA Scene contains the environments and menus of your game. Think of each unique Scene file as a unique level. In each Scene, you place your environments, obstacles, and decorations, essentially designing and building your game in pieces. More info
See in Glossary
, 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.

With the Texture System, you can also use the Memory Budget to set a total memory limit for all Textures to use in a Project. The Texture Streaming system automatically reduces mipmap levels to stay within this budget.

You can use the Texture System API to request specific mipmap levels for specific Textures. Unity provides sample C# code that duplicates the engine logic for mipmap selection, which you can use to override the engine logic for your own Projects. For more details, see Texture Streaming API.

In Unity’s Viking Village demo project, Texture Streaming saves 25–30% of Texture memory, depending on Camera location.

Texture Streaming setup

To enable Texture Streaming, go to Unity’s Quality Settings (Edit > Project SettingsA broad collection of settings which allow you to configure how Physics, Audio, Networking, Graphics, Input and many other areas of your Project behave. More info
See in Glossary
> Quality) and enable the Texture Streaming checkbox. This reveals the settings specific to the Texture Streaming system. For details on each setting, see documentation on Quality Settings.

When you’ve done this, set up Texture Streaming on individual Textures, to allow the Texture Streaming system to stream each Texture’s mipmaps from the disk into memory. To do this, select the Texture you want to apply Texture Streaming to, navigate to the InspectorA Unity window that displays information about the currently selected GameObject, Asset or Project Settings, allowing you to inspect and edit the values. More info
See in Glossary
window and view the Texture Import settings. Open the Advanced settings, and enable the Streaming Mip Maps checkbox.

If you’re developing for Android, you also need to open the Build Settings and set the Compression Method to LZ4 or LZ4HC. Unity requires one of these compressionA method of storing data that reduces the amount of storage space it requires. See Texture Compression, Animation Compression, Audio Compression, Build Compression.
See in Glossary
methods for asynchronous Texture loading, which the Texture Streaming system relies upon.

Unity loads mipmaps at the highest resolution level possible while observing the Texture Memory Budget. For more specific control, or to fine-tune the Texture Streaming system’s automatic results, use the C# API to specify mipmap levels for each Texture. For more details, see Texture Streaming API.

Texture Streaming limitations

You can instruct Mipmap Streaming to calculate the required mipmap levels using one of the following methods:

If you don’t instruct Mipmap Streaming to calculate mipmap levels using one of these methods, Unity can’t calculate which mip level to use. This causes Unity to load the texture using low-quality mips that appear blurry.

The following systems don’t use standard Renderers. This means you must manually set the requested mips for these systems or Unity loads the textures they use at low resolution:

  • Decal projector Textures.
  • Reflection probeA rendering component that captures a spherical view of its surroundings in all directions, rather like a camera. The captured image is then stored as a Cubemap that can be used by objects with reflective materials. More info
    See in Glossary
    Textures: Lower resolution mips are a lookup table for roughness. Therefore, if Unity uses a lower mipmap level, it renders materials using the wrong roughness.
  • Textures in Unity’s TerrainThe landscape in your scene. A Terrain GameObject adds a large flat plane to your scene and you can use the Terrain’s Inspector window to create a detailed landscape. More info
    See in Glossary
    system: Unity does not support Mipmap Streaming on Terrain Textures. This is because Terrain Textures need to be available at full resolution at all times to allow Unity to tile and blend the textures.
  • ShadersA small script that contains the mathematical calculations and algorithms for calculating the Color of each pixel rendered, based on the lighting input and the Material configuration. More info
    See in Glossary
    that handle texture UV coordinates differently from the Unity built-in shaders. Unity always assumes the textures are sampled using UV0 as stored in the MeshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
    See in Glossary
    . Any shader based modifications of the texture coordinates, except for the scale and translation (see below), or the use of UV1, are not taken into account.

When a renderer is active, the mesh that renderer uses requires valid UV distribution metrics to calculate the desired mipmap level. Unity calculates distribution metrics automatically as part of the mesh importing process. You can also calculate this in a script using Mesh.GetUVDistributionMetric.

If you create a mesh from code, Unity does not calculate distribution metrics automatically. This causes Unity to load the wrong mipmaps. For example, it may load low-resolution textures when the camera is close to a mesh. 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 mip level. This means you need to set the Texture mip level manually or disable Mipmap Streaming on this Texture. See Texture2D.requestedMipmapLevel for more details on how to manually set which mip level Unity loads.

When Unity calculates the miplevel for a texture it looks for the scale and translation of that texture in a _ST value with the same name as the texture flagged in your shader. For example, if you reference your textures are in the shader using _MainTex, Unity will look for _MainTex_ST.

Debugging Mipmap Streaming

Unity has a built-in Mipmap Streaming debugging view mode. To access it, click the Scene view control drop-down and select Texture Streaming. This view mode tints GameObjectsThe fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary
the following colours, depending on their status in the Mipmap Streaming system:

  • Green for Textures that have reduced mipmaps due to the Mipmap Streaming system.
  • Red for Textures that have fewer mipmaps because the Mipmap Streaming system does not have enough resources to load them all.
  • Blue for Textures that are not set to stream, or if there is no renderer calculating the mip levels.

You can also write your own custom debug tools and visualizations using the Debugging API

Important : When the main texture is set using the MainTexture attribute, it is not visible in the game view when you use the texture streaming [[wiki:TextureStreaming-API#Debugging|debugging view mode] or a custom debug tool.

Optimizing shader variants
Streaming Controller