Graphics Reference
In-Depth Information
15.6.3 Clipping to the Near Plane
Note that we can't apply perspectiveProject to points for which z
0to
generate correct bounds in the invoking rasterizer. A common solution to this
problem is to introduce some “near” plane z = z n for z n <
0 and clip the triangle
to it. This is the same as the near plane ( zNear in the code) that we used earlier to
compute the ray origin—since the rays began at the near plane, the ray tracer was
also clipping the visible scene to the plane.
Clipping may produce a triangle, a degenerate triangle that is a line or point at
the near plane, no intersection, or a quadrilateral. In the latter case we can divide
the quadrilateral along one diagonal so that the output of the clipping algorithm is
always either empty or one or two (possibly degenerate) triangles.
Clipping is an essential part of many rasterization algorithms. However, it can
be tricky to implement well and distracts from our first attempt to simply pro-
duce an image by rasterization. While there are rasterization algorithms that never
clip [Bli93, OG97], those are much more difficult to implement and optimize. For
now, we'll ignore the problem and require that the entire scene is on the opposite
side of the near plane from the camera. See Chapter 36 for a discussion of clipping
algorithms.
15.6.4 Increasing Efficiency
15.6.4.1 2D Coverage Sampling
Having refactored our renderer so that the inner loop iterates over pixels instead of
triangles, we now have the opportunity to substantially amortize much of the work
of the ray-triangle intersection computation. Doing so will also build our insight
for the relationship between a 3D triangle and its projection, and hint at how it is
possible to gain the large constant performance factors that make the difference
between offline and interactive rendering.
The first step is to transform the 3D ray-triangle intersection test by projection
into a 2D point-in-triangle test. In rasterization literature, this is often referred to
as the visibility problem or visibility testing. If a pixel center does not lie in the
projection of a triangle, then the triangle is certainly “invisible” when we look
through the center of projection of that pixel. However, the triangle might also
be invisible for other reasons, such as a nearer triangle that occludes it, which is
not considered here. Another term that has increasing popularity is more accu-
rate: coverage testing, as in “Does the triangle cover the sample?” Coverage is a
necessary but not sufficient condition for visibility.
We perform the coverage test by finding the 2D barycentric coordinates of
every pixel center within the bounding box. If the 2D barycentric coordinates at
a pixel center show that the pixel center lies within the projected triangle, then
the 3D ray through the pixel center will also intersect the 3D triangle [Pin88].
We'll soon see that computing the 2D barycentric coordinates of several adjacent
pixels can be done very efficiently compared to computing the corresponding 3D
ray-triangle intersections.
15.6.4.2 Perspective-Correct Interpolation
For shading we will require the 3D barycentric coordinates of every ray-triangle
intersection that we use, or some equivalent way of interpolating vertex attributes
such as surface normals, texture coordinates, and per-vertex colors. We cannot
 
 
 
Search WWH ::




Custom Search