Game Development Reference
In-Depth Information
Listing 4-4. Simple Fragment Shader
// Fragment Shader
varying vec3 Color;
void main()
{
gl_FragColor = vec4(Color,1);
}
The gl_FragColor variable is a reserved variable that outputs the actual color of the fragment.
An example of a more complex fragment shader is shown graphically in Figure 4-13 . Here a texture,
texture coordinate, diffuse lighting, specular lighting, a light source, and an object material all
contribute to the final color of the object being rendered. I discuss these subjects in more detail later
in this chapter.
Material
From Vertex Shader
Light
Texture
Texture Coordinate
Diffuse Lighting for Vertex
Specular Lighting for Vertex
Emissive
Ambient
Diffuse
Specular
Alpha
Ambient
Diffuse
Specular
Fragment Shader
Color (gl_FragColor)
Figure 4-13. Complex fragment shader
Overview of the Shader Class
The Shader class holds the vertex and fragment shaders, as well as functions that are used to send
data from the main application to the shader programs (see Figure 4-14 ).
 
Search WWH ::




Custom Search