Graphics Reference
In-Depth Information
a single color value, except when rendering to multiple render targets (see
the section Multiple Render Targets in Chapter 11); in the latter case, a color
value is output for each render target. The color, depth, stencil, and screen
coordinate location ( x w , y w ) generated by the rasterization stage become
inputs to the per-fragment operations stage of the OpenGL ES 3.0 pipeline.
Example 1-2 describes a simple fragment shader that can be coupled with
the vertex shader described in Example 1-1 to draw a Gouraud-shaded
triangle. Again, we will go into much more detail on fragment shaders
later in the topic. We present this example just to give you a basic idea of
what a fragment shader looks like.
Example 1-2
A Fragment Shader Example
1. #version 300 es
2. precision mediump float;
3.
4. in vec4 v_color; // input vertex color from vertex shader
5.
6. out vec4 fragColor; // output fragment color
7. void main()
8. {
9. fragColor = v_color;
10. }
Just as in the vertex shader, line 1 provides the version of the Shading
Language; this information must appear on the first line of the fragment
shader ( #version 300 es indicates the OpenGL ES Shading Language
v3.00). Line 2 sets the default precision qualifier, which is explained in
detail in Chapter 4, “Shaders and Programs.” Line 4 describes the input
to the fragment shader. The vertex shader must write out the same set
of variables that are read in by the fragment shader. Line 6 provides the
declaration for the output variable of the fragment shader, which will be
the color passed on to the next stage. Lines 7-10 describe the fragment
shader main function. The output color is set to the input color v_color .
The inputs to the fragment shader are linearly interpolated across the
primitive before being passed into the fragment shader.
Per-Fragment Operations
After the fragment shader, the next stage is per-fragment operations. A
fragment produced by rasterization with ( x w , y w ) screen coordinates can
only modify the pixel at location ( x w , y w ) in the framebuffer. Figure 1-5
describes the OpenGL ES 3.0 per-fragment operations stage.
 
 
 
Search WWH ::




Custom Search