Vulkan SDF Renderer + Hot Reloader
Quickstart: see QUICKSTART.md for install + first shader.
Render an SDF like ShaderToy using Vulkan and hot reload based on frag shader changes. That way you can use your favourite editor / LSP and also utilise git.
Supports macOS, Linux, and Windows with native file watcher implementations for each platform.
| OS | Support |
|---|---|
| Windows | ✅ Supported |
| Linux | ✅ Supported |
| macOS | ✅ Supported |
Install Vulkan + deps with Homebrew (Quickstart + macOS CI):
brew install molten-vk vulkan-loader glslang glfw glm spdlog vulkan-tools googletesthttps://vulkan.lunarg.com/sdk/home
Then follow the steps to do sudo ./install_vulkan.py in SDK System Paths section
VULKAN_SDK $HOME/VulkanSDK/1.4.328.1/macOS
Install dependencies:
sudo apt-get update
sudo apt-get install -y \
build-essential cmake ninja-build \
libgtest-dev libspdlog-dev \
libglfw3 libglfw3-dev libvulkan-dev \
glslang-tools glslang-dev libglm-dev \- Install vcpkg (if not already installed):
git clone https://github.com/Microsoft/vcpkg.git cd vcpkg .\bootstrap-vcpkg.bat
- Install dependencies using vcpkg (includes Vulkan):
vcpkg install vulkan:x64-windows glfw3:x64-windows glslang:x64-windows spdlog:x64-windows glm:x64-windows gtest:x64-windows vcpkg integrate install
Note: vcpkg provides Vulkan headers and loader, eliminating the need for a separate Vulkan SDK installation.
cmake -B build .
cmake --build build
./build/vsdf {filepath}.fragcmake -B build -DCMAKE_TOOLCHAIN_FILE="C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake" .
cmake --build build --config Release
.\build\Release\vsdf.exe {filepath}.fragHeadless / CI-friendly single-frame run (hide the window and exit after N frames):
./build/vsdf --toy shaders/testtoyshader.frag --frames 1 --headless./build/vsdf --toy path/to/shader.frag./build/vsdf --toy shaders/testtoyshader.fragNote: That if you use --toy we will prepend a template in
shaders/toytemplate.frag which sets up the push constants
like iTime and we will also follow this logic.
if (useToyTemplate) {
Client = glslang::EShClientOpenGL;
ClientVersion = glslang::EShTargetOpenGL_450;
} else {
Client = glslang::EShClientVulkan;
ClientVersion = glslang::EShTargetVulkan_1_0;
}If you don't want any template prepended or you have issues
loading that way, I recommend copying shaders/vulktemplate.frag
and adjusting it to your liking
- See
shaders/vulktemplate.fragto see how push constants are passed in
./build/vsdf path/to/shader.frag--toyPrepend the ShaderToy-compatible template--frames <N>Render N frames then exit (helps CI)--headlessHide the GLFW window (pair withxvfb-runin CI)--log-level <trace|debug|info|warn|error|critical|off>Set spdlog verbosity (default: info)--debug-dump-ppm <dir>Copy the swapchain image before present (adds a stall); mainly for smoke tests or debugging
./build/vsdf shaders/debug_quadrants.frag --toy --headless --frames 1 --debug-dump-ppm out_ppmNow in out_ppm/ you should see an image with 4 quadrants:
- bottom-left: black
- bottom-right: blue
- top-left: red
- top-right: green
Also by running the test suite it will check this automatically
cmake -B build -DBUILD_TESTS=ON -DDEBUG=ON
cmake --build build
./build/tests/vsdf_tests
./build/tests/filewatcher/filewatcher_testscmake -B build -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE="C:/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake" .
cmake --build build --config Debug
.\build\tests\vsdf_tests\Debug\vsdf_tests.exe
.\build\tests\filewatcher\Debug\filewatcher_tests.exenix develop- https://shadertoy.com
- https://iquilezles.org/
- https://www.youtube.com/playlist?list=PL0JVLUVCkk-l7CWCn3-cdftR0oajugYvd (zeux)
- https://github.com/SaschaWillems/Vulkan
(I should try follow this but haven't gotten through it all yet) https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
