Skip to content

benoit-leveau/pyPbrt

Repository files navigation

Overview

pyPbrt is a Python port/rewrite of pbrt, the physically based renderer by Matt Pharr and Greg Humphreys, which is the companion software for their book Physically Based Rendering, Second Edition: From Theory To Implementation. (amazon page for the book)

The pbrt website (for the book and the software) is located at http://pbrt.org . The original (C++) source code can be downloaded at http://pbrt.org/downloads.php

Rationale

The idea behind this project is mainly for me to go along the book and write code as I progress through it. Having a raytracer or path tracer entirely written in Python doesn't make much sense as far as performance is concerned, but I thought it would be a good way to make sure I understand all the algorithms as I have to write them. Writing it in C++ would make copy-paste from the book (or from the source code) too tempting, and inevitably I would come up with the same exact code as pbrt. There is one benefit to having it written in Python though. It becomes very easy to test new algorithms and concepts interactively in the interpreter, reloading code when making changes and testing them directly.

Parts of pbrt that are closely tied to the C++ implementation, like the MemoryArena class, don't make sense in Python and will therefore be skipped.

A more clever approach, if this project wasn't meant for learning purposes, would be to have a Python bindings to a C++ implementation of pbrt, something that can even be automated with a framework like py++ (http://sourceforge.net/projects/pygccxml/)

Once the project is finished, I'll also try to see if I can get decent running times by switching the low-level parts (geometry and transformation classes) to C++, or by using PyCuda.

Installation

Just cd to the project folder and run pyPbrt. Use the flag --help for a description of all available parameters.

Unit Tests

Unit tests are implemented using the unittest module and are located in the tests folder. For convenience, I use nose to run the tests. More information about nose can be found there: https://pypi.python.org/pypi/nose/1.3.0 Once nose is installed, running the tests is just a matter of cd'ing to the pyPbrt folder and running:

[~/Documents/Prog/pyPbrt] - nosetests
----------------------------------------------------------------------
Ran X test in 0.018s

OK

Coding Style

Whenever possible, I tried to adhere to PEP 8 -- Style Guide for Python Code for coding style and to PEP 257 -- Docstring Conventions for docstrings. Code is checked with the command line tools pep8 and pylint.

Links:

This significantly differs from the conventions adopted by the pbrt C++ source code. The differences are highlighted in the table below:

pbrtpyPbrt
Global Variable Nameslowercase_with_underscores
Function NamesCapWords
eg: AbsDot(v1, v2)
lowercase_with_underscores
eg: abs_dot(v1, v2)
Class NamesCapWords
eg: Vector, Sphere
CapWords
eg: Vector, Sphere
Class MethodsCapWords
eg: vector.LengthSquared()
lowercase_with_underscores
eg: vector.length_squared()

About

[WIP] Python port/rewrite of pbrt, the physically based renderer by Matt Pharr and Greg Humphreys

Resources

Stars

Watchers

Forks

Packages

No packages published