O'Reilly logo

Graphics Shaders, 2nd Edition by Steve Cunningham, Mike Bailey

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

375
Using Shaders for
Scientific Visualization
15
So far, we have been cuing through the shader world in one direction—exam-
ining dierent capabilities of GLSL. In this chapter, we try cuing in another
direction for a while—looking at an application focus. We will describe several
ways in which shader programming can enhance the display of data. Clearly,
there are many more ways to do this than just the few we illustrate, but the
point is to show how dierent aspects of shader programming can be brought
to bear on a single problem grouping.
There is much more to scientic visualization than we could begin to
cover in this chapter, of course. Our approach will be to consider how some
shader techniques from the previous chapters can be used for visualization.
These will include image manipulation, geometry modication with vertex
shaders, applications of textures, using fragment shaders to implement trans-
376
15. Using Shaders for Scientific Visualization
fer functions and to carry out ow visualization, and using geometry shader
techniques. This includes the whole range of shader techniques in the book,
showing just how deeply shader programming has aected computer graph-
ics applications.
Image-Based Visualization Techniques
The rst few visualization techniques we describe are image based. They have
already been covered in Chapter 10 on image manipulation, but it is useful to
repeat them again here as we look at how they impact the understanding of
data.
Image Negative
The rst method displays the negative of an image. This is the most simple of
the image shaders, but its use in visualization is surprisingly useful. Figure 15.1
shows a visualization image (a volume rendering, actually) of a mouse verte-
bra. The left-hand image in the gure is the original, and the right-hand one is
the negative. Notice how the negative brings out subtle details that were not
obvious in the original, especially the “pock marks” on the wall of the bone.
Many visualization programs have a “display negative” buon in their user
interface for just this reason.
Figure 15.1. The original (left) and negative (right) of an image, showing how the negative
often brings out new features.
377
Image-Based Visualization Techniques
Image Edge Detection
Another useful image shader in data visualization is the edge
detection Sobel lter. As seen in Figure 15.2, the Sobel lter
emphasizes the parts of the image where shading is changing
quickly, usually the sharp edges. In this gure, the edges have
been colored and superimposed on the original image, but it
is sometimes also useful just to display the edges alone, as we
did in Chapter 11.
Both the image negative and edge detection examples
were implemented by looking at a static image, but in fact
they can also become a post-process to any dynamic 3D ren-
dering. To do this, use the OpenGL render-to-texture capabil-
ity described in Chapter 9 to produce a texture image of the
3D scene, and then render a quadrilateral with this texture on
it, using one of the image shaders.
Toon Rendering
Toon rendering, covered in Chapter 11, starts with edge detec-
tion and adds color quantization. It is sometimes an excellent
way to perform architectural visualization, because it strongly
brings out a building’s key edges, while retaining the col-
ors but de-emphasizing them. This is shown in Figure 15.3,
which shows the Smithsonian Castle in Washington, DC both
without (left) and with (right) toon shading.
Figure 15.2. Edge detection
emphasizes certain features.
Figure 15.3. Toon rendering for architectural visualization.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required