Because the engine uses the Vulkan API, we are required to precompile
the shader files to a bytecode intermediate format. This format is
called SPIR-V. We use the UVKShaderCompiler
as a CLI
tool/library to handle compilation and recompilation of shaders.
The UVKShaderCompiler
can either be invoked by the game
engine at runtime when changes to the shaders are found, or by using the
UVKShaderCompiler
executable.
How it works
The UVKShaderCompiler scans the Config
folder of your
project for shader files, next it generates the MD5 hash of the file and
scans the Generated
directory for any file with that exact
hash as a filename. If no file is found, the shaders get recompiled,
otherwise it continues on to the next shader in the Content
directory.
In production because those hashes are not needed for validating the
shaders, the shaders get compiled into the Content
directory with the original name of the source code file. Then, they get
packaged by the archive and shipped. If any tampering happened in the
archive, the developer can check using the entire archive's hash.
Using the CLI
Since the UVKShaderCompiler
provides a CLI interface,
you can use it for manual compilation. There are 3 options
--help <directory to project>
- for help--complete-regen <directory to project>
- for completely regenerating the cache--compile <directory to project>
- for compiling the cache
Shader formats
The shader compiler can get the following shader formats as input:
.frag
- fragment shader.vert
- vertex shader.comp
- compute shader.geom
- geometry shader.tesc
- tessellation control shader.tese
- tessellation evaluation shader
All you need to do is create a file with the given file extension in
the Content/
directory, and it will automatically be
compiled!
- Home
- Beginner concepts
- Advanced concepts
- Engine developer and contributor resources