Graphics Reference
In-Depth Information
but that code would not have been able to exploit the inherent parallelism of
the GPU.
Now, let's change the fragment shader to create contour lines. There are
geometric ways to create contour lines with real OpenGL line segments, but
for this example, we will use almost the same fragment shader code as we did
above. Let's say we want contour regions at each 10 degrees of temperature.
Then the main difference in the shader will be that we need to find how close
each fragment's interpolated scalar data value is to an even multiple of 10. To
do this, we say
float scalar10 = float( 10*int( (scalar+5.)/10. ) );
if( abs( scalar - scalar10 ) > uTol )
discard;
Notice that this uses a uniform variable called uTol , which is read from
a slider and has a range of 1 to 5. uTol is used to determine how close to an
even multiple of 10 degrees we will accept, and thus how thick we want the
contours to be. Various values for uTol produce the individual images in Fig-
ure 15.14.
Take a close look at what this fragment-based approach to contours gets
you compared with a line-based approach. Notice that the contours have dif-
ferent thicknesses. This is an indication of how much area was within uTol of a
10-degree value. In addition to what the contour lines usually tell us, this type
of display also lets us see how fast the data field is changing, i.e., the gradient.
Thus, we can tell that the data is changing slower at the blue areas than at the
red areas. This two-pieces-of-information-for-the-price-of-one-display feature
is always appreciated in visualization.
Figure 15.14. Contour lines using uTol values of 1, 4, and 5.
Search WWH ::




Custom Search