Game Development Reference
In-Depth Information
Ambient Lighting
Ambient lighting is sent to the fragment shader through the uniform vector variable uLightAmbient .
uniform vec3 uLightAmbient;
This can be directly sent to the AmbientTerm , which is one of the components that determine the final
color of the fragment produced from the fragment shader.
vec3 AmbientTerm = uLightAmbient;
Diffuse Lighting
The color of the diffuse portion of the light source is sent directly to the uLightDiffuse uniform
vector variable.
uniform vec3 uLightDiffuse;
The Diffuse vertex value vDiffuse is received from the vertex shader, as indicated by the varying
qualifier. Remember: Varying variables provide the link from the vertex shader to the fragment shader.
varying float vDiffuse;
The Diffuse component of the final fragment color is determined by multiplying the Diffuse value
calculated from the vertex shader by the color of the diffuse light source. Remember that the
vDiffuse term ranges from 0 to 1. If it is 1, the diffuse light color will be at full strength. If it is 0, the
diffuse light color will be black and, thus, not contributing to the final color of the fragment.
vec3 DiffuseTerm = vDiffuse * uLightDiffuse;
Specular Lighting
The specular color of the light source is input as a uniform vector variable called uLightSpecular .
uniform vec3 uLightSpecular;
The vSpecular variable holds the value of the specular light from the vertex shader.
varying float vSpecular;
The Specular term of the final fragment color is calculated by multiplying the amount of specular light
at the current vertex calculated from the vertex shader times the specular color of the light source.
vec3 SpecularTerm = vSpecular * uLightSpecular;
 
Search WWH ::




Custom Search