Giter VIP home page Giter VIP logo

pbr's Introduction

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:

pbr's People

Contributors

nadrin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pbr's Issues

Cubemap Seams

Great learning resource! Thanks!

I found when applying similar techniques in OpenGL and testing on a sphere with some amount of roughness that I needed to add:

 glTextureParameteri(id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 glTextureParameteri(id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

To the cubemap textures to prevent any visible seams on cubemap edges.

image

Might be useful to anyone that finds it.

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`

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?

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.

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.

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.

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

device lost

vkQueuePresentKHR will get device lost(intel graphic)

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

Build is failing with VS2022

Thanks a lot of this awesome project! It really helped me a lot setting up a basic PBR rendering pipeline.

Sadly I wasn't able to build the executable with VS2022,

I get a list of compile errors like...

Severity	Code	Description	Project	File	Line	Suppression State
Error	C2102	'&' requires l-value	PBR	C:\Users\pixtur\dev\__research\PBR\src\d3d12.cpp	377	

I already installed Vulcan. Does this error indicate that I also need a special version of DX12?

I there by any chance a prebuilt windows executable available?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.