Graphics Reference
In-Depth Information
4.4.3 Ray-Tracing Pass
The following function is the reflection formula where V is the view direction and
N is the surface normal direction (surface orientation) and the return value is
the reflection vector:
Reflect ( V,N )=2( V
N ) N
V.
·
The dot is the dot product, also known as the scalar product, between the two
vectors. We will later use this function to calculate our reflection direction for
the algorithm.
Before we continue with the ray-tracing algorithm, we have to understand
what the depth buffer of a 3D scene actually contains. The depth buffer is
referred to as being nonlinear, meaning that the distribution of the depth values
of a 3D scene does not increase linearly with distance to the camera. We have a
lot of precision close to the camera and less precision far away, which helps with
determining which object is closest to the camera when drawing, because closer
objects are more important than farther ones.
By definition division is a nonlinear operation and there is a division happen-
ing during perspective correction, which is where we get the nonlinearity from. A
nonlinear value can't be linearly interpolated. However, while it is true that the
Z-values in the depth buffer are not linearly increasing relative to the Z-distance
from the camera, it is on the other hand indeed linear in screen space due to the
perspective. Perspective-correct rasterization hardware requires linear interpola-
tion across an entire triangle surface when drawing it from only three vertices. In
particular the hardware interpolates 1/Z for each point that makes up the surface
of the triangle using the original three vertices.
Linear interpolation of Z directly does not produce correct depth values across
the triangle surface, though 1/Z does [Low 02]. Figure 4.10 explains why non-
perspective interpolation is wrong.
A , intensity = 0.0
a , intensity = 0.0
C , intensity ≠ 0.5
virtual
camera
c , intensity = 0.5
Line AB
b , intensity = 1.0
B , intensity = 1.0
Image plane
(screen)
Figure 4.10. Illustration of interpolating an attribute directly in screen space giving
incorrect results. One must do perspective correct interpolation as described in [Low 02].
The depth buffer value, 1/Z, is perspective correct so this allows us to interpolate it in
screen space without any further computation.
Search WWH ::




Custom Search