Graphics Reference
In-Depth Information
Images Using Other Data
An important use of computer graphics is to create images that show how data
or other information is distributed over some concrete or abstracted geometry.
This use, and how it is facilitated by shaders, is discussed in the later chapter
on scientific visualization. Here we want to give a simple example of how the
eye coordinates can be used to modify the colors in an image.
The example we present is ChromaDepth coloring [2]. This computes the
color for each vertex in your model by the depth of the vertex in your scene;
that is, by the distance from the vertex to the eye
plane. The purpose of this is to give the illusion
of depth when the scene is viewed while wear-
ing special ChromaDepth glasses.
Because we are working with shaders,
we can obtain a vertex's eye coordinate depth
easily as the z -coordinate of its eye coordinate,
and can map that distance into a range that the
ChromaDepth( ) function below can use: typi-
cally 0 to 1, though the function will clamp the
value into that range. The ChromaDepth( ) func-
tion implements a transfer function , a function
that computes a color from a real number. This
can be called from a fragment shader to set the
color of each fragment as it is interpolated. This
function was used to create the image shown in
Figure 8.11.
Figure 8.11. A dinosaur with ChromaDepth col-
oring and erosion.
uniform float uChromaBlue; // z-depth corresponding to blue
uniform float uChromaRed; // z-depth corresponding to red
in float vLightIntensity; // from lighting model
in float vZ; // depth in eye coordinates
out vec4 fFragColor;
vec3
ChromaDepth( float t )
{
t = clamp( t, 0., 1. );
float r = 1.;
float g = 0.0;
float b = 1. - 6. * ( t - (5./6.) );
Search WWH ::




Custom Search