Fog

Fog is a powerful cue giving the impression of 3D. In addition, use of fog can result in the rather surprising benefit of improved rendering time for many scenes. Note that fog doesn't necessarily have to be thick or even strongly apparent to add to the 3D scene or to give improvement in rendering time. Fog can be used to soften edges much like one would use antialiasing.

The key to using fog in Java 3D is to first understand the difference among the three fundamental uses of fog. This first is the more obvious use for simulating weather patterns and providing additional parallax when moving through the environment.

The second use of fog is for depth cueing. As mentioned throughout this section, the sense of immersion (again, a central goal of 3D) is severely limited in VR. Most of the things that are done to improve the sense of immersion (for example, lighting, adding textures, or additional geometry, and so on) are computationally expensive. We return to this point here to emphasize the third use of fog, which is to reduce the number of rendered details in the scene.

Indeed, a good portion of any rendering contains computations that are simply not necessary, and even worse, detract from the sense of immersion. Fog provides one of the easiest ways to address this problem and amounts to a further form of culling (described in Chapter 10).

In Java 3D, the Fog class is the superclass for two subclasses that generate basic fog. The two subclasses differ in the mathematical model used to generate the fog. Both subclasses contain two fundamental pieces of information: the color of the fog (blue haze, black, and so on) and the spatial region and scope affected by the fog.

The ExponentialFog subclass is the class to use for creating strongly apparent fog that gives the look of foggy weather or a smoke filled environment. The thickness of an ExponentialFog increases exponentially with distance with the following equation:

EF = e(-density*distance)

where EF is the effect of the fog at any particular distance.

For a denser fog, one can simply increase the density value.

The constructors for an ExponentialFog are

public ExponentialFog()
public ExponentialFog(Color3f color)
public ExponentialFog(Color3f color, float density)
public ExponentialFog(float red, float green, float blue)
public ExponentialFog(float red, float green, float blue, float density)

To read out or to change the density of an ExponentialFog after it has been instantiated, the following capability bits must be set:

ALLOW_DENSITY_READ
ALLOW_DENSITY_WRITE

The LinearFog class is most appropriate for depth cueing because it allows for the setting of the front and back distance. As with the ExponentialFog, a LinearFog increases with distance, but this time in a linear fashion. Instead of specifying a density for the ExponentialFog, a front and back distance are used. To use a LinearFog for depth cueing, use a black fog and specify the front distance at the front of the object and the back distance for the back of the object. Depending on what type of object is being viewed, this can make a fairly dramatic difference in the perception of depth (see “Comprehensive Example #1: MR Physics Visualization”).

The equation for the thickness of a LinearFog is

EF = (backDistance-distance)/(backDistance-frontDistance)

The constructors for a LinearFog are

public LinearFog()
public LinearFog(Color3f color)
public LinearFog(Color3f, double frontDistance, double backDistance)
public LinearFog(float red, float green, float blue)
public LinearFog(float red, float green, float blue, double frontDistance, double 
backDistance)

The rendered color of any shape that is influenced by either an ExponentialFog or LinearFog can be determined from the calculated value EF:

color = EF * shapeColor + (1-EF)*fogColor

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset