Skip to content

danilw/vulkan-shadertoy-launcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vulkan-shadertoy-launcher

what is it launcher for shadertoy shaders in Vulkan.

Use case - launch your own shaders outside of shadertoy, or create a small single-bin(exe) file with built-in shaders, for demo-like apps. This code does not have Vulkan validation errors (and tested on Nvidia/AMD/Intel GPU-s).

Minimal size after upx compression - 30Kb, and using less than 1k lines of shader code building with yariv-shaders bin(exe)-size will be ~50Kb.

Do not use UPX - reason upx/upx#337

Dependencies for compiling - Vulkan SDK. MSVS or MinGW compiler for Windows. Linux requires xcb and xcb-keysyms library or wayland-devel.

Used Vulkan 1.0 and only single extension VK_KHR_swapchain VK_KHR_SWAPCHAIN_EXTENSION_NAME that on 100% devices with Vulkan.

Compiler/platform support - VisualStudio, GCC/Clang, Mingw. OS Windows and Linux(X11/Wayland)

Multiple GPU support - Added launch option --gpu X to use selected GPU device X. Value X is 0 or 1 or 2 etc. By default, selected first GPU which supports graphics and presentation prioritizing DISCRETE_GPU.

Wayland note - by default selected discrete GPU and if it Nvidia it does not support Wayland surface, to launch Wayland build select gpu that support Wayland in launch option --gpu 0 0/1/2 etc.

Bin builds download:

Download from releases.

Example shader in this download - shadertoy link shader use buffers cross-reading, feedback logic, and example for texture and keyboard support, only as an example that logic work same as on shadertoy.

Apps that I made using this code: GLSL Auto Tetris, GLSL Card game in the single shader, likes (GLSL game), Game for Cactus Jam


How to use:

  1. Download Bin build or build the project. (notice empty_template_shadertoy.zip in Release downloads)

  2. Open your shadertoy shader and copy-paste its code to shaders/shadertoy/*.glsl files.

  3. Small setup. If buffers not needed(for shadertoy-test template), can be used simple dummy code for unused buffers:

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    discard;
}

For release, when you want build/pack single minimal application - remember about VRAM usage, by default I use four(x2 double buffering) RGBA32 buffers, if you dont need that much look main.c code to set number of used buffers)

shadertoy textures can be found on Shadertoy Unofficial

Binding:

buffers - iChannels[0-3] and iChannel0-3 defined in the shaders/src/*.frag files.

Warning: do not redefine #define iChannel0 iChannel1. To change order edit launcher/shaders/src/*.frag and change order there.

textures - iTextures[0-3] is images from *.png files.

keyboard - iKeyboard shadertoy keyboard.

  1. Compile shaders to *.spv using glslangValidator commands in the shaders/build_shaders.cmd or shaders/build_shaders.sh

  2. Launch VK_shadertoy_launcher.exe and shader should work the same as on shadertoy


Supported:

TODO list of missing featres #4

Full-screen triangle used to render every buffer, same as on Shadertoy.

Buffers (no mipmap), textures (mipmap supported), keyboard, and mouse (same as on shadertoy).

Discard disabled by default (in the release build also disabled), to enable it in launcher/main.c change VK_C_CLEAR to VK_KEEP (use search).

Warning as Image-shader I use number of framebuffers from vk_get_swapchain_images it may be 1 or 2 or 3 or more, depends of GPU, that means discard will not work(in most cases) on Image-shader. I do not recommend using discard. if you have setup with tile-like render - then just move Image-shader to buffer(iChannel) and replace discard with reading previous frame as example look this tile shader (look comment for buffers), and in Image-shader display that buffer(iChannel).

Not supported - audio/video, cubemaps, 3d texture.

Not implemented Uniforms - iSampleRate does not exist, iChannelTime does not exist, iFrameRate does not exist, iChannelResolution use in shader textureSize instead.


Configuration:

To build minimal bin(exe) - a number of used buffers can be configured, stb_image can be disabled and yariv-shader format can be used to compress shaders. Look for USEFUL defines in the main.c file.

When you have just a single shader, and buffers not needed - use vulkan-shader-launcher


Building:

git clone https://github.com/danilw/vulkan-shadertoy-launcher

Use cmake to build:

Using VS2019 in the Windows (open links to see tutorial screenshot):

  1. Download and install Vulkan SDK.
  2. Launch VS press Continue without code and File-Open-CMake select CMakeLists.txt file.
  3. Press Manage Configureations and Add new configuration select x64 Release.
  4. In General Configuration type set MinSizeRel and press Ctrl+S to save.
  5. Then select created configuration and press Build-Build All.
  6. Compiled build location launcher\out\build\x64-Release\Vk_shadertoy.exe, to launch required folder shaders and textures.

In the Linux use command:

cd launcher
mkdir build
cd build
cmake ..
make

To build with Wayland in CMakeLists.txt set OPTION(USE_WAYLAND_LINUX "use Wayland for Linux" ON) by default used X11. If your system missing Wayland xdg-shell, then look on Building without cmake below.

Building without cmake:

First go to one of folders - Wayland cd build_scripts/build_linux_wayland or x11 cd build_scripts/build_linux_x11 or mingw cd build_scripts/build_mingw_win

Launch sh build.sh, or sh build_yariv.sh to have compressed single bin-file with buildin-shaders.

To build yariv-shaders cd build_scripts/yariv_shaders and sh build_shaders_yariv.sh. Remember yariv_pack file needs run permissions, or build it from source in build_scripts/yariv/ and move to yariv_shaders folder.

To generate Wayland xdg-shel headers usesh gen_wayland_header.sh in the build_linux_wayland folder.


This project includes prebuild files:

build_scripts/win_vk_dll/vulkan-1.dll file from Vulkan SDK needed to build using mingw.

build_scripts/yariv_shaders/yariv_pack this is compiled file, its source build_scripts/yariv/main.c, needed to generate yariv shaders.

build_scripts/yariv_shaders/bin folder with pre-build yariv shaders.


Images:

img