PBRT Tutorial
Steven Bergner
TA for Cmpt 461/770
Email: sbergner@cs.sfu.ca
PBRT Tutorial - Steven Bergner 2
Advantages of PBRT
• Very general and well tested
framework
• Delivers you from wasting time on the
basics (foundation classes, API)
• Teaches good code design
– Reverse software engineering:
• Understanding abstraction reveals principles
• State of the art rendering!
PBRT Tutorial - Steven Bergner 3
Downsides?
• Work in a large framework that you
haven’t thought up yourself
– Hard to overlook in the beginning
• Saves you time coding, BUT
• Requires time to learn!
– Minimized by good documentation
PBRT Tutorial - Steven Bergner 4
Overview
• Getting started
• Structure of PBRT
• Scene description
• Extending the source code
• Strategies for development
PBRT Tutorial - Steven Bergner 6
Find PBRT
• Find a computer (MTF)
– orange.csil.sfu.ca (cyan, emerald, ...)
– you can only login from within sfu.ca
domain (e.g. go through fraser.sfu.ca)
• Installed in /usr/local/pkg/pbrt/
• Directories bin, images, scenes, src
PBRT Tutorial - Steven Bergner 7
Prerequisites
• be able to logon to the MTF machines
• be familiar with
– basic shell navigation,
– compiling,
– makefiles
PBRT Tutorial - Steven Bergner 8
Setup PBRT
• Environment variable
PBRT_SEARCHPATH
– used to scan plugins from shared objects
(.so or .dll)
– also setup LD_LIBRARY_PATH
>source pbrt.env
PBRT Tutorial - Steven Bergner 9
Render a scene
• render a scene:
– you have to be in the scene path
>cd ~/pbrt/scenes/
>pbrt simple.pbrt
>exrtotiff simple.exr simple.tiff
>display simple.tiff
(using && you can write everything into one
line)
PBRT Tutorial - Steven Bergner 10
Sources of information
• Le book
• Doxygen documentation
• Website www.pbrt.org
• grep on scenes and source code
PBRT Tutorial - Steven Bergner 11
The book
• Highly cross-referenced content
• See Appendices
– C scene description interface
– E index of classes
• Don’t read it page by page
• Read it page by page
PBRT Tutorial - Steven Bergner 12
Doxygen
• Automatic documentation from
source code (+comments)
• PBRT doxygen documentation
– In $PBRTDIR/src/doxygen/html
• Comment your code
– Use //! or /*! Blubb */
• Be concise ;-)
– See www.doxygen.org
PBRT Tutorial - Steven Bergner 13
The website
• FAQ is very useful
• Forum is well frequented
• Links to other courses are useful
• ReadMe file on the CD
PBRT Tutorial - Steven Bergner 14
Structure of PBRT
Object-oriented world
• Core: General principle of raytracing
is abstracted into base classes
• Plug-in: Extend base classes that
implement functionality
PBRT Tutorial - Steven Bergner 16
Base Classes (p. 17)
• Camera
– Film, Sampler, and Filter
• Light
• Material and Texture
• Shape
– Accelerators
• Volumes
• Surface-/volume integrator
– Guided by Ray
PBRT Tutorial - Steven Bergner 17
Rendering Loop (p. 25)
PBRT Tutorial - Steven Bergner 18
Surface Integration (p. 32)
PBRT Tutorial - Steven Bergner 19
Scene description
.pbrt file format
• Read Appendix C, p. 911 (it helps)
• ASCII human readable (and writable)
• Dynamic + common parameter passing
• Dynamic plug-in instantiation
– have to be in the path
PBRT Tutorial - Steven Bergner 21
.pbrt file format
• Parameter lists: “float fov” [30]
• Statements
– Transformations (CTM): LookAt, Rotate,
Translate, … (left-handed CS!)
• Rendering options
– Camera, Sampler, Film
• Attributes – object descriptions
– WorldBegin, WorldEnd
– AttributeBegin/End – State push/pop
PBRT Tutorial - Steven Bergner 22
Standard plug-ins
• Cameras 917
• Samplers 919
• Film 920
• Filters 921
• Shapes 922
• Accelerators 926
• Materials 927
• Textures 930
• Volumes 934
• Lights 936
• SurfaceIntegrator 938
• VolumeIntegrator 940
PBRT Tutorial - Steven Bergner 23
Example scene
• Simple.pbrt
PBRT Tutorial - Steven Bergner 24
Debugging a scene
• display shows alpha mask
• Build incrementally, start simple
• Lights
– Point lights are very weak over distance
• Intelligent copy
PBRT Tutorial - Steven Bergner 25
Generated scenes
• Generate scene files from scripts
• pbrt can be used as stream processor
cat simple.pbrt|pbrt
PBRT Tutorial - Steven Bergner 26
Implementing a plug-in
Core
• pbrt.h
• geometry.h
• Base classes: shape, light, camera, …
PBRT Tutorial - Steven Bergner 28
Implementing a plug-in
• Locate right spot in class hierarchy
– Find appropriate directory
• Update Makefile to build yours too
• Inherit base class
– Setup your parameters
– Implement the full interface
• Read hints in the book (e.g., for class Shape)
PBRT Tutorial - Steven Bergner 29
Example: sphere
• shapes/sphere.cpp
• Look at interface and parameters
• Look at CreateShape
• Look at implementation
PBRT Tutorial - Steven Bergner 30
Differential Geometry
• General shading interface
• Parameterize surface
• Provide Normal (by dpdu dpdv)
PBRT Tutorial - Steven Bergner 31
Strategies
Before you start coding…
• look for existing classes and functions
– understand the structure
– what functions do you need?
• do they already exist? (e.g., vectors, basic geometry)
– if you add functions, where do they belong?
• use Doxygen help to quickly follow cross-
references in the code
• use the book to understand usage
PBRT Tutorial - Steven Bergner 33
Have fun!
Have questions?