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.
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:
- Load the world, adjust necessary rendering settings.
- Open the console.
- 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.
- 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:
-
Run the Engine using the OpenGL API and load your world by specifying the following startup command-line options:
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.
-
Run the Engine using the DirectX API and load your world by specifying the following startup command-line options:
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.
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.
-
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:you should copy shader cache files to the following directory:-project_name "YourProject"
- On Windows, in the C:/Users/<username>/YourProject/
- On Linux, in the /home/<username>/.YourProject/
- Now shader cache files are ready for use.