ShaderVariantCollection
ShaderVariantCollection records which shader variants are actually used in each shader.
Read time 5 minutesLast updated 4 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
- Inherits from: Object
public sealed class ShaderVariantCollection : Object
Remarks
This is used for shader preloading ("warmup"), so that a game can make sure "actually required" shader variants are loaded at startup (or level load time), to avoid shader compilation related hiccups later on in the game.
In Unity, many shaders internally have multiple "variants", to account for different light modes, lightmaps, shadows and so on. These variants are identified by a shader pass type, and a set of shader keywords. See ShaderVariantCollection.ShaderVariant.
Typical use of ShaderVariantCollection is to record the shader variants used during a play session from the editor (under Graphics Settings), save them out as an asset, and add to the list of preloaded shaders (again in Graphics Settings). Additionally, you could call ShaderVariantCollection.WarmUp on a ShaderVariantCollection object manually.
ShaderVariantCollection generally replaces the old Shader.WarmupAllShaders function.
Constructors
Constructor | Description |
|---|---|
| ShaderVariantCollection() | Create a new empty shader variant collection. |
Properties
Property | Description |
|---|---|
| isWarmedUp | Is this ShaderVariantCollection already warmed up? (Read Only) |
| shaderCount | Number of shaders in this collection (Read Only). |
| variantCount | Number of total variants in this collection (Read Only). |
| warmedUpVariantCount | Number of total variants in this collection that are already warmed up (Read Only). |
Methods
Method | Description |
|---|---|
| Add | Adds a new shader variant to the collection. |
| Clear | Remove all shader variants from the collection. |
| Contains | Checks if a shader variant is in the collection. |
| Remove | Removes shader variant from the collection. |
| WarmUp | Prewarms all shader variants in this shader variant collection. |
| WarmUpProgressively | Prewarms the given number of shader variants in this shader variant collection. |
Structs
Struct | Description |
|---|---|
| ShaderVariantCollection.ShaderVariant | Identifies a specific variant of a shader. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |