Graphics Reference
In-Depth Information
out —a parameter of this type is not assumed to have an initial value the
first time it appears in the function, but it is assumed that a value will be
assigned before the function returns. Such parameters are intended to
communicate only from the called function to the calling function.
inout —a parameter that is intended to have a value when it is passed
into a function and to have a value, possibly different, when the function
returns. Such parameters are intended to provide two-way communica-
tion between the called function and the calling function.
One final additional capability in fragment shaders that should be men-
tioned is the discard operator. This is used to discard pixels so they will not be
passed to the framebuffer. Note that this is quite different from having the pix-
els made transparent by seting their alpha color value to zero. Pixels with zero
alpha still have a depth value and are recorded in the depth buffer, so they
mask any pixel that might lie behind them. As you can clearly see in Figure 3.5,
discarded pixels do not mask anything.
The GLSL shader language is missing some of the properties of C that
you may be used to using. Remember that shaders operate in the graphics pro-
cessor, not in a general-purpose processor, and that this limits the operations
that it makes sense for the language to support. Many of these can be worked
around (type casts) and some do not fit the concept of graphics processing (no
enums or strings)—and some you simply will need to live without or will need
to do outside the shader. Some of the differences include
No type casts (use constructors instead).
No automatic promotion (although some GLSL compilers handle this).
No pointers.
No strings.
No enums.
Can only use 1D arrays (no bounds checking).
No file-based pre-processor directives.
There are several atribute variables that you will use a lot in your vertex
shaders. These variables are defined in your application and give you access to
per-vertex OpenGL state information for your shader. In the examples above,
you saw some key values taken from these atribute variables, such as model
coordinates, normals, and color, and these values (possibly modified) were
turned into out variables so they could be used by tessellation or geometry
shaders or interpolated later by a fragment shader. Using our variable name
convention, and noting that you may use other names instead of those we
chose here, these variables include
Search WWH ::




Custom Search