Convert Figma logo to code with AI

mmp logopbrt-v3

Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.

4,879
1,185
4,879
57

Top Related Projects

Mitsuba 2: A Retargetable Forward and Inverse Renderer

1,149

LuxCore source repository

A modern open source rendering engine for animation and visual effects

5,987

Universal Scene Description

Quick Overview

PBRT-v3 is an open-source implementation of the physically based rendering techniques described in the book "Physically Based Rendering: From Theory to Implementation (3rd edition)" by Matt Pharr, Wenzel Jakob, and Greg Humphreys. It serves as both a reference implementation and a practical rendering system for research and experimentation in computer graphics.

Pros

  • Comprehensive implementation of modern physically based rendering techniques
  • Well-documented codebase that closely follows the book, making it an excellent learning resource
  • Extensible architecture allowing for easy addition of new materials, light sources, and integrators
  • Supports a wide range of advanced rendering features like subsurface scattering, volumetric rendering, and spectral rendering

Cons

  • Performance may not be as optimized as some commercial rendering engines
  • Steep learning curve for beginners due to the complexity of physically based rendering concepts
  • Limited built-in support for interactive rendering or real-time preview
  • May require significant computational resources for complex scenes or high-quality renders

Code Examples

  1. Creating a simple scene with a sphere and a point light:
std::shared_ptr<Shape> sphere = std::make_shared<Sphere>(Transform(), Transform(), true, 1.0f);
std::shared_ptr<Light> light = std::make_shared<PointLight>(Transform(), Spectrum(1.0f));
scene.AddShape(sphere);
scene.AddLight(light);
  1. Defining a matte material:
std::shared_ptr<Material> matte = std::make_shared<MatteMaterial>(
    std::make_shared<ConstantTexture<Spectrum>>(Spectrum(0.5f)),
    std::make_shared<ConstantTexture<Float>>(0.0f),
    nullptr);
  1. Setting up a perspective camera:
Point3f eye(0, 0, 5);
Point3f lookAt(0, 0, 0);
Vector3f up(0, 1, 0);
Float fov = 45.0f;
std::shared_ptr<Camera> camera = std::make_shared<PerspectiveCamera>(
    AnimatedTransform(LookAt(eye, lookAt, up)), fov, film);

Getting Started

  1. Clone the repository:

    git clone https://github.com/mmp/pbrt-v3.git
    
  2. Build the project using CMake:

    cd pbrt-v3
    mkdir build && cd build
    cmake ..
    make
    
  3. Run the renderer with a sample scene:

    ./pbrt ../scenes/simple.pbrt
    

This will generate a rendered image of the specified scene. Explore the scenes directory for more example scenes to render.

Competitor Comparisons

Mitsuba 2: A Retargetable Forward and Inverse Renderer

Pros of Mitsuba2

  • More flexible and extensible architecture, allowing easier integration of new rendering techniques
  • Better support for differentiable rendering and inverse problems in computer graphics
  • More comprehensive documentation and tutorials for users and developers

Cons of Mitsuba2

  • Steeper learning curve due to its more complex architecture
  • Potentially slower rendering performance for some scenes compared to PBRT-v3
  • Less widespread adoption in the industry compared to PBRT-v3

Code Comparison

Mitsuba2 (Python interface):

import mitsuba
mitsuba.set_variant('scalar_rgb')
from mitsuba.core import load_file
scene = load_file('scene.xml')
image = scene.render()

PBRT-v3 (C++):

#include "pbrt.h"
#include "api.h"
pbrtInit(options);
pbrtParseFile("scene.pbrt");
pbrtRender();
pbrtCleanup();

Both renderers offer powerful capabilities, but Mitsuba2 provides a more flexible Python interface, while PBRT-v3 uses a C++ API. Mitsuba2's architecture allows for easier experimentation with new rendering techniques, while PBRT-v3 is known for its stability and widespread use in education and research.

1,149

LuxCore source repository

Pros of LuxCore

  • More advanced rendering features, including bidirectional path tracing and metropolis light transport
  • Active development with frequent updates and new features
  • Extensive material system with support for complex shaders and textures

Cons of LuxCore

  • Steeper learning curve due to more complex architecture
  • Potentially slower render times for simple scenes compared to PBRT-v3
  • Less educational focus, as it's primarily designed for production use

Code Comparison

LuxCore (C++):

Scene *scene = Scene::Create();
camera->Update(filmWidth, filmHeight, 0.f);
scene->SetCamera(camera);
scene->Preprocess();

PBRT-v3 (C++):

std::unique_ptr<Integrator> integrator(CreateIntegrator(integratorName, &params));
std::unique_ptr<Scene> scene(pbrtScene.makeScene());
integrator->Render(*scene);

Both projects use C++ and have similar high-level structures for scene creation and rendering. However, LuxCore's API tends to be more object-oriented, while PBRT-v3 often uses free functions and a more procedural style.

LuxCore offers more advanced features and is actively developed, making it suitable for production rendering. PBRT-v3, on the other hand, is designed with education in mind and may be easier to understand for beginners studying physically-based rendering techniques.

A modern open source rendering engine for animation and visual effects

Pros of appleseed

  • More active development with frequent updates and releases
  • Broader feature set including interactive rendering and a plugin system
  • Extensive documentation and user guides

Cons of appleseed

  • Steeper learning curve due to more complex architecture
  • Potentially slower render times for some scenes compared to PBRT-v3
  • Less academic focus, which may impact its use in research settings

Code Comparison

appleseed:

class APPLESEED_DLLSYMBOL Scene
  : public Entity
  , public SourceInputs
{
  public:
    // Scene methods...
};

PBRT-v3:

class Scene {
public:
    std::vector<std::shared_ptr<Primitive>> primitives;
    std::shared_ptr<Primitive> aggregate;
    std::vector<std::shared_ptr<Light>> lights;
    // Scene methods...
};

Both projects use C++ and have similar overall structures, but appleseed's codebase tends to be more complex with additional abstractions and features. PBRT-v3's code is often more straightforward and closely follows the concepts presented in the PBRT book.

5,987

Universal Scene Description

Pros of OpenUSD

  • Comprehensive framework for 3D scene description and interchange
  • Extensive industry adoption and support
  • Rich set of tools and APIs for asset management and collaboration

Cons of OpenUSD

  • Steeper learning curve due to complex architecture
  • Larger codebase and dependencies
  • Primarily focused on animation and VFX pipelines

Code Comparison

OpenUSD example (C++):

#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdGeom/sphere.h"

auto stage = pxr::UsdStage::CreateNew("sphere.usda");
auto spherePrim = pxr::UsdGeomSphere::Define(stage, "/mySphere");
spherePrim.CreateRadiusAttr().Set(2.0);

pbrt-v3 example (C++):

#include "geometry.h"
#include "shape.h"

Sphere *sphere = new Sphere(Transform(), Transform(), false, 2.0);
std::shared_ptr<Shape> sphereShape(sphere);

The OpenUSD code demonstrates creating a stage and defining a sphere primitive with attributes, while the pbrt-v3 code shows creating a sphere object directly. OpenUSD provides a more abstract and extensible approach, while pbrt-v3 offers a more straightforward implementation for rendering purposes.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

pbrt, Version 3

Build Status Build status

This repository holds the source code to the version of pbrt that is described in the third edition of Physically Based Rendering: From Theory to Implementation, by Matt Pharr, Wenzel Jakob, and Greg Humphreys. As before, the code is available under the BSD license.

The pbrt website has general information about both the Physically Based Rendering book as well as many other resources for pbrt. As of October 2018, the full text of the book is now available online, for free.

Example scenes

Over 8GB of example scenes are available for download. (Many are new and weren't available with previous versions of pbrt.) See the pbrt-v3 scenes page on the pbrt website for information about how to download them.

After downloading them, see the README.md.html file in the scene distribution for more information about the scenes and preview images.

Additional resources

  • There is a pbrt Google Groups mailing list that can be a helpful resource.
  • Please see the User's Guide for more information about how to check out and build the system as well as various additional information about working with pbrt.
  • Should you find a bug in pbrt, please report it in the bug tracker.
  • Please report any errors you find in the Physically Based Rendering book to authors@pbrt.org.

Note: we tend to let bug reports and book errata emails pile up for a few months for processing them in batches. Don't think we don't appreciate them. :-)

Building pbrt

To check out pbrt together with all dependencies, be sure to use the --recursive flag when cloning the repository, i.e.

$ git clone --recursive https://github.com/mmp/pbrt-v3/

If you accidentally already cloned pbrt without this flag (or to update an pbrt source tree after a new submodule has been added, run the following command to also fetch the dependencies:

$ git submodule update --init --recursive

pbrt uses cmake for its build system. On Linux and OS X, cmake is available via most package management systems. To get cmake for Windows, or to build it from source, see the cmake downloads page. Once you have cmake, the next step depends on your operating system.

Makefile builds (Linux, other Unixes, and Mac)

Create a new directory for the build, change to that directory, and run cmake [path to pbrt-v3]. A Makefile will be created in the current directory. Next, run make to build pbrt, the obj2pbrt and imgtool utilities, and an executable that runs pbrt's unit tests. Depending on the number of cores in your system, you will probably want to supply make with the -j parameter to specify the number of compilation jobs to run in parallel (e.g. make -j8).

By default, the makefiles that are created that will compile an optimized release build of pbrt. These builds give the highest performance when rendering, but many runtime checks are disabled in these builds and optimized builds are generally difficult to trace in a debugger.

To build a debug version of pbrt, set the CMAKE_BUILD_TYPE flag to Debug when you run cmake to create build files to make a debug build. To do so, provide cmake with the argument -DCMAKE_BUILD_TYPE=Debug and build pbrt using the resulting makefiles. (You may want to keep two build directories, one for release builds and one for debug builds, so that you don't need to switch back and forth.)

Debug versions of the system run much more slowly than release builds. Therefore, in order to avoid surprisingly slow renders when debugging support isn't desired, debug versions of pbrt print a banner message indicating that they were built for debugging at startup time.

Xcode

To make an Xcode project on OS X, run cmake -G Xcode [path to pbrt-v3]. A PBRT-V3.xcodeproj project file that can be opened in Xcode. Note that the default build settings have an optimization level of "None"; you'll almost certainly want to choose "Faster" or "Fastest".

MSVC on Windows

On Windows, first point the cmake GUI at the directory with pbrt's source code. Create a separate directory to hold the result of the build (potentially just a directory named "build" inside the pbrt-v3 directory) and set that for "Where to build the binaries" in the GUI.

Next, click "Configure". Note that you will want to choose the "Win64" generator for your MSVC installation unless you have a clear reason to need a 32-bit build of pbrt. Once cmake has finished the configuration step, click "Generate"; when that's done, there will be a "PBRT-V3.sln" file in the build directory you specified. Open that up in MSVC and you're ready to go.

Build Configurations

There are two configuration settings that must be set when configuring the build. The first controls whether pbrt uses 32-bit or 64-bit values for floating-point computation, and the second controls whether tristimulus RGB values or sampled spectral values are used for rendering. (Both of these aren't amenable to being chosen at runtime, but must be determined at compile time for efficiency). The cmake configuration variables PBRT_FLOAT_AS_DOUBLE and PBRT_SAMPLED_SPECTRUM configure them, respectively.

If you're using a GUI version of cmake, those settings should be available in the list of configuration variables; set them as desired before choosing 'Generate'.

With command-line cmake, their values can be specified when you cmake via -DPBRT_FLOAT_AS_DOUBLE=1, for example.