This demo uses the third-party pygltflib to parse glTF assets and generate HLSL shaders that can be rendered with a fork of the Cauldron glTFSample. The goal is to demonstrate that Metashade can generate sufficiently complex renderable shaders and that it can be integrated with other Python libraries and content production pipelines.
First, clone the repo, recursing into submodules, e.g.
git clone --recurse-submodules https://github.com/metashade/metashade-glTFSample.git
The demo uses the following directory structure:
- glTFSample - submodule pointing at https://github.com/metashade/glTFSample/tree/metashade_demo, which is a fork of https://github.com/GPUOpen-LibrariesAndSDKs/glTFSample - a C++ host app, originally developed by AMD to demo the rendering of glTF assets in DX12 and Vulkan.
- build - the build directory for the above repo.
- DX12 - this directory will be created later by the glTFSample build and will contain the DX12-specific Visual Studio solution generated with CMake. It's added to .gitignore.
- metashade-out - this is where the Metashade demo will generate the HLSL shaders.
- DX12 - this directory will be created later by the glTFSample build and will contain the DX12-specific Visual Studio solution generated with CMake. It's added to .gitignore.
- libs/cauldron - submodule pointing at https://github.com/metashade/Cauldron/tree/metashade_demo, a fork of https://github.com/GPUOpen-LibrariesAndSDKs/Cauldron, AMD's demo rendering framework.
- media/Cauldron-Media - submodule pointing at https://github.com/metashade/Cauldron-Media, cloned from https://github.com/GPUOpen-LibrariesAndSDKs/Cauldron-Media, which contains the glTF assets used in the demo.
- build - the build directory for the above repo.
- metashade - submodule pointing at https://github.com/metashade/metashade
- src - the demo code generating shaders with metashade for rendering with glTFSample.
Building glTFSample
Follow the build instructions in glTFSample/readme.md.
The Python implementation of the demo requires pygltflib to be installed:
pip install pygltflib
src/generate.py usage
--gltf-dir Path to the source glTF assets
--out-dir Path to the output directory
The script processes all glTF asset files it finds under the directory specified by --gltf-dir
and writes the generated shader files to the directory specified by --out-dir
.
The Visual Studio Code launch configurations in .vscode/launch.json execute the above script with the command-line arguments set to the appropriate paths in the demo's directory structure.
In order to use the generated shaders with glTFSample, their parent directory needs to be passed to the executable via a command-line argument:
cd glTFSample\bin
GLTFSample_DX12.exe --metashade-out-dir=..\build\DX12\metashade-out
The names of the generated shader files are derived from the names of glTF meshes and primitives. glTFSample uses the same naming convention to find the right shaders at runtime and use them for rendering.