Skip to main content

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, Luna utilizes Unity's variants trimming, exporting only the variants that Unity considers required for the set of scenes being exported.

Shaders Tab

In the Luna 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 Luna 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 (Creative Suite or any other ad network build). We recommend having 20 or less shaders for platform builds.


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:

  1. ShaderName
  2. ShaderName/PassName
  3. ShaderName/PassName/Keyword1/Keyword2/…/KeywordN
  4. ShaderName/Keyword1/Keyword2/…/KeywordN
  5. PassName/Keyword1/Keyword2/…/KeywordN
  6. Keyword1/Keyword2/…/KeywordN

For example:


Shaders List

The shaders list allows an easy control over your project's shader variants.


  1. images-xxsmall

    Show/Hide excluded variants in the view.
  2. images-xxsmall 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 Creative Suite builds, Luna will find and apply another that matches it most closely.

  3. images-xxsmall 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.


  1. Shader asset picker - Default Unity asset picker.


  1. Shader pass type dropdown - Contains all shader passes supported by Luna.


  1. Add button - Add selected shader variant to included variants.


  1. Keywords search - Search for keywords using their names or parts of their names.


  1. Keywords selector - Show and toggle all pass keywords supported by Luna.


Luna Shader Variant Collection

Luna 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:

  1. 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.

  2. Shader variants ( Runtime Analysis ): the number of shader variants detected by Runtime Analysis after build.

  3. Shader variants included by user: the number of shader variants that were manually included by the user.

  4. Shader variants excluded by user: the number of shader variants that were manually excluded by the user.

  5. 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 in luna.json, you can prevent Luna 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.