Game Development Reference
In-Depth Information
Textures in the Vertex Shader
Texture information in the vertex shader is basically passed through to the fragment shader for our
basic lighting method. The aTextureCoord receives input vertex texture coordinates.
attribute vec2 aTextureCoord;
The vTextureCoord variable passes through this texture coordinate information into the fragment shader.
varying vec2 vTextureCoord;
vTextureCoord = aTextureCoord;
Textures in the Fragment Shader
Texture information in the fragment shader is used in combination with the diffuse, specular, ambient,
and emissive light produced by the object to find its final color. The color from the currently active
texture that matches the texture coordinates in vTextureCoord is found through the texture2D()
function. That color is then modified by the total combined light from the diffuse, specular, ambient,
and emissive light colors for that vertex.
uniform sampler2D sTexture;
varying vec2 vTextureCoord;
vec4 color = texture2D(sTexture, vTextureCoord);
vec4 tempColor = color * (vec4(DiffuseTerm,1) + vec4(SpecularTerm,1) + vec4(AmbientTerm,1) +
vec4(EmissiveTerm,1));
Summary
In this chapter, I covered the basic concepts of programming graphics in OpenGL ES 2.0 for
Android. I started with a general description of how OpenGL rendering works, then moved on to
a more specific explanation, discussing the 3D math, transformations, and vertex and fragment
shaders involved. Next, I gave an overview of the shader language used for vertex and fragment
shaders, as well as some examples. Then I covered core custom classes that relate to fundamental
concepts in OpenGL ES 2.0 that are essential to creating not only 3D games but any OpenGL ES 2.0
graphics application.
 
Search WWH ::




Custom Search