Graphics Reference
In-Depth Information
The fragment shader is where
all the interesting graphics hap-
pens. Its arrow starts “flying” at the
rotated model coordinate position of
its fragment and steps through the
data in the 3D volume, one vDirSTP at a time. If a step takes it outside the
volume, it ignores that value. At each step, it samples the data from the 3D
texture. Each of these samples is like a pixel with thickness, and so is called a
volume element , or voxel . If that scalar value is outside the desired [Min,Max]
range, the fragment shader doesn't discard the fragment as we did before,
but sets the alpha value to 0. to indicate that this voxel makes no contribu-
tion to the final blended color along this flight path. Otherwise, it sets the
alpha value to some value read from a glman slider variable. 2 If this voxel
does make a contribution to the final blended color, the scalar value from the
3D volume texture is converted into an RGB color, in this case using a rainbow
scale color transfer function.
The fragment shader composites data colors, as shown in Figure 15.16.
While the fragment shader will do the compositing front-to-back, it is
more intuitive to derive the equations by looking at the situation from back-
to-front. For the simple three-voxel example above, let's see what color will
ultimately get displayed in this fragment, by breaking each step into its own
equation. The arrow starts at the back of the volume, in this case voxel #2. It
uses voxel #2's alpha value to blend the black background color with voxel
#2's own color. It then moves forward and uses voxel #1's alpha value to blend
the current color with voxel #1's own color. It then moves forward and contin-
ues the process:
Figure 15.16. Determining the overall blending equation for
multiple colored voxels.
color 12 = α 2 * color 2 + (1 − α 2 ) * black,
color 01 = α 1 * color 1 + (1 − α 1 ) * color 12 ,
color * = α 0 * color 0 + (1 − α 0 ) * color 01 ,
We can algebraically combine these equations into one equation, like this:
(
) {
}
color
=∗ +−
α
color
1
1
α
color
0
0
0
01
{
}
) [
]
(
) ∗∗
(
=∗ +−
α
color
α
α
colo
r
+−
1
α
color
0
0
0
1
1
1
12
{
}
(
) ∗∗ +−
(
)
(
)
=∗ +−
α
color
1
α
α
color
1
α
α 2
color
+
1
α
black
.
0
0
0
1
1
1
2
2
2. Using one alpha value for all voxels is a concession to keeping this code segment small and read-
able. Normally, you would get the proper alpha as a function of the scalar value to reflect what data
ranges you are most interested in seeing.
Search WWH ::




Custom Search