Skip to content

Physical based rendering with Vulkan using glTF 2.0 models

License

Notifications You must be signed in to change notification settings

ButchDean/Vulkan-glTF-PBR

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

  • Loading arbitrary glTF 2.0 models
    • Full node hierarchy
    • Full PBR material support
      • Metallic-Roughness workflow
      • Specular-Glossiness workflow (extension)
    • Animations
      • Articulated (translate, rotate, scale)
      • Skinned
      • Morph targets
    • Support for Draco mesh compression (see instructions)

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:

  • KHR_materials_pbrSpecularGlossiness
  • KHR_materials_unlit
  • KHR_materials_emissive_strength
  • KHR_texture_basisu

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

  • In Android Studio, select Import project
  • Select the android sub folder of the repository
  • Once import has finished the project can be build, run and debugged from Android Studio

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:

  • Clone and build https://github.com/google/draco as per their build instructions
  • Copy the Draco decoder library dracodec.lib into libs\draco
  • Copy the src folder contents into external\draco, make sure the draco_features.h is also present
  • If everything is in place, running CMake will output Draco mesh compression enabled and loading Draco compressed meshes will work out of the box

Links

About

Physical based rendering with Vulkan using glTF 2.0 models

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 88.7%
  • GLSL 7.6%
  • CMake 3.5%
  • Java 0.2%