Rendering scenes with pbrt3

At the end of Computer Graphics class, we had an assignment to design our own ray tracing renderer. It was an extremely difficult task, and our group failed in the end despite our efforts. As so, I would like to see how a working ray tracing engine performs in rendering a scene.

Here I would like to share the procedure I used to run this ray-tracing code, as well as the huge excitement I felt at the time. If you are not familiar with build and make, then you can also get a grasp of that in this blog.

So, what is ray tracing? Imagine your eyes are a camera. When you look at the screen, you are looking at about 2560 x 1600 pixels (could vary depending on your computer) altogether. Therefore, for each pixel, the computer needs to put a color on there. So how does it determine that? In other words, how does your computer project a 3D scene to a 2D platform? In short, the “camera” shoots out a ray towards each pixel. As each ray hits an object, it reads the color value of this hitting point on the object. This color value is determined by the material, reflection algorithm, and light sources. Eventually, the ray gives the RGB value to that pixel it passed on the screen.

In computer graphics, the best book for rendering is Physically Based Rendering. Up to this point, it has a third version already, and the fourth one is coming next year. It seems that CG researchers have been discovering better and faster ways to render.

The beautiful bathroom picture below is my goal today – actually, it was the goal 24 days ago, and you will see what I mean by that later. Yes, it is a completely modeled scene. It is not a picture taken by a camera.

Salle_de_bains, created by nacimus, downloaded from Blend Swap

The first step is getting the code from this book’s official GitHub. https://github.com/mmp/pbrt-v3

All the code in this book is published there. The README file is also detailed enough to follow, but I’d still like to offer here a concise procedure with screenshots. I ran this on a MacBook, but keep in mind that you can also do it on Windows command prompt in the same way with a slightly different syntax. After all, there is only one cmake in the world.

Firstly, I created an empty folder called “build” in the folder I just cloned. Then, I cd into that build folder, and called “$ cmake ..” in terminal. This is how cmake works – you call “$ cmake [the folder with CMakeLists.txt]”, and it will give you a Makefile in the current folder.

 

 

 

After it finished building, there will be a Makefile in the build folder. I cd into the build folder and called “ $ make”. There you will see some beautiful purple and green messages. This one could take a while.

 

 

 

 

Cool. Now my build folder looks like this:

There is an exec file called “pbrt”, and that is exactly what we want after all these messes! Think it as a software you normally use, except that you don’t double click it – you use it by calling it in command prompt.

Now that we have a stove, we still need some raw food to cook. In this case, the latter is a 3D scene. If you go to https://pbrt.org/scenes-v3.html, you will see a lot of good-looking scenes created by artists in the public. On the top of the page there’s a GitHub source to clone from. Here, we use “Salle de Bain” created by nacimus for instance.

Finally, we get to render it! What you should do in command line is pointing out that I want to use the pbrt engine to render this bathroom scene. Still in the build directory, enter a line like this:

$  ./pbrt  [the .pbrt file]

And then it starts running! Note that it shows how many cores it detects. We will use that later. Then, look at the progress bar. It is still empty. The number on the left in the parenthesis is the time already taken, and the number on the right (still a ‘?’ at this point) is the estimated remaining time. In the beginning, the computer cannot tell how long it will take yet. But feel free to take a guess now 🙂

So, what is your guess? Is it 6 hours or even longer than a day? The answer is 23 days on my MacBook Air with 4 cores!

~ 2 million seconds ≈ 551 h ≈ 23 days

That’s why the smartest CG researchers in the world are still studying ray tracing after all these years. The resulting pictures certainly look nice – but it is too slow.

However, it does get better if you have stronger hardware. This is the result I got running on my msi gaming laptop with 8 cores:

~ 1 million seconds ≈ 278 h ≈ 11.6 days

Asya said that the speed is mostly related to the number of cores. That makes sense here – the laptop with 8 cores has twice the speed than the one with 4 cores. They also have different GPU and RAM, but I guess they are not that important. My opinion is that the program ran in multiple threads, each requiring a core; however, each thread is not that much of a work, so the other factors did not influence the speed that much.

However, as I ran this on Mudd’s research computer, I was amazed to find that though the system only detected 4 cores, it finished the work in a mere 3 days! The secret of computing has still a lot to explore.

By Jack Chen