Graphics Programs Reference
In-Depth Information
▪ The vertex shader code in Listing 5-16 uses the built-in func-
tion max(float, float) to make sure that ambient
light is also taken into account.
▪ Ambient light sets a general level of brightness for the ob-
ject. It is a background light, and its intensity is constant for
all the objects in the scene, for all the surfaces, and over all
directions.
▪ Using the max function, the brighter among ambient
(“0.210”) and diffuse light, is selected as the diffuseIn-
tensity .
▪ As discussed, to obtain the final intensity of outgoing light,
multiply the diffuseIntensity variable with the reflec-
tion coefficient (also set as “0.210”), as well as the intensity
of incoming light ( Listing 5-16 ) .
Finally, the diffuseIntensity varying variable is passed to the fragment shader
and is set as the fragment color, as shown in Listing 5-17 . Please note that the diffuse
intensity can also be combined with the material color for the object.
Listing 5-17. VERTEX POINT LIGHTING/src/com/apress/android/vertexpoint-
lighting/GLES20Renderer.java
private final String _tankFragmentShaderCode =
"precision lowp float; // not to be done in a vertex
shader \n"
+ "varying float diffuseIntensity; \n"
+ "void main() { \n"
+ " vec3 diffuse = vec3(diffuseIntensity); \n"
+ " // gl_FragColor = vec4(0.1, 0.1, 0.25, 1.0) +
vec4(diffuse, 1.0); \n"
+ " gl_FragColor = vec4(diffuse, 1.0); \n"
+ "} \n";
Because you are interpolating the final intensity of light ( Figure 5-10 ) , shading effect
will be more pronounced, as shown in Figure 5-11 (output of VERTEX POINT
LIGHTING application from the source code), which can lead to unrealistic effects
on some occasions.
 
 
 
 
Search WWH ::




Custom Search