CS 563: Advanced Computer Graphics
Assignment 1: Heightfield Intersection
Due: February 20, 2007
Description
This assignment was adapted from CS 348B, Stanford University, Spring 2005
For this assignment, you will improve pbrt's support for rendering
terrain in scenes like landscapes and seascapes. Terrain is often represented
as an elevation map, or what we will call a heightfield: a 2D table
indicating the height of a surface above each point of a uniform grid. In other
words, a heightfield is tabulated form of a height function z(x,y) stored in a
2D array.
pbrt has no native support for rendering directly from heightfield
data. Instead, it converts heightfields into triangle meshes by connecting
adjacent height values in the array. This approach is general but relatively
inefficient; by converting to triangles we lose the orderly structure of the
heightfield, which can be exploited to render more efficiently. Your assignment
is to apply techniques similar to those used for grid-based acceleration
structures to develop a fast intersection routine for heightfields.
Step 1
Click here to download a zip file containing
several pbrt scene files, heightfield data, and textures. The UNIX
version of pbrt should build the heightfield shape plugin by default.
If you're using windows, copy the heightfield.vcproj file to
pbrt/win32/Projects/ and add the project file in the pbrt solution.
After you have built the heightfield plugin, run pbrt on scenes:
hftest.pbrt and landsea-0.pbrt, and you should see output
images (hftest.exr and landsea-0.exr) that look like this:
The 4x4 heightfield in hftest.pbrt (left image) is designed for
debugging; use this file as you develop and test your intersection algorithm.
The landsea-0.pbrt contains two 64x64 heightfields (land and sea) and
there are several views of this scene (0-3). landsea-big.pbrt contains a
1000x1000 heightfield and will likely take a while to render and consume loads
of memory in the process.
Step 2
Your assignment is to write a fast heightfield intersection algorithm, which
will allow you to render higher resolution terrains more quickly than the
current implementation. You should do this by modifying the existing
'pbrt/shapes/heightfield.cpp' file; you do not need to change other pbrt
files. Specifically, you need to:
-
Add and implement Intersect() and IntersectP() functions, which
will allow the renderer to intersect a ray directly with the
heightfield.
-
Change CanIntersect to return true, so that pbrt uses your functions
instead of the Refine method to convert to a triangle mesh.
Your implementation of Intersect() and IntersectP() will likely use an
acceleration structure like a uniform grid or kd-tree. If you choose to
use an acceleration structure, you should start by searching
for a paper that describes a fast method for marching rays
through uniform grids. Also feel free to peruse the pbrt source for
examples, but make sure you understand any code that you borrow.
Step 3
Once you have the fast intersection routines working, add the following
additional features:
- Compute the u and v coordinates so that you can texture map heightfields.
You can test this by rendering the texture.pbrt scene, which maps the
land heightfield with a colored grid texture.
- Perform Phong interpolation of the normals across each heightfield
triangle. See the text book for information about Phong interpolation.
Here are some example images of what you should see after completing the steps above:
Suggestions
- Make sure you understand how pbrt deals with transformations (e.g.
object-to-world)
- You should understand the
GetShadingGeometry() function and how it's used by the integrator to shade an
intersection point. You will need to implement this as a member function in the
heightfield class (for Step 3).
- It will probably be difficult for your algorithm to out perform
pbrt, which uses a highly optimize 3D kd-tree to render triangle
meshes. However, you should try to make your code as fast as possible.
Submission
Write a web page and mail the URL to me.. The page should contain the following:
-
A brief description of the algorithm(s) you implemented in steps 2 and 3.
- A link to your modified heightfield.cpp file
- Two renderings of landsea-0.pbrt: one with Phong interpolated
normals and one without.
-
Renderings of scene files landsea-0.pbrt, landsea-1.pbrt,
landsea-2.pbrt, and texture.pbrt,
with Phong interpolation if you have it. Below each image include the time it
took to render using your implementation vs. the original version of
heightfield.cpp.
-
A rendering of landsea-big.pbrt, which contains a 1000x1000 sea
heightfield. This should be a good stress test for your algorithm.
FAQ
- Q: I don't understand what this assignment is about. Doesn't pbrt
already store the height field in an acceleration structure?
A: The default pbrt implementation does store the tessellated height field
in a 3D K-d tree. This default implementation is actually highly
optimized. However, you can provide a useful specialized
implementation for height fields by exploiting the structure of the height
field. For instance, a common approach is to traverse a 2D grid,
building the height field triangles in that cell when you need to.
This can save a lot of memory for larger height fields. Another
approach would be to use a 2D K-d tree. These specializations are possible
because of the structure of the height field, and are simpler and often more
efficient than more general 3D versions. Choose an acceleration
structure that interests you and explore it in this simpler 2D space.
- Q: How do I compile pbrt with optimizations?
A: On Unix systems, type 'make clean' to delete existing object files and executables.
Type 'make OPT=-O2' (there's a dash before the capital O). That builds
the system with optimization. On Windows, build the system under
"Release" mode.
- Q: How do I time my code for the timing results on my web page?
A: On Linux, you can use commands such as: 'time pbrt hw1-view1.lrt'. After rendering is complete, the time command will print
out a line, where the first token is the total time executed in user mode,
in seconds.
- Q: I can't get my intersection routine faster than the default
implementation!
A: It may be challenging to get your intersection routine as fast as
the default version in pbrt, because pbrt has been quite carefully optimized
with a 3D K-d tree. It is not a requirement for the assignment
that your code run as fast as the default implementation (your routine is still
practically useful because it probably uses less memory than the
default). Nevertheless, it is possible to get your specialized height
field intersection as fast or faster than pbrt, and you can get extra credit
if you succeed in doing so.
- Q: I can't seem to eliminate some black reflected regions in the
foreground of the image when rendering with landsea-big.pbrt. Is that okay?
A: You may get some black regions where the water is reflecting far away
from the forward direction. The sky background doesn't actually cover
the entire hemisphere, and the water will appear black where the correct
reflection direction misses the sky geometry (a cylinder). This
doesn't happen in sea1.lrt, but it does in the foreground of landsea-big.pbrt
where the water is more bumpy. However, if you are getting black
speckles on the crests of your waves in the distance, then this is likely an
artifact of your Phong interpolation scheme; this is something you should
eliminate.
Grading
This homework will be graded according to the following system:
0 - Little or no work was done
* - Significant effort was put into the assignment, but rendering does not
work fully
** - The intersection routine was functionally complete, but step 3 doesn't
work at all.
*** - Intersection and texture mapping worked, but normal interpolation
didn't.
**** - Intersection and normal interpolation worked, but texture mapping
didn't.
***** - All requirements satisfied, and the implementation is faster than the original
Note that only ONE star is available for intersection routines that aren't
functional from all viewpoints, regardless of texture mapping and/or normal
interpolation.