SaschaWillems / Vulkan-glTF-PBR

Physical based rendering with Vulkan using glTF 2.0 models
MIT License
915 stars 124 forks source link
gltf gltf2 pbr vulkan

Vulkan physically-Based Rendering using glTF 2.0 models

YouTube Vulkan glTF 2.0 playlist

About

Physically-Based Rendering example implementation with image based lighting in Vulkan using glTF 2.0 models. The lighting equation is based on the reference glTF PBR implementation from Khronos.

glTF 2.0 Model loading

Model loading is implemented in the vkglTF::Model class, using tiny glTF library to import the glTF 2.0 files, so e.g. all file formats supported by tinyglTF are suported. This class converts the glTF structures into Vulkan compatible structures used for setup and rendering.

The following major glTF 2.0 features are currently supported by the vkglTF::Model class:

Note that the model loader does not fully implement all aspects of the glTF 2.0 standard, and as such there is no guarantee that all glTF 2.0 models work properly.

Supported extensions:

Loading different scenes

The repository only includes a basic scene setup with the static "damaged helmet" pbr sample model. The official collection of glTF 2.0 sample models can be found at here.

To load a different scene instead, specify the glTF model file name as a command line argument, e.g.:

Vulkan-glTF-pbr "PATH-TO-glTF-Sample-Models\2.0\BrainStem\glTF\brainstem.gltf"

On Windows the application supports drag and drop. You can simply drop a .gltf or .glb file to load onto the main window.

Texture map generation

The physical based render model uses multiple source images for the lighting equation. Instead of relying on offline tools to generate those, this example will generate all required texture maps during startup using the GPU.

BRDF lookup table

This pass generates a 2D BRDF lookup table based on the formulas used in the pbr implementation. The lookup table contains BRDF values for roughness and view angle and is stored as a 16-bit per component floating point texture to provide proper precision.

See VulkanApplication::generateBRDFLUT()

Irradiance cube map

(left: front face environment cube map / right: front face irradiance cube map)

Generates a small (64 x 64 px) irradiance cube map from that stores the light radiated from the surrounding environment. This is sampled for the indirect diffuse part of the lighting equation.

See VulkanApplication::generateCubemaps() with target IRRADIANCE

Pre-filtered (mip-mapped radiance) environment cube map

(left: front face environment cube map / right: front face prefiltered cube map)

Generates a pre-filtered radiance cube map that is sampled for the indirect specular part of the lighting equation and stores specular contribution based on roughness. The mip chain stores increasing roughness values with increasing level count and is sampled accordingly when rendering the object.

Complete mip chain from left roughness = 0.0 to right roughness = 1.0:

(note: down/up sized to same size for visualization)

See VulkanApplication::generateCubemaps() with target PREFILTEREDENV

Cloning

This repository contains submodules for some of the external dependencies, so when doing a fresh clone you need to clone recursively:

git clone --recursive https://github.com/SaschaWillems/Vulkan-glTF-PBR.git

Updating submodules manually:

git submodule init
git submodule update

Building

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

Windows, Linux

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

Windows:

cmake -G "Visual Studio 14 2015 Win64"

Linux:

cmake .
make

Android

Prerequisites

Building

NOTE: Android SDK API version is set to 33 (Android 13).

How to enable Draco mesh compression

In order to enable support for loading Draco compressed glTF files you need to:

Links