(c) 2017 - 2018 Michał Siejak (@Nadrin)
An implementation of physically based shading model & image based lighting in various graphics APIs.
API | SLOC | Implementation status |
---|---|---|
OpenGL 4.5 | 508 | Done |
Vulkan | 1843 | Done |
Direct3D 11 | 673 | Done |
Direct3D 12 | 1205 | Done |
The goal of this project is to showcase the use of various modern graphics APIs and to provide a clear side-by-side comparison of them. I believe that an implementation of physically based shading is a sufficiently non-trivial use case for that comparison to be useful.
Each implementation is completely self contained within a single source/header pair residing directly in src
directory.
The coding style is mostly procedural ("C with classes") using simple POD structs for grouping related data together.
This was done for simplicity, readability, and to not impose any particular renderer design/organization.
Shared functionality (loading of images & 3D models, application event loop & entry point, misc utility functions)
can be found in src/common
directory.
Please note that it was not my goal to try to come up with the most efficient/optimized use of each API. The rendered scene is very simple anyway (only handful of drawcalls, mostly static data), and when in doubt I tried to refrain from using "clever" tricks and went for simple solutions.
Shaders are heavily commented because there's where interesting stuff happens. :)
- Windows 10 or Windows Server 2016 (x64 versions)
- Visual Studio 2017 (any edition)
- Relatively recent version of Windows 10 SDK
- LunarG Vulkan SDK
Visual Studio solution is available at projects/msvc2017/PBR.sln
. After successful build the resulting executable
and all needed DLLs can be found in data
directory. Note that precompiled third party libraries are only available
for x64 target.
- C/C++ compiler supporting C++14
- CMake 3.8 or newer
- pkg-config
- glslang from Khronos
- Development files for GLFW3, Assimp, OpenGL & Vulkan
- Install prerequisites; for Debian/Ubuntu:
sudo apt install build-essential cmake pkg-config libglfw3-dev libassimp-dev libgl1-mesa-dev libvulkan-dev
-
Download & install glslang. Make sure that
glslangValidator
binary is inPATH
or in/opt/glslang/bin
. -
Configure & build the project:
mkdir -p projects/cmake/build
cd projects/cmake/build
cmake ..
make install
- After successful build the resulting executable can be found in
data
directory.
Make sure to run from within data
directory as all paths are relative to it. API to be used can be specified on the command line
as a single parameter (-opengl
, -vulkan
, -d3d11
, or -d3d12
). When run with no parameters -d3d11
is used
on Windows, and -opengl
on other platforms.
Input | Action |
---|---|
LMB drag | Rotate camera |
RMB drag | Rotate 3D model |
Scroll wheel | Zoom in/out |
F1-F3 | Toggle analytical lights on/off |
This implementation of physically based shading is largely based on information obtained from the following courses:
- Real Shading in Unreal Engine 4, Brian Karis, SIGGRAPH 2013
- Moving Frostbite to Physically Based Rendering, Sébastien Lagarde, Charles de Rousiers, SIGGRAPH 2014
Other resources that helped me in research & implementation:
- Adopting Physically Based Shading Model, Sébastien Lagarde
- Microfacet Models for Refraction through Rough Surfaces, Bruce Walter et al., Eurographics, 2007
- An Inexpensive BRDF Model for Physically-Based Rendering, Christophe Schlick, Eurographics, 1994
- GPU-Based Importance Sampling, Mark Colbert, Jaroslav Křivánek, GPU Gems 3, 2007
- Hammersley Points on the Hemisphere, Holger Dammertz
- Notes on Importance Sampling, Tobias Franke
- Specular BRDF Reference, Brian Karis
- To PI or not to PI in game lighting equation, Sébastien Lagarde
- Physically Based Rendering: From Theory to Implementation, 2nd ed., Matt Pharr, Greg Humphreys, 2010
- Advanced Global Illumination, 2nd ed., Philip Dutré, Kavita Bala, Philippe Bekaert, 2006
- Photographic Tone Reproduction for Digital Images, Erik Reinhard et al., 2002
This project makes use of the following open source libraries:
- Open Asset Import Library
- stb_image
- GLFW
- GLM
- D3D12 Helper Library
- glad (used to generate OpenGL function loader)
- volk (meta loader for Vulkan API)
The following assets are bundled with the project:
- "Cerberus" gun model by Andrew Maximov.
- HDR environment map by Bob Groothuis obtained from HDRLabs sIBL archive (distributed under CC-BY-NC-SA 3.0).