Game Development Reference
In-Depth Information
Listing 4-46. Fragment Shader with Object Materials Added
uniform vec3 uMatEmissive;
uniform vec3 uMatAmbient;
uniform vec3 uMatDiffuse;
uniform vec3 uMatSpecular;
uniform float uMatAlpha;
vec3 EmissiveTerm = uMatEmissive;
vec3 AmbientTerm = uMatAmbient * uLightAmbient;
vec3 DiffuseTerm = vDiffuse * uLightDiffuse * uMatDiffuse ;
vec3 SpecularTerm = vSpecular * uLightSpecular * uMatSpecular ;
vec4 tempColor = vec4(DiffuseTerm,1) + vec4(SpecularTerm,1) + vec4(AmbientTerm,1) +
vec4(EmissiveTerm,1) ;
gl_FragColor = vec4(tempColor.r,tempColor.g, tempColor.b, uMatAlpha );
Textures
A 3D object can have an image or texture mapped onto it. A texture has texture coordinates along
the U or S horizontal direction and the V or T vertical direction. A texture can be mapped using these
coordinates to an object whose vertices match these coordinates. Basically, the texture is wrapped
around the 3D object according to the vertex UV texture coordinates (see Figure 4-25 ).
Vertex UV Coordinates
(1,0)
(0,0)
(0,1)
(1,1)
(0,0)
(1,0)
(0,1)
(1,1)
UV Texture Coordinates
Figure 4-25. Texture UV coordinate mapping
 
Search WWH ::




Custom Search