Graphics Reference
In-Depth Information
quite familiar, but we want to remind our-
selves of them in the fragment shader context.
Uniform Variables
Fragment shaders can use uniform variables
that are provided by the system or by the
application. Because uniform variables do
not change within a graphics primitive, they
will not change during the interpolations that
the rasterizer performs. However, they can
be used for any computations that might be
needed in fragment processing.
As a preview, there is a special kind of
uniform variable for textures that is avail-
able to both vertex and fragment shaders,
but which is particularly important for frag-
ment shaders: the uniform sampler variable.
The uniform sampler variables correspond to
textures, so with the 1D, 2D, and 3D textures,
we have sampler types sampler1D , sampler2D ,
and sampler3D . Since GLSL also allows cube
mapping textures, we have the additional
sampler type samplerCube . The particular
sampler type that you use must correspond to
the texture type that was defined in your application. The value associated with
a sampler variable is the texture image number associated with the texture it
represents, which is also set up in the texture definition functions in your appli-
cation. The texture( ) function will be used with the texture unit and texture
coordinates to return the texture value at those coordinates, as in the line
Figure 8.2. The vertices of a graphics primitive
and the fragments that are processed to make up
the primitive being displayed.
vec4 textureValue = texture( TexUnit, coordinateVector );
We will see examples of this use in texture-based fragment shader code later
in this chapter.
Input and Output Variables
Perhaps the most important inputs to fragment shaders are the variables that
are passed to the fragment shader as out variables by the pipeline stage that
occurs right before the rasterizer and fragment processor. This could be a
vertex, geometry, or tessellation shader. These variables are the data that are
interpolated across a graphics primitive in order to give the fragment shader
enough information to set the colors of each pixel.
Search WWH ::




Custom Search