This page has been translated automatically.
Setting Up Development Environment
Usage Examples
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
Double Precision Coordinates
Common Functionality
Controls-Related Classes
Engine-Related Classes
Filesystem Functionality
GUI-Related Classes
Math Functionality
Node-Related Classes
Networking Functionality
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
CIGI Client Plugin
Rendering-Related Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

How to Generate Shader Cache

The shader cache stores a collection of parsed and precompiled shaders. Since the shader code is written with multiple defines, an enormous number of different shaders can be generated. Compiling shaders on demand at runtime causes freezes and requires extra memory. In order to reduce this overhead, all required shader combinations are parsed, compiled, and stored in the shader cache. Loading precompiled shaders from cache is much faster.

Shader cache for OpenGL represents a pre-translation of shaders from UUSL to GLSL, not a compilation. It is generated 5-10 times faster than for DirectX, but uses 5-6 times more disk space.

DirectX shaders cache generated for debug builds should not be used for release builds, as shader compilation is performed without optimizations. Re-generate DirectX shaders cache for your release build for maximum performance (ensured by optimized compilation).

There are no special requirements for shaders caching such as installing or setting up any additional software. Every time when the Engine fails to retrieve a shader from the cache, the required shader is compiled and added to cache automatically.

To generate shaders cache you should do the following:

  1. Load the world, adjust necessary rendering settings.
  2. Open the console.
  3. Execute the shaders_create command. This command will create shaders for all loaded materials and current rendering settings, update the cache, and load all shaders to RAM.

    Usually, generation with the default parameters takes 40-60 minutes.

    You can use the shaders_destroy console command to remove all generated shaders from RAM.

  4. Output shader cache for DirectX / OpenGL will be generated inside the data folder:
    • shader_d3d11.cache
    • shader_gl.cache

Next time you load this world with the selected rendering settings, necessary shaders will be loaded from the cache to RAM on demand.

Usage Example

Suppose your project is completed and final builds are ready to be handed over to customers. So, you want to generate shader cache for both OpenGL and DirectX. To generate cache you should perform the following steps:

Shader cache files for macOS are to be generated separately. You cannot use files generated for Linux or Windows.
  1. Run the Engine using the OpenGL API and load your world by specifying the following startup command-line options:

    Shell commands
    main_x64 -video_app opengl -console_command "world_load <your_world_name>" && shaders_create

    A file named shader_gl.cache containing the OpenGL shader cache will be created in the data directory.

  2. Run the Engine using the DirectX API and load your world by specifying the following startup command-line options:

    Shell commands
    main_x64 -direct3d11 opengl -console_command "world_load <your_world_name>" && shaders_create

    A file named shader_d3d11.cache containing the DirectX shader cache will be created in the data directory.

  3. If your project uses several presets with different rendering settings or several worlds with different rendering settings or materials, the previous two steps (1 and 2) should be repeated for each world and preset. This ensures that all required shaders will be added to cache.

  4. Copy both cache-files (shader_gl.cache and shader_d3d11.cache) to the data directory of the final build.

    If you pass a project name via the command line or on engine initialization:
    Shell commands
    -project_name "YourProject"
    you should copy shader cache files to the following directory:
    • On Windows, in the C:/Users/<username>/YourProject/
    • On Linux, in the /home/<username>/.YourProject/
    • On Mac OS X, in the /Users/<username>/Library/Application Support/YourProject/
  5. Now shader cache files are ready for use.
Last update: 2017-10-20
Build: ()