Game Development Reference
In-Depth Information
(which might be skipped over by a casual reader), now that you have the
basic idea behind barycentric coordinates, let us take this opportunity to
mention a few places where barycentric coordinates are useful.
In graphics, it is common for parameters to be edited (or computed) per
vertex, such as texture coordinates, colors, surface normals, lighting values,
and so forth. We often then need to determine the interpolated value of one
of those parameters at an arbitrary location within the triangle. Barycen-
tric coordinates make this task easy. We first determine the barycentric
coordinates of the interior point in question, and then take the weighted
average of the values at the vertices for the parameter we seek.
Another important example is intersection testing. One simple way
to perform ray-triangle testing is to determine the point where the ray
intersects the infinite plane containing the triangle, and then to decide
whether this point lies within the triangle. An easy way to make this
decision is to calculate the barycentric coordinates of the point, using the
techniques described here. If all of the coordinates lie in the [0,1] range,
then the point is inside the triangle; otherwise at least one coordinate lies
outside this range and the point is outside the triangle. It is common for
the calculated barycentric coordinates to be further used to fetch some
interpolated surface property. For example, let's say we are casting a ray
to determine whether a light is visible to some point or if the point is in
shadow. We strike a triangle on some model at an arbitrary location. If
the model is opaque, the light is not visible. However, if the model uses
transparency, we may need to determine the opacity at that location to
determine what fraction of the light is blocked. Typically, this transparency
is in a texture map, which is indexed using UV coordinates. (More about
texture mapping is presented in Section 10.5.) To fetch the transparency
at the location of ray intersection, we use the barycentric coordinates at
the point to interpolate the UVs from the vertices. Then we use these UVs
to fetch the texel from the texture map, and determine the transparency
of that particular location on the surface.
9.6.4
Calculating Barycentric Coordinates
Now let's see how to determine barycentric coordinates from Cartesian co-
ordinates. We start in 2D with Figure 9.20, which shows the three vertices
v 1 , v 2 , and v 3 and the point p . We have also labeled the three “subtrian-
gles” T 1 , T 2 , T 3 , which are opposite the vertex of the same index. These
will become useful in just a moment.
We know the Cartesian coordinates of the three vertices and the point p .
Our task is to compute the barycentric coordinates b 1 , b 2 , and b 3 . This gives
 
Search WWH ::




Custom Search