Skip to content
Examples and demos for the new Vulkan API
C++ Makefile CMake Python Objective-C++ Objective-C Other
Branch: master
Clone or download
Pull request Compare This branch is 12 commits ahead, 504 commits behind SaschaWillems:master.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
android
base Fix FPS calculation under Metal. Dec 19, 2018
bin Added missing assimp dll Feb 16, 2016
bloom Set sampler max. anisotropy to 1.0f instead of 0.0f (valdidation) Jun 17, 2017
cmake Add Wayland WSI support Feb 2, 2017
computecullandlod
computenbody Moved Initializers to vks namespce (Refs SaschaWillems#260) Feb 12, 2017
computeparticles Code cleanup (Refs SaschaWillems#95) Apr 16, 2017
computeshader Set sampler max. anisotropy to 1.0f instead of 0.0f (valdidation) Jun 17, 2017
data
debugmarker Set sampler max. anisotropy to 1.0f instead of 0.0f (valdidation) Jun 17, 2017
deferred
deferredmultisampling Enable required device features (validation) (Refs SaschaWillems#277) Jun 7, 2017
deferredshadows Enable required device features (validation) (Refs SaschaWillems#277) Jun 7, 2017
displacement Code cleanup (Refs SaschaWillems#95) Apr 16, 2017
distancefieldfonts Moved Initializers to vks namespce (Refs SaschaWillems#260) Feb 12, 2017
documentation Added my Khronos Meetup Munich Presentation Apr 9, 2016
dynamicuniformbuffer
external Updated Vulkan headers to 1.0.49 May 19, 2017
gears Moved shaders into separate directory Mar 12, 2017
geometryshader
hdr Update for latest MoltenVK. Jun 12, 2018
images
imgui Added imgui example to CMakeLists.txt [skip ci] Apr 22, 2017
indirectdraw
instancing Enable required device features for instancing example Jun 15, 2017
libs Updates to iOS and macOS functionality using MoltenVK. Jun 22, 2017
mesh Check device features (only build non solid pipelines if feature avai… Mar 8, 2017
multisampling
multithreading Moved thread pool class to vks namespace (Refs SaschaWillems#260) Feb 12, 2017
occlusionquery Fix FPS calculation under Metal. Dec 19, 2018
offscreen Set sampler max. anisotropy to 1.0f instead of 0.0f (valdidation) Jun 17, 2017
parallaxmapping Double tap key for option toggle Mar 25, 2017
particlefire Set sampler max. anisotropy to 1.0f instead of 0.0f (valdidation) Jun 17, 2017
pbrbasic PBR examples minor tweaks and updated screenshots Jun 11, 2017
pbribl PBR examples minor tweaks and updated screenshots Jun 11, 2017
pbrtexture Initial camera position Jun 30, 2017
pipelines Check device features (only build non solid pipelines if feature avai… Mar 9, 2017
pushconstants Code cleanup (Refs SaschaWillems#95) Apr 16, 2017
radialblur Set sampler max. anisotropy to 1.0f instead of 0.0f (valdidation) Jun 17, 2017
raytracing Set sampler max. anisotropy to 1.0f instead of 0.0f (valdidation) Jun 17, 2017
scenerendering Change 'SceneMaterialProperites' to 'SceneMaterialProperties' May 29, 2017
screenshot
screenshots PBR examples minor tweaks and updated screenshots Jun 11, 2017
shadowmapping Set maxAnisotropy to 1.0f instead of 0.0f (Fixes validation errors, r… Jun 1, 2017
shadowmappingomni Set sampler max. anisotropy to 1.0f instead of 0.0f (valdidation) Jun 17, 2017
skeletalanimation Added ETC2 and ASTC texture variants (Refs SaschaWillems#174) Mar 17, 2017
specializationconstants Moved Initializers to vks namespce (Refs SaschaWillems#260) Feb 12, 2017
sphericalenvmapping
ssao Set maxAnisotropy to 1.0f instead of 0.0f (Fixes validation errors, r… Jun 1, 2017
subpasses
terraintessellation Added ETC2 and ASTC texture variants (Refs SaschaWillems#174), only u… Mar 17, 2017
tessellation Updated tessellation text interface Apr 17, 2017
textoverlay Added ETC2 and ASTC texture variants (Refs SaschaWillems#174) Mar 17, 2017
texture Updates to iOS and macOS functionality using MoltenVK. Jun 22, 2017
texture3d Removed unused parameters for image layout transitions and shader loa… Apr 23, 2017
texturearray Removed unused parameters for image layout transitions and shader loa… Apr 23, 2017
texturecubemap Removed unused parameters for image layout transitions and shader loa… Apr 23, 2017
texturemipmapgen Removed unused parameters for image layout transitions and shader loa… Apr 23, 2017
texturesparseresidency added sparseBinding presence check May 9, 2017
triangle
viewportarray Removed unused function Apr 3, 2017
vulkanscene Moved Initializers to vks namespce (Refs SaschaWillems#260) Feb 12, 2017
xcode Updated for compatibility with latest version of MoltenVK. Nov 7, 2018
.gitattributes
.gitignore gitignore Jun 11, 2017
.travis.yml
CMakeLists.txt CMakeLists.txt updated to fix, "visual studio project debug version g… May 26, 2017
LICENSE.md Added Vulkan examples sources! Feb 16, 2016
README.md Merge branch 'master' of https://github.com/SaschaWillems/Vulkan Jun 22, 2017
appveyor.yml appveyor build configuration file Jan 3, 2017
cleanup.bat Added Vulkan examples sources! Feb 16, 2016
download_assets.py Download script and note on (new) additional asset pack [skip ci] Apr 21, 2017
vulkanExamples.sln Textured PBR IBL example Apr 23, 2017
vulkanExamples.vcxproj Added Vulkan examples sources! Feb 16, 2016
vulkanExamples.vcxproj.filters Added Vulkan examples sources! Feb 16, 2016

README.md

Vulkan C++ examples and demos

A comprehensive collection of open source C++ examples for Vulkan(tm), the new graphics and compute API from Khronos.

Donate

Building

The repository contains everything required to compile and build the examples on Windows, Linux and Android using a C++ compiler that supports C++11. All required dependencies are included.

Windows

Build status

A Visual Studio solution file for compiling all examples is included with the repository, examples will compile with VS2015 out of the box.

If you're using a different IDE or compiler you can use the provided CMakeLists.txt for use with CMake to generate a build configuration for your toolchain.

Linux

Build Status

Use the provided CMakeLists.txt with CMake to generate a build configuration for your favorite IDE or compiler.

Note that you need assimp in order to compile the examples for Linux. Either compile and install from the repository, or install libassimp-dev. The examples require at least version 3.2.

Window system integration
  • XCB: Default WSI (if no cmake option is specified)
  • Wayland: Use cmake option USE_WAYLAND_WSI (-DUSE_WAYLAND_WSI=ON)
  • DirectToDisplay: Use cmake option USE_D2D_WSI (-DUSE_D2D_WSI=ON)

Android

Building on Android is done using the Android NDK and requires a device that supports Vulkan. Please see the Android readme on how to build and deploy the examples.

iOS and macOS

Building for iOS and macOS is done using the examples Xcode project found in the xcode directory. These examples use the MoltenVK Vulkan driver to provide Vulkan support on iOS and macOS, and require an iOS or macOS device that supports Metal. Please see the MoltenVK Examples readme for more info on acquiring MoltenVK and building and deploying the examples on iOS and macOS.

Additional asset pack

Note: Binary assets (textures, models) will no longer be added directly to the repository to keep it's size down, so newer examples will require the download of an additional asset pack.

Precompiled binaries

Precompiled binaries for Windows (x64), Linux (x64) and Android can be found here. Note that these may not always be up-to-date with the repository.

Examples

Examples marked with 💬 offer additional details with a separate readme.

Basics

Triangle

Most basic example. Renders a colored triangle using an indexed vertex buffer. Vertex and index data are uploaded to device local memory using so-called "staging buffers". Uses a single pipeline with basic shaders loaded from SPIR-V and and single uniform block for passing matrices that is updated on changing the view.

This example is far more explicit than the other examples and is meant to be a starting point for learning Vulkan from the ground up. Much of the code is boilerplate that you'd usually encapsulate in helper functions and classes (which is what the other examples do).

Pipelines

Pipeline state objects replace the biggest part of the dynamic state machine from OpenGL, baking state information for culling, blending, rasterization, etc. and shaders into a fixed state that can be optimized much easier by the implementation.

This example uses three different PSOs for rendering the same scene with different visuals and shaders and also demonstrates the use of pipeline derivatives.

Texture mapping

Shows how to upload a 2D texture into video memory for sampling in a shader. Loads a compressed texture into a host visible staging buffer and copies all mip levels to a device local optimal tiled image for best performance.

Also demonstrates the use of combined image samplers. Samplers are detached from the actual texture image and only contain information on how an image is sampled in the shader.

Cube maps

Building on the basic texture loading example, a cubemap texture is loaded into a staging buffer and is copied over to a device local optimal image using buffer to image copies for all of it's faces and mip maps.

The demo then uses two different pipelines (and shader sets) to display the cubemap as a skybox (background) and as a source for reflections.

Texture arrays

Texture arrays allow storing of multiple images in different layers without any interpolation between the layers. This example demonstrates the use of a 2D texture array with instanced rendering. Each instance samples from a different layer of the texture array.

Mesh rendering

Uses assimp to load a mesh from a common 3D format including a color map. The mesh data is then converted to a fixed vertex layout matching the shader vertex attribute bindings.

Dynamic uniform buffers 💬

Demonstrates the use of dynamic uniform buffers for rendering multiple objects with different matrices from one big uniform buffer object. Sets up one big uniform buffer that contains multiple model matrices that are dynamically addressed upon descriptor binding time.

This minimizes the number of descriptor sets required and may help in optimizing memory writes by e.g. only doing partial updates to that memory.

Push constants

Demonstrates the use of push constants for updating small blocks of shader data at pipeline creation time, without having to use a uniform buffer. Displays several light sources with position updates through a push constant block in a separate command buffer.

Specialization constants

Demonstrates the use of SPIR-V specialization constants used to specify shader constants at pipeline creation time. The example uses one "uber" shader with different lighting paths (phong, toon, texture mapped) from which all pipelines are build, with a specialization constant used to select the shader path to be used for that pipeline at creation time.

Offscreen rendering

Shows how to do basic offscreen rendering. Uses a separate framebuffer with color and depth attachments (that is not part of the swap chain) to render the mirrored scene off screen in the first pass.

The second pass then samples from the color attachment of that framebuffer for rendering a mirror surface.

Fullscreen radial blur

Demonstrates the basics of a fullscreen (fragment) shader effect. The scene is rendered into a low resolution offscreen framebuffer first and blended on top of the scene in a second pass. The fragment shader also applies a radial blur to it.

Text rendering

Renders a 2D text overlay on top of an existing 3D scene. The example implements a text overlay class with separate descriptor sets, layouts, pipelines and render pass to detach it from the rendering of the scene. The font is generated by loading glyph data from a stb font file into a buffer that's copied to the font image.

After rendering the scene, the second render pass of the text overlay class loads the contents of the first render pass and displays text on top of it using blending.

CPU particles

CPU based point sprite particle system simulating a fire. Particles and their attributes are stored in a host visible vertex buffer that's updated on the CPU on each frame. Demonstrates how to update vertex buffer per frame.

Also makes use of pre-multiplied alpha for rendering particles with different blending modes (smoke and fire) in one single pass.

Advanced

Multi threaded command buffer generation

This example demonstrates multi threaded command buffer generation. All available hardware threads are used to generated n secondary command buffers concurrent, with each thread also checking object visibility against the current viewing frustum. Command buffers are rebuilt on each frame.

Once all threads have finished (and all secondary command buffers have been constructed), the secondary command buffers are executed inside the primary command buffer and submitted to the queue.

Scene rendering

This example demonstrates a way to render a complex scene consisting of multiple meshes with different materials and textures. It makes use of separate per-material descriptor sets for passing texturing information and uses push constants to pass material properties to the shaders upon pipeline creation.

Also shows how to use multiple descriptor sets simultaneously with the new GLSL "set" layout qualifier introduced with GL_KHR_vulkan_glsl.

Instancing

Uses instancing for rendering multiple instances of the same mesh using different attributes. A secondary vertex buffer containing instanced data (in device local memory) is used to pass instanced data to the shader via vertex attributes, including a texture layer index for using different textures per-instance. Also shows how to mix instanced and non-instanced object rendering.

Indirect drawing 💬

This example renders thousands of instanced objects with different geometries using only one single indirect draw call (if multiDrawIndirect is supported). Unlike direct drawing function, indirect drawing functions take their draw commands from a buffer object containing information like index count, index offset and number of instances to draw.

Shows how to generate and render such an indirect draw command buffer that is staged to the device. Indirect draw buffers are the base for generating and updating draw commands on the GPU using shaders.

High dynamic range

Demonstrates high dynamic range rendering using floating point texture and framebuffer formats, extending the internal image precision range from the usual 8 Bits used in LDR to 16/32 bits. Also adds HDR bloom on top of the scene using a separable blur filter and manual exposure via tone mapping.

Occlusion queries

Shows how to use occlusion queries to determine object visibility depending on the number of passed samples for a given object. Does an occlusion pass first, drawing all objects (and the occluder) with basic shaders, then reads the query results to conditionally color the objects during the final pass depending on their visibility.

Run-time mip-map generation 💬

Generates a complete mip-chain at runtime (instead of using mip levels stored in texture file) by blitting from one mip level down to the next smaller size until the lower end of the mip chain (1x1 pixels is reached).

This is done using image blits and proper image memory barriers.

Multi sampling

Demonstrates the use of resolve attachments for doing multisampling. Instead of doing an explicit resolve from a multisampled image this example creates multisampled attachments for the color and depth buffer and sets up the render pass to use these as resolve attachments that will get resolved to the visible frame buffer at the end of this render pass. To highlight MSAA the example renders a mesh with fine details against a bright background. Here is a screenshot without MSAA to compare.

Shadow mapping

Dynamic shadows from a directional light source in two passes. The first pass renders the scene depth from the light's point-of-view into a separate framebuffer attachment with a different (higher) resolution.

The second pass renders the scene from the camera's point-of-view and compares the depth value of the texels with the one stored in the offscreen depth attachment (which the shader directly samples from) to determine whether a texel is shadowed or not and then applies a PCF filter to smooth out shadow borders. To avoid shadow artefacts the dynamic depth bias state (vkCmdSetDepthBias) is used to apply a constant and slope depth bias factor.

Omnidirectional shadow mapping

Dynamic shadows from a point light source. Uses a dynamic 32 bit floating point cube map for a point light source that casts shadows in all directions (unlike projective shadow mapping).

The cube map faces contain the distances from the light sources, which are then used in the final scene rendering pass to determine if the fragment is shadowed or not.

Skeletal animation

This example loads and displays a rigged COLLADA model including animations. Bone weights are extracted for each vertex and are passed to the vertex shader together with the final bone transformation matrices for vertex position calculations.

Bloom

Advanced fullscreen shader example implementing a separated gaussian blur using two passes. The glowing parts of the scene are rendered to a low-resolution offscreen framebuffer that is blurred in two steps and then blended on top of the scene.

Deferred

These examples use a deferred shading setup

Deferred shading

Demonstrates the use of multiple render targets to fill a G-Buffer for a deferred shading setup with multiple dynamic lights and normal mapped surfaces.

Deferred shading collects all values (color, normal, position) into different render targets in one pass thanks to multiple render targets, and then does all shading and lighting calculations based on these in screen space, thus allowing for much more light sources than traditional forward renderers.

Deferred shading and shadow mapping

Building on the deferred shading setup this example adds directional shadows using shadow maps from multiple spotlights.

Scene depth from the different light's point-of-view is renderer to a layered depth attachment using only one pass. This is done using multiple geometry shader invocations that allows to output multiple instances of the same geometry using different matrices into the layers of the depth attachment.

The final scene compositing pass then samples from the layered depth map to determine if a fragment is shadowed or not.

Screen space ambient occlusion

Implements ambient occlusion in screen space, adding depth with the help of ambient occlusion to a scene. The example is using a deferred shading setup with the AO pass using the depth information from the deferred G-Buffer to generate the ambient occlusion values. A second pass is then applied to blur the AO results before they're applied to the scene in the final composition pass.

Physically based rendering

Physical based rendering as a lighting technique that achieves a more realistic and dynamic look by applying approximations of bidirectional reflectance distribution functions that rely on measured real-world material parameters and environment lighting.

Physical shading basics

Basic implementation of a metallic-roughness based physical based rendering model using measured material parameters. Implements a specular BRDF based on material parameters for metallic reflectance, surface roughness and color and displays a grid of objects with varying metallic and roughness parameters light by multiple fixed light sources.

Physical shading with image based lighting

Adds image based lighting to the PBR equation. IBL uses the surrounding environment as a single light source. This adds an even more realistic look the models as the light contribution used by the materials is now controlled by the environment. The sample uses a fixed HDR environment cubemap as for lighting and reflectance. The new textures and cubemaps required for the enhanced lighting (BRDF 2D-LUT, irradiance cube and a filtered cube based on roughness) are generated at run-time based on that cubemap.

Physical shading with textures and image based lighting

This example adds a textured model with materials especially created for the metallic-roughness PBR workflow. Where the other examples used fixed material parameters for the PBR equation (metallic, roughness, albedo), this model contains texture maps that store these values (plus a normal and ambient occlusion map) used as input parameters for the BRDF shader. So even though the model uses only one material there are differing roughness and metallic areas and combined with image based lighting based on the environment the model is rendered with a realistic look.

Compute

Compute shaders are mandatory in Vulkan and must be supported on all devices

Particle system

Attraction based particle system. A shader storage buffer is used to store particle on which the compute shader does some physics calculations. The buffer is then used by the graphics pipeline for rendering with a gradient texture for. Demonstrates the use of memory barriers for synchronizing vertex buffer access between a compute and graphics pipeline

N-body simulation

Implements a N-body simulation based particle system with multiple attractors and particle-to-particle interaction using two passes separating particle movement calculation and final integration.

Also shows how to use shared compute shader memory for a significant performance boost.

Ray tracing

Implements a simple ray tracer using a compute shader. No primitives are rendered by the traditional pipeline except for a fullscreen quad that displays the ray traced results of the scene rendered by the compute shaders. Also implements shadows and basic reflections.

Cull and LOD

Based on indirect drawing this example uses a compute shader for visibility testing using frustum culling and level-of-detail selection based on object's distance to the viewer.

A compute shader is applied to the indirect draw commands buffer that updates the indirect draw calls depending on object visibility and camera distance. This moves all visibility calculations to the GPU so the indirect draw buffer can stay in device local memory without having to map it back to the host for CPU-based updates.

Image processing

Demonstrates the basic use of a separate compute queue (and command buffer) to apply different convolution kernels on an input image in realtime.

Tessellation

Tessellation shader support is optional (see deviceFeatures.tessellationShader)

Displacement mapping

Uses tessellation shaders to generate additional details and displace geometry based on a heightmap.

Dynamic terrain tessellation

Renders a terrain with dynamic tessellation based on screen space triangle size, resulting in closer parts of the terrain getting more details than distant parts. The terrain geometry is also generated by the tessellation shader using a 16 bit height map for displacement. To improve performance the example also does frustum culling in the tessellation shader.

PN-Triangles

Generating curved PN-Triangles on the GPU using tessellation shaders to add details to low-polygon meshes, based on this paper, with shaders from this tutorial.

Geometry shader

Geometry shader support is optional (see deviceFeatures.geometryShader)

Normal debugging

Uses a geometry shader to generate per-vertex normals that could be used for debugging. The first pass displays the solid mesh using basic phong shading and then does a second pass with the geometry shader that generates normals for each vertex of the mesh.

Extensions

VK_EXT_debug_marker

Example application to be used along with this tutorial for demonstrating the use of the new VK_EXT_debug_marker extension. Introduced with Vulkan 1.0.12, it adds functionality to set debug markers, regions and name objects for advanced debugging in an offline graphics debugger like RenderDoc.

Misc

Parallax mapping

Implements multiple texture mapping methods to simulate depth based purely on texture information without generating additional geometry. Along with basic normal mapping the example includes parallax mapping, steep parallax mapping and parallax occlusion mapping, with the later being the best in quality but also with the highest performance impact.

Spherical environment mapping

Uses a (spherical) material capture texture containing environment lighting and reflection information to fake complex lighting. The example also uses a texture array to store (and select) several material caps that can be toggled at runtime.

The technique is based on this article.

Vulkan Gears

Vulkan interpretation of glxgears. Procedurally generates separate meshes for each gear, with every mesh having it's own uniform buffer object for animation. Also demonstrates how to use different descriptor sets.

Distance field fonts

Instead of just sampling a bitmap font texture, a texture with per-character signed distance fields is used to generate high quality glyphs in the fragment shader. This results in a much higher quality than common bitmap fonts, even if heavily zoomed.

Distance field font textures can be generated with tools like Hiero.

Vulkan demo scene

More of a playground than an actual example. Renders the Vulkan logo using multiple meshes with different shaders (and pipelines) including a background.

Credits

Thanks to the authors of these libraries :

And a huge thanks to the Vulkan Working Group, Vulkan Advisory Panel, the fine people at LunarG, Baldur Karlsson (RenderDoc) and everyone from the different IHVs that helped me get the examples up and working on their hardware!

Attributions / Licenses

Please note that (some) models and textures use separate licenses. Please comply to these when redistributing or using them in your own projects :

External resources

You can’t perform that action at this time.