Lightspeed views support a number of graphical effects which are applied globally, across all layers. These effects serve to improve the realism, sense of depth or scale, or simply the aesthetics of the images produced by the view. An example of such an effect is lighting, which greatly improves the user’s perception of the shape of 3D objects.

Using ALspGraphicsEffect and TLspGraphicsEffects

Graphics effects are represented by the abstract class ALspGraphicsEffect. The design of graphic effects classes is conceptually similar to that of ALspStyle: they describe the intended result, but do not contain any implementation logic. It is up to the layers and painters to interpret the properties of the effects, and to apply the effects in terms of OpenGL rendering as they see fit. Because of this approach, ALspGraphicsEffect itself is a fairly minimal class: it only contains an enable/disable flag and support for property change listeners.

The class TLspGraphicsEffects serves as a central repository for all the effects that are currently applied to a given ILspView. Each view creates its own instance of TLspGraphicsEffects, and exposes the instance via its TLspViewServices. TLspGraphicsEffects is essentially a collection of ALspGraphicsEffect instances. When you add an effect to this collection, it is automatically applied to the view.

Program: Adding graphics effects to a view
ILcdCollection<ALspGraphicsEffect> fx = getView().getServices().getGraphicsEffects();
fx.add( new TLspHeadLight( getView() ) );

The following sections describe the concrete implementations of ALspGraphicsEffect.

Adding lighting

Lighting can add important visual cues about the size and shape of 3D objects in a view. Without it, objects are always drawn at full brightness. When the lighting effect is enabled, the object sides that face the light are brighter, whereas the sides that face away from the light are darkened. There are three concrete types of ALspGraphicsEffect that enable lighting:

  • TLspDirectionalLight describes a light source coming from a specified direction. the light source is represented by a direction vector in world coordinates. A directional light can be used to simulate sunlight and its various directions in the course of a day.

  • TLspHeadLight is also a directional light, but its direction is linked to the orientation of the camera in the Lightspeed view. This can be a useful feature in many applications where lighting can improve a user’s perception of shape. In this case, lighting is not used to represent the time of day. The user does not want the whole Earth to have a bright side and a dark side.

  • TLspAmbientLight is a light of constant intensity that affects all objects equally. It is used to prevent that the unlit sides of objects turn totally black.

The Lightspeed view implementation currently only supports a single directional light, either TLspDirectionalLight or TLspHeadLight, and a single TLspAmbientLight. If more than one of each is added to TLspGraphicsEffects, only the first addition of each type will be used. The lighting effects that are added afterwards will be ignored. Also note that lighting is mostly ignored if you are using a 2D view.

Adding sky and atmosphere effects

To enable the display of a sky or atmosphere in the background of the view, add the class TLspAtmosphere to TLspGraphicsEffects. Note that when you use TLspViewBuilder, the atmosphere is added by default.

Adding fog

The class TLspFog enables a basic fog effect when it is used in a 3D view. Fog can be used to simulate weather conditions to some extent, and can also improve the sense of scale in the view. TLspFog computes the amount of fog in the view based on the altitude of the viewer above the Earth. Above a certain altitude, fog is no longer applied.

The following properties are available to tweak the fog effect:

  • The fog color: use setColor().

  • The visibility distance: use setVisibilityAtMinAltitude(). Objects located beyond this distance from the viewer are completely hidden in the fog.

  • A minimum and maximum altitude: use setMinAltitude() and setMaxAltitude(). These define the altitude range in which the visibility is varied. At or below the minimum altitude, the visibility is equal to the visibility distance, to be set with setVisibilityAtMinAltitude(). As the camera approaches maximum altitude, visibility gradually increases. Beyond the maximum altitude, fog is no longer applied.