Graphics Reference
In-Depth Information
Additional Output Variables
A fragment shader program can also write a value to the built-in variable
float gl_FragDepth so that the depth can be used in later depth process-
ing. Seting this overrides the fragment depth that the graphics pipeline keeps
around for use in the depth buffer. This would be a way, for example, for you
to offset pixels' depth values to alter the scene's z -ighting behavior.
Particularly Important “In” Variables for the Fragment Shader
The most important of the vary-
ing variables are those that give the
position, color, texture coordinates,
depth, and user-defined values.
These are described in more detail
below.
If you are working in compatibility mode,
there are built-in versions of several of the
input variables we discuss in this chapter:
gl_Vertex
gl_Normal
gl_MultiTexCoordi i
gl_NormalMatrix
gl_ModelViewMatrix
Here we use the variable name conventions
we introduced earlier, but the conventions
are basically the same as the built-in names
without the gl_ prefix .
Colors
Computing the color for each frag-
ment can be done in many differ-
ent ways. The fixed-function role
includes operations to interpolate
colors that are passed in for each
vertex, to interpolate texture coordi-
nates and use textures to calculate colors, and to use the interpolated color and
texture color to develop a final pixel color. Once the color is developed, it is
writen to your output vec4 color variable ( fFragColor in our case) to store the
pixel's color for further work before the fragment is writen to the color bufer.
From now on, we are going to use the vec4 variable fFragColor to indi-
cate we are assigning the final pixel RGBA to. You, of course, are free to use
whatever variable name you want, or to continue to use gl_FragColor in the
compatibility profiles.
Texture Coordinates
If your graphics primitives have been assigned texture coordinates, you can
get the texel coordinates for each vertex from whatever texture coordinates
variable you have interpolated through the rasterizer. As most of our exam-
ples in this chapter use just a vertex and fragment shader, we will call this vec2
variable vST .
Once you have the texture coordinates interpolated through the raster-
izer, you get the actual texel color from the texture( ) function. You can then
Search WWH ::




Custom Search