/cpbrt

My implementation of the renderer of Physically Based Rendering: From Theory to Implementation by Pharr, Jakob, and Humphreys

Primary LanguageC++

CPBRT is my physically-based, offline toy renderer. It is the result of studying Physically Based Rendering: From Theory to Implementation, by Pharr, Jakob, and Humphreys (online edition), writing down the code fragments provided by the authors, and filling in the gaps.

A more detailed description is found in my blog.

Features

Light transport algorithms: Kajiya path tracing (unidirectional, unbiased Monte Carlo estimation of the light transport equation). Direct-lighting (no indirect illumination) and path (full global illumination) integrators. Reflectance models and BRDFs: Lambert diffuse model, Oren-Nayar diffuse model for rough surfaces, Fresnel perfectly specular model, and Fresnel glossy specular model (with Torrance-Sparrow microfacets with Beckmann-Spizzichino or Trowbridge-Reitz distributions).
Textures: Floating-point and spectrum constant-value textures. Procedural checkerboard texture, antialiased with a box filter. Mipmapping. Materials: Matte with either a perfect diffuse Lambertian BRDF or an Oren-Nayar BRDF for various degrees of roughness; plastic with diffuse and glossy specular BRDFs; mirror with a perfectly-specular BRDF; gold; glass with perfectly-specular BRDF and BTDF; diffuse substrate and glossy coat with an Ashikhmin-Shirley BRDF.
Shapes: Triangle meshes, single triangles, and spherical implicit surfaces. Accelerators: BVH with 5 different primitive (or object) subdivision methods: linear BVH, hierarchical linear BVH, midpoint partitioning, equal counts partitioning, and surface area heuristic (SAH).
Samplers: Uniform or jittered stratified pixel sampling for 1D samples and Latin Hypercube sampling for 2D samples. Samplers rely on a Permuted Congruential Generator (PCG) pseudo-random number generator. Filters: Box, triangle, Gaussian, Mitchell-Netravali, and Lanczos windowed-sinc filters.
Lights: Point, distant, and diffuse area light sources. An area light can take the form of any of the supported *shapes*. Infinite area light source backed by environment map. Cameras: Thin lens perspective and orthographic projective cameras with configurable aperture and focal distance (for depth of field) and film aspect ratio. The perspective camera also has a configurable field of view.
Participating media: Homogeneous-density and grid-based variable-density media.

Select images

Diffuse substrate and glossy coat with an Ashikhmin-Shirley BRDF. Volumetric path integrator.

Diffuse substrate and glossy coat with an Ashikhmin-Shirley BRDF.

10mm fish-eye lens.

Subsurface scattering, skin material.

Glass material, lit with an infinite area light backed by a latitude-longitude radiance map.

Glass material, volumetric path tracing; a bug prevents the environment map from being sampled.

Metal material, lit with an infinite area light backed by a latitude-longitude radiance map.

Gold material, Torrance-Sparrow microfacets with Trowbridge-Reitz distribution.

Ganesha mesh by Wenzel Jakob; notice the absence of shadows (wrong).

Participating media. Not working yet.

Cornell box, direct lighting integrator, stratified sampling, 30 samples per pixel.

Cornell box, path integrator, stratified sampling, 10 samples per pixel.

Plastic material with Torrance-Sparrow microfacet BRDF to simulate glossy hard plastic.

Spherical diffuse area light, matte material with Lambertian reflection.

Spherical diffuse area light, plastic material w/o specular reflection.

Matte material with Oren-Nayar diffuse reflection.

Matte material with perfect Lambertian diffuse reflection.

Cover of the PBRT book by Yining Karl Li, perspective camera, 2 point lights, mirror material, specular BRDF.

Dragon triangle mesh by Christian Schüller, perspective camera, 2 point lights, matte material.

Cover of the PBRT book by Yining Karl Li, perspective camera, 2 point lights, matte material.

One triangle of a triangle mesh, matte material.

First render, implicitly defined sphere.

The sections I've covered are marked next. Each covered section is accompanied by my personal notes.

1 Introduction (notes/1 Introduction)

  • 1.1 Literate Programming
  • 1.2 Photorealistic Rendering and the Ray-Tracing Algorithm
  • 1.3 pbrt: System Overview
  • 1.4 Parallelization of pbrt
  • 1.5 How to Proceed through This Book
  • 1.6 Using and Understanding the Code
  • 1.7 A Brief History of Physically Based Rendering

2 Geometry and Transformations (notes/2 Geometry and Transformations)

  • 2.1 Coordinate Systems
  • 2.2 Vectors
  • 2.3 Points
  • 2.4 Normals
  • 2.5 Rays
  • 2.6 Bounding Boxes
  • 2.7 Transformations
  • 2.8 Applying Transformations
  • 2.9 Animating Transformations
  • 2.10 Interactions

3 Shapes (notes/3 Shapes)

  • 3.1 Basic Shape Interface
  • 3.2 Spheres
  • 3.3 Cylinders
  • 3.4 Disks
  • 3.5 Other Quadrics
  • 3.6 Triangle Meshes
  • 3.7 Curves
  • 3.8 Subdivision Surfaces
  • 3.9 Managing Rounding Error

4 Primitives and Intersection Acceleration (notes/4 Primitives and Intersection Acceleration)

  • 4.1 Primitive Interface and Geometric Primitives
  • 4.2 Aggregates
  • 4.3 Bounding Volume Hierarchies
  • 4.4 Kd-Tree Accelerator

5 Color and Radiometry (notes/5 Color and Radiometry)

  • 5.1 Spectral Representation
  • 5.2 The SampledSpectrum Class
  • 5.3 RGBSpectrum Implementation
  • 5.4 Radiometry
  • 5.5 Working with Radiometric Integrals
  • 5.6 Surface Reflection

6 Camera Models (notes/6 Camera Models)

  • 6.1 Camera Model
  • 6.2 Projective Camera Models
  • 6.3 Environment Camera
  • 6.4 Realistic Cameras

7 Sampling and Reconstruction (notes/7 Sampling and Reconstruction)

  • 7.1 Sampling Theory
  • 7.2 Sampling Interface
  • 7.3 Stratified Sampling
  • 7.4 The Halton Sampler
  • 7.5 (0, 2)-Sequence Sampler
  • 7.6 Maximized Minimal Distance Sampler
  • 7.7 Sobol' Sampler
  • 7.8 Image Reconstruction
  • 7.9 Film and the Imaging Pipeline

8 Reflection Models (notes/8 Reflection Models)

  • 8.1 Basic Interface
  • 8.2 Specular Reflection and Transmission
  • 8.3 Lambertian Reflection
  • 8.4 Microfacet Models
  • 8.5 Fresnel Incidence Effects
  • 8.6 Fourier Basis BSDFs

9 Materials (notes/9 Materials)

  • 9.1 BSDFs
  • 9.2 Material Interface and Implementations
  • 9.3 Bump Mapping

10 Texture (notes/10 Texture)

  • 10.1 Sampling and Antialiasing
  • 10.2 Texture Coordinate Generation
  • 10.3 Texture Interface and Basic Textures
  • 10.4 Image Texture
  • 10.5 Solid and Procedural Texturing
  • 10.6 Noise

11 Volume Scattering

  • 11.1 Volume Scattering Processes
  • 11.2 Phase Functions
  • 11.3 Media
  • 11.4 The BSSRDF

12 Light Sources (notes/12 Light Sources)

  • 12.1 Light Emission
  • 12.2 Light Interface
  • 12.3 Point Lights
  • 12.4 Distant Lights
  • 12.5 Area Lights
  • 12.6 Infinite Area Lights

13 Monte Carlo Integration (notes/13 Monte Carlo Integration)

  • 13.1 Background and Probability Review
  • 13.2 The Monte Carlo Estimator
  • 13.3 Sampling Random Variables
  • 13.4 Metropolis Sampling
  • 13.5 Transforming between Distributions
  • 13.6 2D Sampling with Multidimensional Transformations
  • 13.7 Russian Roulette and Splitting
  • 13.8 Careful Sample Placement
  • 13.9 Bias
  • 13.10 Importance Sampling

14 Light Transport I: Surface Reflection (notes/14 Light Transport I Surface Reflection)

  • 14.1 Sampling Reflection Functions
  • 14.2 Sampling Light Sources
  • 14.3 Direct Lighting
  • 14.4 The Light Transport Equation
  • 14.5 Path Tracing

15 Light Transport II: Volume Rendering

  • 15.1 The Equation of Transfer
  • 15.2 Sampling Volume Scattering
  • 15.3 Volumetric Light Transport
  • 15.4 Sampling Subsurface Reflection Functions
  • 15.5 Subsurface Scattering Using the Diffusion Equation

16 Light Transport III: Bidirectional Methods

  • 16.1 The Path-Space Measurement Equation
  • 16.2 Stochastic Progressive Photon Mapping
  • 16.3 Bidirectional Path Tracing
  • 16.4 Metropolis Light Transport

17 Retrospective and The Future

  • 17.1 Design Retrospective
  • 17.2 Alternative Hardware Architectures

A Utilities (notes/Appendix A)

  • A.1 Main Include File
  • A.2 Image File Input and Output
  • A.3 Communicating with the User
  • A.4 Memory Management
  • A.5 Mathematical Routines
  • A.6 Parallelism
  • A.7 Statistics

B Scene Description Interface (notes/Appendix B)

  • B.1 Parameter Sets
  • B.2 Initialization and Rendering Options
  • B.3 Scene Definition
  • B.4 Adding New Object Implementations