Java Reference
In-Depth Information
Figure 4. Baising of normal
Incident ray
Reflected ray
To achieve special effects such as bumping, the normal can be set manually so that it
becomes slanted as shown in Figure 4. As illustrated, the direction of the reflected ray will
be changed correspondingly, leading to interesting visual effects.
ambIent lIGht
Java 3D provides a variety of lights that can be controlled through parameters such as their
influence boundaries, on and off states, and scopes (Lighting and textures, 2006). The on
and off state of a light can be changed by using Lit.setEnable(boolean), while the scope of
a light corresponds to the objects that will be affected by the light. By default, all objects
in the scene will be affected. Figures 5 and 6 show an example code segment that can be
used to illustrate the effects of having different types of light.
The purpose of ambient light is to fill the whole space with a light having uniform in-
tensity from all directions. Its primary use is to provide background lighting for the whole
environment. The presence of ambient light will enable every visual object to give at least
a minimal amount of reflection.
In the example in Figure 6, an ambient light is created using AmbientLight(Color3f
(0.5f, 0.5f, 0.5f)) which will give a weak white light. Changing the color of this light during
run time is possible if the appropriate capabilities are set using lit.SetCapability(ALLOW_
COLOR_READ) and lit.setCapability(ALLOW_COLOR_WRITE). Specifically, with these
set, AmbientLight(Color3f (0f, 0f, 1f)) will give a blue ambient light.
The effect of having a weak white and a strong blue ambient light in the example of
Figures 5 and 6 is compared in Figure 7. Obviously, the background planes take on the
color of the ambient light, while the sphere has the same green color for both ambient
lights. This is because the sphere is set to have a material with black ambient, black dif-
fuse, white specular and green emissive colors. Thus, while there is no ambient reflection,
Search WWH ::

Custom Search