Skip to content

Commit

Permalink
Added Disney BSDF, demonstrations and made final readme changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-shenoy committed Jun 20, 2021
1 parent 04f67cb commit edf90ff
Show file tree
Hide file tree
Showing 91 changed files with 531 additions and 1,243,540 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ CMakeFiles/
CMakeCache.txt
cmake_install.cmake
src/dependacies/
.vscode/settings.json
.vscode/
settings.json
clutter.txt
*.hdr
*.obj
*.mtl
1 change: 0 additions & 1 deletion bin/denoise
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ convert output/normal_maps/$1.png -endian LSB PFM:output/normal_maps/$1.pfm

# Denoise
./src/dependancies/bin/oidnDenoise -ldr output/noisy_renders/$1.pfm -alb output/albedo_maps/$1.pfm -nrm output/normal_maps/$1.pfm -o output/denoised_renders/$1.pfm

#./src/dependancies/bin/oidnDenoise -ldr output/noisy_renders/$1.pfm -alb output/albedo_maps/$1.pfm -o output/denoised_renders/$1.pfm

# Convert denoised output to PNG
Expand Down
Binary file modified bin/path-tracer
Binary file not shown.
Binary file added output/albedo_maps/Buddha.pfm
Binary file not shown.
Binary file added output/albedo_maps/Buddha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/albedo_maps/David.pfm
Binary file not shown.
Binary file added output/albedo_maps/David.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified output/albedo_maps/Other.pfm
Binary file not shown.
Binary file modified output/albedo_maps/Other.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/albedo_maps/Statue.pfm
Binary file not shown.
Binary file added output/albedo_maps/Statue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/albedo_maps/Thinker.pfm
Binary file not shown.
Binary file added output/albedo_maps/Thinker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified output/albedo_maps/VaryingFuzz.pfm
Binary file not shown.
Binary file modified output/albedo_maps/VaryingFuzz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/denoised_renders/Buddha.pfm
Binary file not shown.
Binary file added output/denoised_renders/Buddha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/denoised_renders/David.pfm
Binary file not shown.
Binary file added output/denoised_renders/David.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed output/denoised_renders/Other (copy).png
Binary file not shown.
Binary file modified output/denoised_renders/Other.pfm
Binary file not shown.
Binary file modified output/denoised_renders/Other.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/denoised_renders/Statue.pfm
Binary file not shown.
Binary file added output/denoised_renders/Statue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/denoised_renders/Thinker.pfm
Binary file not shown.
Binary file added output/denoised_renders/Thinker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified output/denoised_renders/VaryingFuzz.pfm
Binary file not shown.
Binary file modified output/denoised_renders/VaryingFuzz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/noisy_renders/Buddha.pfm
Binary file not shown.
Binary file added output/noisy_renders/Buddha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/noisy_renders/David.pfm
Binary file not shown.
Binary file added output/noisy_renders/David.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed output/noisy_renders/Other (3rd copy).png
Binary file not shown.
Binary file removed output/noisy_renders/Other (4th copy).png
Binary file not shown.
Binary file removed output/noisy_renders/Other (another copy).png
Binary file not shown.
Binary file removed output/noisy_renders/Other (copy).png
Binary file not shown.
Binary file modified output/noisy_renders/Other.pfm
Binary file not shown.
Binary file modified output/noisy_renders/Other.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/noisy_renders/Statue.pfm
Binary file not shown.
Binary file added output/noisy_renders/Statue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/noisy_renders/Thinker.pfm
Binary file not shown.
Binary file added output/noisy_renders/Thinker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified output/noisy_renders/VaryingFuzz.pfm
Binary file not shown.
Binary file modified output/noisy_renders/VaryingFuzz.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/normal_maps/Buddha.pfm
Binary file not shown.
Binary file added output/normal_maps/Buddha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added output/normal_maps/Budha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added output/normal_maps/David.pfm
Binary file not shown.
Binary file added output/normal_maps/David.png
Binary file modified output/normal_maps/Other.pfm
Binary file not shown.
Binary file modified output/normal_maps/Other.png
Binary file added output/normal_maps/Statue.pfm
Binary file not shown.
Binary file added output/normal_maps/Statue.png
Binary file added output/normal_maps/Thinker.pfm
Binary file not shown.
Binary file added output/normal_maps/Thinker.png
Binary file modified output/normal_maps/VaryingFuzz.pfm
Binary file not shown.
Binary file modified output/normal_maps/VaryingFuzz.png
65 changes: 32 additions & 33 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
# Physically Based Path Tracer
The below 3D model for the *Head of Michelangelo's David* bust was taken from [this link](https://www.myminifactory.com/object/3d-print-head-of-michelangelo-s-david-52645). Other `.obj` files taken from [The Stanford 3D Scanning repository](http://graphics.stanford.edu/data/3Dscanrep/)
|:-------------------------:|
![Head of David](output/denoised_renders/David.png)


<p align="center">
<img src="output/noisy_renders/Statue.png" />
<img src="output/denoised_renders/VaryingFuzz.png" />
<img src="output/denoised_renders/Marbles.png" />
<img src="output/denoised_renders/Test.png" />
</p>

This repository contains the implementation of a physically based monte carlo path tracer in C++. The project avoids the use of graphics API's and attempts to implement simple physically based rendering effects from scratch.

This is a project I essentially come to in my free time and is something I intend to update sporadically. If you have read the code, or tried to create a scene and have found any flaws or errors in the way things have been done — do feel free to leave an issue! Feel free to leave an issue for any sort of suggestion too, if any.

## Primitives
<p align="center">
<img src="output/noisy_renders/VaryingFuzz.png" />
</p>

Ray Surface intersection routine has been implemented for Spheres, Planes, Boxes, Triangles, and Meshes (that can be represented as a collection of triangles); and basic transformations of these primitives. Other effects and features include

## PBR (*Physically Based Rendering*) Effects
* Materials
* Lambertian (Matte)
* Lambertian with custom textures
* Checkered Texture
* Image Texture
* Metals
* Emissive
* Dielectrics (Refractive surfaces)
* Constant Density Mediums (Smoke, etc.)

## Feature Tracker
This is a project I essentially come to in my free time and is something I intend to update sporadically. If you have read the code, or tried to create a scene and have found any flaws or errors in the way things have been done — do feel free to leave an issue!

## Feature Tracker / To Do
- [x] Motion Blur
- [x] Antialiasing
- [x] Depth of Field
Expand All @@ -39,15 +25,17 @@ Ray Surface intersection routine has been implemented for Spheres, Planes, Boxes
- [x] HDR Environment maps
- [ ] ~~Find a way to serialize BVH tree object (for re-use for large meshes)~~
- [x] Optimize and Multithread mesh BVH tree building
- [ ] Optimize ray-triangle intersection routine
- [ ] Implement additional BSDF's (Disney BSDF) and materials
- [ ] Incorporate CUDA, get full rendering to happen on GPU
- [ ] ~~Optimize ray-triangle intersection routine~~
- [x] Implement additional BSDF's (Disney BSDF) and materials (sort of?)
- [ ] ~~Incorporate CUDA, get full rendering to happen on GPU~~

On halt for now, spending too much time on this

## Denoiser

Noisy Render (Output) | Denoised Image
:-------------------------:|:-------------------------:
![](output/noisy_renders/CornellBox.png) | ![](output/denoised_renders/CornellBox.png)
Noisy Render (Output) | Normal map | Albedo map | Denoised Image
:-------------------------:|:-------------------------:|:-------------------------:|:-------------------------:
![](output/noisy_renders/David.png) | ![](output/normal_maps/David.png) |![](output/albedo_maps/David.png) | ![](output/denoised_renders/David.png)

Since the application runs on the CPU, samples per pixel needs to be limited to obtain reasonable render times (even with multi-threading).

Expand All @@ -57,25 +45,36 @@ The pre-compiled zip file (unzipped, includes a `bin` and a `lib` folder) needs

## Usage
<p align="center">
<img src="output/noisy_renders/GlowRoom.png" />
<img src="output/denoised_renders/GlowRoom.png" />
</p>

A sample binary has been uploaded with the repo (compiled on x86, as a 64 bit application), but its unlikely that it would generally work even on a system with the same configuration (try anyway, it just might). To compile in a device specific manner, you can create a Makefile using cmake (`CMakeLists.txt` given) or use the given `Makefile`.

After creating the Makefile using cmake and making/compiling the project, the compiled binary (`path-tracer`) can be found in `bin/` and is to be used with a single command line argument - the name of the scene in `src/scenes/`. (The folder `src/scenes/` contains implementation of all the scenes in this readme file and few others. The `.scene.h` files are just C++, and the files were created mostly just for organisational purposes)
After creating the Makefile using cmake and making/compiling the project (`cmake .` followed by `make`), the compiled binary (`path-tracer`) can be found in `bin/` and is to be used with a single command line argument - the name of the scene in `src/scenes/`. (The folder `src/scenes/` contains implementation of all the scenes in this readme file and few others. The `.scene.h` files are just C++, and the files were created mostly just for organisational purposes)

> ./bin/path-tracer CornellBox
> ./bin/path-tracer GlowRoom

Running this should show a progress bar, after which 3 images will be stored in `output` - the noisy render (Primary output), an albedo image, and a normal map (To aid the denoising process). After these three images have been generated the `denoise` binary can be run in the same way that the main one was

> ./bin/denoise CornellBox
> ./bin/denoise GlowRoom

The resolution of the output render and the samples per pixel have been hard-coded in `main.cpp`

## Dependancies and Other Stuff
## Dependancies

A simple `OpenMP` call was used to multithread the loop which shoots multiple samples per pixel. The `OpenMP` dependancy is included by the `CmakeLists.txt`, but can easily be removed and worked without.

The project uses libraries for reading and writing images ([stb_image](https://github.com/nothings/stb) and [FreeImage](https://freeimage.sourceforge.io/)) and for convenience. [GLM](https://github.com/g-truc/glm) was used for mathematical data types (vectors, matrices, etc.) and operations, but can easily be replaced by a few structs. [ImageMagick](https://github.com/ImageMagick/ImageMagick) is also required for commands in the `denoise` shell script.

More about depandancy set up in the sub-folder `src/dependancies`

## Resources

This project takes a lot from Ravi Ramamoorthi's course - [An intro to graphics](https://www.edx.org/course/computer-graphics-2); and the repository and code largely takes its structure and features from [Peter Shirley's book series](https://raytracing.github.io/).

The Disney BSDF, though poorly incorporated and incomplete, takes a lot from [this repository](https://github.com/schuttejoe/Selas) and the corresponding [blog articles](https://schuttejoe.github.io/post/disneybsdf/). Inspiration was also taken, but to a lesser extent from [tinsel from mmacklin](https://github.com/mmacklin/tinsel) and [GLSLPathTracer from knightcrawler25](https://github.com/knightcrawler25/GLSL-PathTracer).

And just like everyone ever who has written a path tracer, constant references were made to [Physically Based Rendering by *Matt Pharr, Wenzel Jakob, and Greg Humphreys*](https://www.pbr-book.org/) and its [repository](https://github.com/mmp/pbrt-v3).

## Note
This was more or less a pet project to be able to learn the fundamental basics of path tracing, and with every feature I added, I got carried away. I have licensed this project under the MIT license, and do what you may with the code but I would highly recommend not to re-use the `bsdf` namespace and the `core::Disney` class, since some of the lobe calculations are off.
Empty file added res/data/.gitkeep
Empty file.
12 changes: 12 additions & 0 deletions res/data/david.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Blender MTL File: 'None'
# Material Count: 1

newmtl Default_OBJ
Ns 225.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
10 changes: 10 additions & 0 deletions res/data/thinker.mtl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Blender MTL File: 'None'
# Material Count: 1

newmtl None
Ns 500
Ka 0.8 0.8 0.8
Kd 0.8 0.8 0.8
Ks 0.8 0.8 0.8
d 1
illum 2
Loading

0 comments on commit edf90ff

Please sign in to comment.