Optimising Shaders
Unity uses a concept of keywords available within shaders. These keywords effectively act as defines
that get enabled and disabled depending on the scene presets, light sources available, and so on.
Each combination of keywords produces a so-called shader variant.
While being very flexible and powerful, such a mechanism is prone to introducing unnecessarily big amount of shader variants. This happens because Unity cannot predict whether certain variants will be used or not: for instance, having a light on the scene forces Unity to generate variants where the light does or does not cast shadows, where the light is directional, spot or point, has or doesn't have a cookie and so on - as all these things can be changed from user's scripts at any time.
If you would like to read more about the reasons behind the number of shader variants in Unity, click here.
By default, Unity Playworks Plugin utilizes Unity's variants trimming, exporting only the variants that Unity considers required for the set of scenes being exported.
Shaders Tab
In the Plugin UI, select Runtime Analysis → Shaders to access the Runtime Analysis Shaders tab.
In this view, you can find a list of any shaders or shader variants that have been activated while testing in a develop build. Use this tab to confirm that Unity Playworks Plugin is using only shaders that are relevant to your project.
After your first develop build you will be able to see your projects shaders and modify them.
If your project contains an excessive number of shaders, you will receive a warning (image below).
This is the total count of shaders that were exported to your develop build.
This is the total count of shaders that were actually used in develop build and will be exported to platform build (Unity Playworks or any other ad network build). We recommend having 20 or less shaders for platform builds.
Search Bar
Users can utilize the search bar to find specific a Shader, Pass or Variant quickly.
The search bar is case-insensitive! Uppercase and lowercase letters are interpreted as the same.
The following search query syntax is available:
- ShaderName
- ShaderName/PassName
- ShaderName/PassName/Keyword1/Keyword2/…/KeywordN
- ShaderName/Keyword1/Keyword2/…/KeywordN
- PassName/Keyword1/Keyword2/…/KeywordN
- Keyword1/Keyword2/…/KeywordN
For example:
Shaders List
The shaders list allows an easy control over your project's shader variants.
Exclude specific shader variants. This affects all build types ( e.g. develop, ads, runtime analysis ).
Be careful!GameObjects using excluded or unsupported shader variants will have the error shader applied. Restoring the excluded variant will fix the problem. When a shader variant isn't found on Unity Playworks builds, Unity Playworks Plugin will find and apply another that matches it most closely.
Include shader variants to the active list or/and removes shaders from excluded list.
Add Shader Variants
Sometimes, if a shader is used/set via script - it cannot be found automatically on build time. However, it's not a problem as you can manually add any Shader/Pass/Variant to the build by using the Add Shader and Variants section in the Shaders Tab. Below you can find a description for each UI element and their functions.
- Shader asset picker - Default Unity asset picker.
- Shader pass type dropdown - Contains all shader passes supported by Luna.
- Add button - Add selected shader variant to included variants.
- Keywords search - Search for keywords using their names or parts of their names.
- Keywords selector - Show and toggle all pass keywords supported by Luna.
Unity Playworks Plugin Shader Variant Collection
Unity Playworks Plugin Shader Variant Collection - or SVC_Luna
- contains all the information about the shader variants that are in the project (created automatically during build process). This file is used to share shader information among the team, and can reside in git.
It provides different information to the users:
Shader variant used on scenes: the count of shader variants that were detected on exported scenes (information collected/renewed at build time). This includes unsupported shader variants as well.
Shader variants ( Runtime Analysis ): the number of shader variants detected by Runtime Analysis after build.
Shader variants included by user: the number of shader variants that were manually included by the user.
Shader variants excluded by user: the number of shader variants that were manually excluded by the user.
Parsed shaders: the number of shaders that were processed and cached during the export stage. Your next export will use these shaders to accelerate the process. In order for them to be deleted, you must delete all shader variants listed above (1-4) because they are dependent on parsed shaders. By setting
useShadersCache = false
inluna.json
, you can prevent Unity Playworks Plugin from using cached shaders.
Modified Shaders
When a shader detected by Runtime Analysis is modified, a warning message appears:
Shaders that have been modified will be removed from the list of shaders and the list of parsed shaders. This means that in the next export, auto-use of parsed shaders will be skipped in order to gather all updated changes and re-process the shaders.
Shader Runtime Analysis
Runtime Analysis can help users to export only the necessary shader variants, reduce build size, and playable startup time.
This feature will record all the shader variants that the engine uses during runtime. After this, the next build export will contain only shader variants grabbed from the Runtime Analysis data.
Shader Runtime Analysis is part of the Runtime Analysis feature and works in parallel with existing code stripping logic.