Graphics Reference
In-Depth Information
Example 5-2
Vertex and Fragment Shaders with Matching Output/Input
Declarations (continued)
void main()
{
o_fragColor = vec4(v_color, 1.0);
}
In Example 5-2, the fragment shader contains the definition for the
output variable o_fragColor :
layout(location = 0) out vec4 o_fragColor;
The fragment shader can output one or more colors. In the typical case,
we will render just to a single color buffer, in which case the layout
qualifier is optional (the output variable is assumed to go to location 0).
However, when rendering to multiple render targets (MRTs), we can use
the layout qualifier to specify which render target each output goes to.
MRTs are covered in detail in Chapter 11, “Fragment Operations.” For the
typical case, you will have one output variable in your fragment shader,
and that value will be the output color that is passed to the per-fragment
operations portions of the pipeline.
Interpolation Qualiiers
In Example 5-2, we declared our vertex shader output and fragment
shader input without any qualifiers. The default behavior for interpolation
when no qualifiers are present is to perform smooth shading. That is, the
output variables from the vertex shader are linearly interpolated across
the primitive, and the fragment shader receives that linearly interpolated
value as its input. We could have explicitly requested smooth shading
rather than relying on the default behavior in Example 5-2, in which case
our output/inputs would be as follows:
// ...Vertex shader...
// Vertex shader output
smooth out vec3 v_color;
// ...Fragment shader...
// Input from vertex shader
smooth in vec3 v_color;
OpenGL ES 3.0 also introduces another type of interpolation known as flat
shading. In flat shading, the value is not interpolated across the primitive.
Rather, one of the vertices is considered the provoking vertex (dependent
 
 
 
Search WWH ::




Custom Search