Graphics Reference
In-Depth Information
The fragment shader must use an output vec4 variable to declare what
color should be placed in its pixel. In OpenGL 3 and beyond, you declare this
yourself, something like
out vec4 fFragColor;
In pre-OpenGL 3 systems, there is a built-in vec4 variable, called gl_FragColor ,
for this purpose. Our examples here will use the standard in OpenGL 3 and
beyond.
You can declare other out vec4 variables in your fragment shader and
write color data to it in order to send your graphics output to another buffer or
a texture. You simply declare these variables to be the appropriate kind.
Other variables can also be provided by the previous pipeline stage
to give the fragment shader any data or information that could be used in
developing the pixel colors. Among the things these variables might provide
are
Light intensity, for scenes that use per-vertex lighting.
Geometric coordinates in model or eye coordinates, as discussed later in
this chapter.
Texture coordinates, used as indices into the texture array to a per-frag-
ment lighting model.
Per-vertex reflection vectors, for use in environment mapping, cube map-
ping, or any other computation that involves reflections.
Per-vertex refraction vectors, for use in cube mapping or any other com-
putation that involves refractions.
Vectors from vertices to the light source(s), for dealing with spot lighting
or Phong shading.
Data, for other computations that may depend on application-specific
information that has been passed through the vertex processor.
The coordinates ( x , y , z , 1/ w ) of each fragment in window-relative space,
from the built-in variable gl_FragCoord .
These variables are not required,
but they might be writen by the previous
shader in the pipeline in case the applica-
tion using the shaders needs them for its
particular use.
The overall input and output opera-
tions of fragment shaders are shown in
Figure 8.3.
Figure 8.3. Inputs and outputs for a fragment shader.
Search WWH ::




Custom Search