Light Objects
Objects of the IDLgrLight class represent sources of illumination for graphic objects. Although light objects are not rendered themselves, they are part of the model tree and thus can be transformed along with the graphic objects they illuminate.
If no light sources are specified for a given model, a default ambient light source is supplied. This allows you to display many objects without explicitly creating a light source. The use of only ambient light becomes problematic, however, when solid surfaces and other objects constructed from polygons are displayed. With only ambient lighting, all solid surfaces appear flat—in fact, they appear to be single two-dimensional polygons rather than objects in three-dimensional space.
Note
Graphic objects do not automatically cast shadows onto other objects.
Creating Light Objects
There are no arguments to the IDLgrLight::Init method. Keywords to the Init method allow you to control a number of properties of the light object, including the attenuation, color, cone angle (area of coverage), direction, focus, intensity, location, and type of light.
The following statement creates a default light object. The default light object is a white positional light, located at the origin.
There are four types of light objects available. Set the TYPE property of the light object to one of the following integer values:
- 0 = Ambient light. An ambient light is a universal light source, which has no direction or position. An ambient light illuminates every surface in the scene equally, which means that no edges are made visible by contrast. Ambient lights control the overall brightness and color of the entire scene. If no value is specified for the TYPE property, an ambient light is created.
- 1 = Positional light. A positional light supplies divergent light rays, and will make the edges of surfaces visible by contrast if properly positioned. A positional light source can be located anywhere in the scene.
- 2 = Directional light. A directional light supplies parallel light rays. The effect is that of a positional light source located at an infinite distance from scene.
- 3 = Spot light. A spot light illuminates only a specific area defined by the light's position, direction, and the cone angle, or angle which the spotlight covers.
See "IDLgrLight" (IDL Reference Guide) for details on creating light objects.
Configuring Light Objects
In addition to the type of light source, you can control several other properties of a light object. The following example creates a solid surface object and displays it first with only ambient lighting, then adds various light objects to the scene.
Note
The SET_VIEW function is discussed in Finding an Appropriate View Volume.
Begin by creating some data, the surface object, and supporting objects:
zdata = DIST(40) mywindow = OBJ_NEW('IDLgrWindow') myview = OBJ_NEW('IDLgrView') mymodel = OBJ_NEW('IDLgrMODEL') mysurf = OBJ_NEW('IDLgrSurface', zdata, STYLE=2) ; Create the object hierarchy: myview->Add, mymodel mymodel->Add, mysurf ; Retrieve the X, Y, and Z ranges from the surface object: mysurf->GetProperty, XRANGE=xr, YRANGE=yr, ZRANGE=zr ; Convert x, y, and z ranges to normalized coordinates. xnorm = [-xr[0]/(xr[1]-xr[0]), 1/(xr[1]-xr[0])] ynorm = [-yr[0]/(yr[1]-yr[0]), 1/(yr[1]-yr[0])] znorm = [-zr[0]/(zr[1]-zr[0]), 1/(zr[1]-zr[0])] mysurf->SETPROPERTY, XCOORD_CONV=xnorm, $ YCOORD_CONV=ynorm, ZCOORD_CONV=znorm ; Rotate the surface to a convenient orientation: mymodel->Rotate, [1,0,0], -90 mymodel->Rotate, [0,1,0], 30 mymodel->Rotate, [1,0,0], 30 ; Use the SET_VIEW routine to set an appropriate viewplane ; rectangle and zclip region for the view: SET_VIEW, myview, mywindow ; Draw the contents of the view: mywindow->Draw, myview
Once the surface object is drawn, we see that there is no definition or apparent three-dimensional shape to the surface. If we add a positional light one unit in the Z direction above the XY origin, however, details appear:
mylight = OBJ_NEW('IDLgrLight', TYPE=1, LOCATION=[0,0,1])
mymodel->Add, mylight
mywindow->Draw, myview
We can continue to alter the lighting characteristics by changing the properties of the existing light or by adding more light objects. (You can have up to eight lights in a given view object.) We can change the color:
We can change the intensity of the light:
mylight->SetProperty, INTENSITY=0.7 mywindow->Draw, myviewNote
Also see Volume Lighting for volume object specific lighting information.
Optimizing Light Object Use
Lighting computations are generally set up to compute the light intensity based on the normal vector for the polygon. If the polygon normal faces away from the eye, the lighting model will likely determine that the light intensity for that polygon is zero. When the polygonal mesh being rendered is a closed surface, this is not a problem because the back-facing polygons will always be obscured. However, when the polygon mesh represents an open shape (for which back-facing polygons may be visible), the dark appearance of these polygons may hinder the user's perception of the overall shape. In such a case, two-sided lighting can be useful. Two-sided lighting is the process of reversing the normals for all back-facing polygons before computing the light intensities for that polygon.
In IDL's Object Graphics, two-sided lighting is enabled by default. When the additional lighting calculation is not required, one-sided lighting can be used to improve rendering performance. On an IDLgrModel object, set the LIGHTING property to a value of 1 to enable one-sided lighting.