CS 348B - Computer Graphics: Image Synthesis Techniques

Homework  - Environment Map Importance Sampling

© Matt Pharr and Greg Humphreys

Assigned Tuesday, May 3.   Due Tuesday, May 10.  


Environment lighting can greatly contribute to the realism and richness of your renderings.  However, since it involves integrating over the entire hemisphere in the worst case, it is prone to be noisy, requiring many samples for reasonable quality.  In this project you will add support to pbrt for handling distant environmental lighting more efficiently by using importance sampling.

This assignment is designed to be significantly shorter than Homework 2 and 3. 

Step 1

Read chapters 13 (especially 13.5), 14 (especially 14.3.4) and 15 (especially 15.6) in the pbrt book.

Step 2

  1. Download this zip archive (Updated 5/7) and unzip it into your working directory. 
  2. Render an image of the killeroo scene. This uses pbrt's built-in implementation of an infinite environment light (pbrtsrc/lights/infinite.cpp). It should look something like this:


Step 3: Enhance environment map light implementation with importance sampling

  1. Copy pbrt's standard environment map light plugin (src/lights/infinite.cpp) to your working directory, and call it importance_infinite.cpp.
  2. Modify killeroo_imp.pbrt to render the scene using your importance-sampled light.
  3. Design an unbiased importance-based sampling scheme for the the light that uses the distant radiance defined by the environment as the probability density function (pdf).
  4. Modify your importance_infinity.cpp to use this sampling scheme.
  5. Verify that your implementation produces the same image as the default when a large number of samples are taken (i.e. that your Monte Carlo estimator is indeed unbiased) and that your scheme produces less noise with an equal number of samples (i.e. that your importance metric produces less variance).
  6. Try out some of the other environments provided in the textures directory.  The grace environment is particularly colorful.

* As a general rule, use only the course notes and the pbrt book as references for this assignment. Do not copy importance sampling code from the internet.


  1. The environment map is in color, but your pdf is scalar-valued.  Convert the color radiance to a scalar value (the so-called luminance) by using the Spectrum::y() function.  Use this scalar value as the value of your pdf.
  2. Sampling from 2D distributions is more complicated than sampling from 1D distributions.  For the 2D case you may need to review marginal distributions.  You may like to take a look at the description of how to use the marginals in Section 2.3.1 (page 24) of the SIGGRAPH course notes from 2001. This was on the assigned reading from the Monte Carlo lectures.
  3. Given continuous theta and phi angles, the radiance value in that direction is defined by bilinear interpolation from the nearest environment image grid samples (see infinity.cpp).  It can be challenging to define a pdf based on that piecewise linear reconstruction.  Instead, we recommend that while designing your pdf, you assume a piecewise constant (i.e. nearest neighbor) reconstruction of the image map.  This will make designing a sampling scheme easier, it will be close to using the bilinear reconstruction, and it will still be unbiased (see the next hint) and produce accurate final pictures.  Be sure to use bilinear interpolation in returning the value of the radiance however; this hint applies only to the design of the pdf. 
  4. Given the last hint, the only point to be careful about is how you handle black pixels in the scene when designing your sampling scheme. You may need to introduce some special handling of such pixels to ensure that your estimator remains unbiased.

Step 4: Web page submission

  1. Document your work in a web page again.    
  2. Please send an email to cs348b-spr0405-staff@lists.stanford.edu

Misc Data

You can render an image of the car shown in chapter 13 of pbrt and at the top of this page. The scene file to render is scene/tt.pbrt on the CD.  Be aware that this includes a very large scene file for the car (60 MB large), and might be difficult to render on the raptors with only 256 MB of memory.

pbrt assumes environment maps use a latitude-longitude parameterization. The images we provide have this format, so make sure you convert to the same if you want to try using other environment maps. You can covert from various other parameterizations using the panoramic transformations in HDRShop. Also, Paul Debevec's website is good resource for all things related to image-based lighting, and there you can also find more environment maps.


Please check back here for updates before sending questions to the staff list.

  1. Q: How do I build my importance_infinity.cpp file?
    A: In the first assignments we provided a Makefile for Linux and a Visual Studio project file for Windows.  In this assignment, please adapt one of these build configurations from an earlier assignment, or take a look at the versions used to build the core pbrt system.  This will be good practice for the final project when you will likely have to make much larger changes to pbrt and get it to build correctly.  If you have questions about how to do this, please send us email. 


**  The assignment passes all or almost all our tests.
*   Substantial work was put in, but the assignment didn't pass all our tests.
0  Little or no work was done on the assignment.

*** Extra credit may be given on a case-by-case basis for well done extensions that produce superior results.


Copyright © 2005 Pat Hanrahan