An implementation of physically based shading & image based lighting in D3D11, D3D12, Vulkan, and OpenGL 4.

Overview

Physically Based Rendering

(c) 2017 - 2018 Michał Siejak (@Nadrin)

An implementation of physically based shading model & image based lighting in various graphics APIs.

Screenshot

API SLOC Implementation status
OpenGL 4.5 508 Done
Vulkan 1843 Done
Direct3D 11 673 Done
Direct3D 12 1205 Done

About

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. :)

Building

Windows

Prerequisites

  • Windows 10 or Windows Server 2016 (x64 versions)
  • Visual Studio 2017 (any edition)
  • Relatively recent version of Windows 10 SDK
  • LunarG Vulkan SDK

How to build

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.

Linux

Prerequisites

  • C/C++ compiler supporting C++14
  • CMake 3.8 or newer
  • pkg-config
  • glslang from Khronos
  • Development files for GLFW3, Assimp, OpenGL & Vulkan

How to build

  1. Install prerequisites; for Debian/Ubuntu:
sudo apt install build-essential cmake pkg-config libglfw3-dev libassimp-dev libgl1-mesa-dev libvulkan-dev
  1. Download & install glslang. Make sure that glslangValidator binary is in PATH or in /opt/glslang/bin.

  2. Configure & build the project:

mkdir -p projects/cmake/build
cd projects/cmake/build
cmake ..
make install
  1. After successful build the resulting executable can be found in data directory.

macOS

Help wanted.

Running

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.

Controls

Input Action
LMB drag Rotate camera
RMB drag Rotate 3D model
Scroll wheel Zoom in/out
F1-F3 Toggle analytical lights on/off

Bibliography

This implementation of physically based shading is largely based on information obtained from the following courses:

Other resources that helped me in research & implementation:

Third party libraries

This project makes use of the following open source libraries:

Included assets

The following assets are bundled with the project:

Comments
  • Failed to load mesh file: meshes/cerberus.fbx

    Failed to load mesh file: meshes/cerberus.fbx

    Direct3D 11 Renderer [NVIDIA GeForce GTX 965M] Compiling HLSL shader: shaders/hlsl/pbr.hlsl [main_ps] Compiling HLSL shader: shaders/hlsl/pbr.hlsl [main_vs] Compiling HLSL shader: shaders/hlsl/skybox.hlsl [main_ps] Compiling HLSL shader: shaders/hlsl/skybox.hlsl [main_vs] Compiling HLSL shader: shaders/hlsl/tonemap.hlsl [main_ps] Compiling HLSL shader: shaders/hlsl/tonemap.hlsl [main_vs] Loading mesh: meshes/cerberus.fbx Assimp: Error, T7892: FBX-Parser (TOK_DATA, line 1, col 8) unexpected token, expected TOK_KEY Error: Failed to load mesh file: meshes/cerberus.fbx

    opened by ychding11 3
  • Missing license (file)

    Missing license (file)

    First of all thank you for sharing your implementation on Github! For other's to contribute and also to use your implementation, it would be great if you could add a license. I know that beggars can't be choosers, but a permissive license would be most welcome.

    https://help.github.com/en/articles/adding-a-license-to-a-repository

    opened by souljedi 3
  • All asset data held hostage by LFS

    All asset data held hostage by LFS

    I cannot access any of the data files. I get this LFS error:

    This repository is over its data quota. Account responsible for LFS bandwidth should purchase more data packs to restore access.
    
    opened by jcoffland 2
  • Which assimp version did you use?

    Which assimp version did you use?

    Hi, thanks for sharing this cool project. I am wondering which assimp version are you using? I tried 3.2 and 4.1 and both versions give me some errors.

    question 
    opened by fxia22 2
  • Failed to load mesh file: meshes/skybox.obj

    Failed to load mesh file: meshes/skybox.obj

    I compiled this project in Ubuntu 18.04, but have such error:

    `./PBR

    OpenGL 4.5 Renderer [Mesa DRI Intel(R) UHD Graphics 620 (Kabylake GT2) ] Compiling GLSL shader: shaders/glsl/tonemap_vs.glsl Compiling GLSL shader: shaders/glsl/tonemap_fs.glsl Loading mesh: meshes/skybox.obj Assimp: Error, T0: Validation failed: aiScene::mNumMeshes is 0. At least one mesh must be there Error: Failed to load mesh file: meshes/skybox.obj`

    opened by zim32 1
  • Can't clone this project completely.

    Can't clone this project completely.

    Error downloading object: data/environment.hdr (f139d4c): Smudge error: Error do wnloading data/environment.hdr (f139d4c699dc27a0b2c3a110955469b2d293e5ed94984e2d da61717a5214ce9b): batch response: This repository is over its data quota. Accou nt responsible for LFS bandwidth should purchase more data packs to restore acce ss. Errors logged to C:\src\PBR.git\lfs\logs\20191122T175645.259632.log

    opened by zinwalin 1
  • If vulkan version miss some .spv files?

    If vulkan version miss some .spv files?

    When I run PBR -vulkan on Windows, it first threw the VK_ERROR_LAYER_NOT_PRESENT ERROR, then I modified the related code not to load layers, then run again, it threw the Error: Could not open file: shaders/spirv/tonemap_vs.spv But I didn't find the tonemap_vs.spv in the shaders dir. Is there anything missed?

    opened by irimsky 2
  • vk renderer update

    vk renderer update

    Hi~ I'm new to vulkan. very happy to see your pbr demo source, it helps me a lot. However, I found in the new version of vulkan (1.2.154.1), the following two places seem to need to be changed:

    1. Validation Layers changed : VK_LAYER_LUNARG_standard_validation -> VK_LAYER_KHRONOS_validation. https://vulkan.lunarg.com/doc/view/1.1.114.0/windows/validation_layers.html

    2. There are some image layout warnings when running, like ".....(subresource: aspectMask 0x1 array layer 0, mip level 1) to be in layout VK_IMAGE_LAYOUT_GENERAL--instead, current layout is VK_IMAGE_LAYOUT_UNDEFINED." It seems that all the mips of the "envTextureUnfiltered" image shouled be changed before cs dispatch.

    Thank you~

    opened by wsqjny 0
  • Support building on macOS with MoltenVK

    Support building on macOS with MoltenVK

    It would be great if someone modified projects/cmake/CMakeLists.txt to make this project build on macOS using MoltenVK. Unfortunately I don't have access to any Apple hardware to do it myself.

    enhancement help wanted 
    opened by Nadrin 5
Owner
Michał Siejak
Software developer specializing in computer graphics, game development, and general-purpose GPU computing.
Michał Siejak
Light probe generation and BRDF authoring for physically based shading.

IBLBaker About IBLBaker is provided under the MIT License(MIT) Copyright(c) 2015 Matt Davidson. Please see the LICENSE file for full details. Feel fre

MattD 660 Dec 28, 2022
Specular Lighting in OpenGL (Followed tutorial by Michael Grieco)

Specular lighting in OpenGL Specular Lighting in OpenGL (Followed tutorials by Michael Grieco). 2022-02-13.01-55-21.mp4 Setup Clone $ git clone https:

Aniket Rajnish 4 Feb 18, 2022
OpenGL Template Engine - a C++ OpenGL graphics engine which aimed to be a simple startup template for 3D OpenGL projects.

OpenGL Template Engine is a C++ OpenGL graphics engine which aimed to be a simple startup template for 3D OpenGL projects. This is the template I personally use for my own projects and provides me with the general OpenGL 3D render setup with model import and UI.

Marcus Nesse Madland 2 May 16, 2022
A d3d9 and d3d10 to d3d11 translation layer.

DXUP A D3D9 and D3D10 -> D3D11 Translation Layer Get latest build here or tagged builds here. What's the point? The main reason is for DXVK, a D3D11->

Joshie 245 Dec 18, 2022
Diwali Lighting using ESP32 with OTA update support

OTA_ESP32_8x50_ws2811 Diwali Lighting using ESP32 with OTA update support! This code is meant to drive 8 neopixel chains through separate pins. Being

Anindya Mitra 1 Feb 5, 2022
Desk lighting with an Arduino

desk-lighting Dimmable RGB Desk Lighting with an Arduino I made a small project for my own desktop where I used: Arduino Uno A couple of LEDs A potent

Pratham 1 Apr 9, 2022
Real-Time Rendering with Lighting Grid Hierarchy I3D 2019 Demo

Real-Time Rendering with Lighting Grid Hierarchy I3D 2019 Demo Daqi Lin This demo is for the I3D 2019 paper Real-Time Rendering with Lighting Grid Hie

Lin Daqi 110 Sep 20, 2022
A Visual Studio extension that provides enhanced support for editing High Level Shading Language (HLSL) files

HLSL Tools for Visual Studio This extension is for Visual Studio 2017 / 2019. Go here for the Visual Studio Code extension. HLSL Tools is a Visual Stu

Tim Jones 433 Dec 27, 2022
ShaderConductor is a tool designed for cross-compiling HLSL to other shading languages

ShaderConductor ShaderConductor is a tool designed for cross-compiling HLSL to other shading languages. Features Converts HLSL to readable, usable and

Microsoft 1.5k Dec 29, 2022
Several GX2 test programs to compare it with OpenGL. (With additional GLFW+OpenGL implementation provided)

GX2-Tests Provided are GX2 test programs and samples for comparison with OpenGL and with additional GLFW+OpenGL implementation for test on PC. These s

AboodXD 1 Nov 15, 2021
dump and replace shaders of any OpenGL or Vulkan application

deshade deshade is a library that allows you to dump and replace the shaders of any OpenGL or Vulkan application, which includes: GL2 + extensions, GL

Dale Weiler 25 Aug 10, 2022
C++/openGL/Vulkan 3D engine

Deus In Machina engine C++/GL/Vulkan 3D graphic engine This project should be an abstraction of the engine that I am using on BOC: Birth of Cultures,

Brais 41 May 19, 2022
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2

Filament Filament is a real-time physically based rendering engine for Android, iOS, Linux, macOS, Windows, and WebGL. It is designed to be as small a

Google 15.1k Jan 8, 2023
Physically-based GPU and CPU ray-tracer emerging on a surface

etx-tracer Physically-based GPU and CPU ray-tracer emerging on a surface. Features Vertex Connection and Merging algorithm (CPU and GPU); Full-spectra

Serhii Rieznik 233 Dec 14, 2022
Bollu learns physically based sound sythesis

Kavariance bollu learns digital audio synthesis from the blog at the bottom of the sea. the name is a pun on Kaveri, A wav/river goddess, and Covarian

Siddharth 8 Dec 29, 2021
Code accompanying our SIGGRAPH 2021 Technical Communications paper "Transition Motion Tensor: A Data-Driven Approach for Versatile and Controllable Agents in Physically Simulated Environments"

SIGGRAPH ASIA 2021 Technical Communications Transition Motion Tensor: A Data-Driven Framework for Versatile and Controllable Agents in Physically Simu

null 10 Apr 21, 2022
The OpenEXR project provides the specification and reference implementation of the EXR file format, the professional-grade image storage format of the motion picture industry.

OpenEXR OpenEXR provides the specification and reference implementation of the EXR file format, the professional-grade image storage format of the mot

Academy Software Foundation 1.3k Jan 6, 2023
Vulkan and other GPU API bugs I found.

GPU-my-list-of-bugs what is it - list of bugs I found writing shaders, mostly shader bugs. Maybe this is my code bug or/and shader bugs, but this code

Danil 14 Dec 26, 2022
A collection of tools, libraries, and tests for Vulkan shader compilation.

Shaderc A collection of tools, libraries and tests for shader compilation. At the moment it includes: glslc, a command line compiler for GLSL/HLSL to

Google 1.4k Dec 29, 2022