Contents |
|
Surface Normal Calculation
To calculate the surface normals, we must first calculate the two
tangent vectors to the surface. We calculate the s tangent vector by
replacing the s-based basis function value in the position calculation
with the value of its derivative at the sample point s. Similarly, we
calculate the t tangent vector by replacing the t-based basis function
value with the value of its derivative at the sample point t. The cross
product of these vectors generates the surface normal at the sampling
point. To do this calculation efficiently, we precalculate all the basis
function derivatives data needed during the process, and store the
derivative values together with the basis function values that are already
stored for the position calculation. The code for this calculation
is:
normk.x = normk.y =
normk.z = normt.x = normt.y = normt.z = _ZERO_;
for
(k=0;k<4;k++) {
PIIIVector3 *wpt =
&worldBase;
normt.x += coeff *
wpt->x;
normk.z += coeff * wpt->z;
}
}
PIIIVector3 norm;
// Cross product of partial
derivatives
norm.y = normk.z*normt.x -
normk.x*normt.z;
norm.z = normk.x*normt.y -
normk.y*normt.x;
// One over size of
normal
// Normalize the surface
normal
norm.x *= size;
norm.y *=
size;
norm.z *=
size;
Performance
Tessellate position
only | ||||
Tessellation level |
# of
Triangles |
Legacy
|
Pentium III code |
Ratio |
2 |
64 |
1280 |
1150 |
111% |
3 |
256 |
2400 |
1550 |
155% |
4 |
576 |
3880 |
1770 |
219% |
6 |
1600 |
6500 |
2800 |
232% |
8 |
3136 |
8570 |
4050 |
212% |
12 |
7744 |
11500 |
6800 |
169% |
18 |
18496 |
13500 |
9650 |
140% |
24 |
33856 |
14500 |
11700 |
124% |
Tessellate position and calculate one directional light in world space | ||||
Tessellation
level |
#of triangles
|
Legacy code |
Pentium III code |
Ratio |
2 |
64 |
2800 |
1610 |
174% |
3 |
256 |
5100 |
2770 |
184% |
4 |
576 |
7100 |
3300 |
215% |
6 |
1600 |
10100 |
5380 |
188% |
8 |
3136 |
12000 |
7370 |
163% |
12 |
7744 |
13800 |
10450 |
132% |
18 |
18496 |
14850 |
12850 |
116% |
24 |
33856 |
15530 |
13880 |
112% |
Ideas for Future Improvements
The normal calculation and, in point light cases, the extra
tessellation to object/world coordinates, is very compute intensive. There
are several ways to approximate the surface normals using different levels
of interpolations of the surface edges. In our code, we implemented a
simple linear interpolation. Other interpolation techniques use Hermite
basis functions, which are based on the second-derivative values on the
surface edges. All these techniques produce a fairly decent image, as long
as the surface curvature is relatively small.
Bezier patches can save communications bandwidth, as well as add to the photo-realism of the application. The optimization techniques shown enables real-time Bezier patch tessellation within a 3D engine; thus encouraging this type of content to be more common in real time applications.
A demo utilizing the techniques discussed in this article can be found here.
Haim Barad has a Ph.D. in Electrical Engineering (1987) from the University of Southern California. His areas of concentration are in 3D graphics, video and image processing. Haim was on the Electrical Engineering faculty at Tulane University before joining Intel in 1995. Haim is a staff engineer and currently leads the Media Team at Intel's Israel Design Center (IDC) in Haifa, Israel.
___________________________________________________________________