Main Content

Relief Mapping with Light Objects

This example shows how to create a light object to mimic the map produced in Colored Surface Shaded Relief, which uses shaded relief computations rather than light objects.

The meshlsrm and surflsrm functions simulate lighting by modifying the colormap with bands of light and dark. The map matrix is then converted to indices for the new "shaded" colormap based on calculated surface normals. Using light objects allows for a wide range of lighting effects. The toolbox manages light objects with the lightm function, which depends upon the MATLAB® light function. Lights are separate MATLAB graphic objects.

For more information, consult the reference pages for lightm, daspectm, material, lighting, and view, along with Lighting, Transparency, and Shading.

Illuminate Color 3-D Relief Maps with Light Objects

Add a light source to a surface colored data grid using lightm. First, load elevation data and a geographic cells reference object for the Korean peninsula. Display the data without lighting effects using meshm. Apply a colormap appropriate for elevation data using demcmap. Eliminate extra white space around the map using tightmap.

load korea5c
axesm('miller','MapLatLimit',[30 45],'MapLonLimit',[115 135])
meshm(korea5c,korea5cR,size(korea5c),korea5c)
demcmap(korea5c)
tightmap

Figure contains an axes object. The axes object contains an object of type surface.

Place a light source at the northwest corner of the grid, one degree high, using lightm. The lightm function is similar to the MATLAB® function light, but accepts latitude and longitude inputs instead of x, y, and z. Note that the figure becomes darker.

lightm(45,115,1)

Figure contains an axes object. The axes object contains an object of type surface.

Exaggerate the vertical dimension to make any relief viewable in perspective. Note that the figure becomes darker still.

daspectm('meters',50)

Figure contains an axes object. The axes object contains an object of type surface.

Set the ambient (direct), diffuse (skylight), and specular (highlight) surface reflectivity characteristics, respectively.

material([0.7 0.9 0.8])

Figure contains an axes object. The axes object contains an object of type surface.

By default, the lighting is flat (plane facets). Change the light to use Gouraud shading (interpolated normal vectors at facet corners).

lighting Gouraud

Figure contains an axes object. The axes object contains an object of type surface.

Remove the edges of the bounding box. Change the view by specifying an azimuth of -30º and an altitude of 30º.

ax = gca;
ax.Box = 'off';
view(-30,30)

Figure contains an axes object. The axes object contains an object of type surface.

If there is only one light in the current figure, you can remove it using clmo.

clmo(handlem('light'))

Figure contains an axes object. The axes object contains an object of type surface.