Fanning Software Consulting

Elevation Shading in Object Graphics

QUESTION: I know how to make an elevation-shaded surface in direct graphics. I just use the SHADES keyword and byte scale the data I am viewing. Something like this:

   Surface, data, Shades=BytScl(data)
   Shade_Surf, data, Shades=BytScl(data)

But I can't work out how do the same thing in object graphics. Can you show me how to do this?

ANSWER: Ever since this question was asked by someone in the IDL newsgroup I've been puttering around it in my odd moments because, frankly, I didn't know how to do it either. With the help of the friendly support people at RSI I was finally able to work it out and I include a simple example here.

The essential elements of the solution are these:

(1) Turn shading ON.

(2) Turn all lights OFF. (Well, ambient lights are OK, but unnecessary.) Lights modulate the effect of the shading and that is not what you want here. [Editor's Note: as of IDL 6.4, and maybe earlier, this is no longer the case, and the elevation surface actually looks better with lights on. See, for example, FSC_SURFACE in the Coyote Library.]

(3) Add a color palette to the surface. Although the ability to add a palette object to a surface object is undocumented, you can do it. This will make sure your surface is displayed with the correct colors all the time.

(4) Color each individual vertex in the surface with a color from the palette. Use the Vert_Colors keyword for this. It is also possible to create a texture map (with a palette if you like) and drape that onto the surface with the Texture_Map keyword, but it doesn't result in as smooth a surface as using the Vert_Colors keyword. Note that the argument to Vert_Colors must be a vector, so you have to REFORM the 2D shading array into a 1D vector.

The essential part of the code looks like this:

   s = Size(data, /Dimensions)
   thisPalette->LoadCT, 5
   thisSurface = OBJ_NEW('IDLgrSurface', data, x, y, Style=style, Shading=1, $
      Vert_Colors=Reform(BytScl(data), s[0]*s[1]), Palette=thisPalette)

You can see an example of how this is done by examining the program OBJECT_SHADE_SURF, which is available on this web page. Output from the program is shown below beside the same example created in direct graphics.

Here are two examples of an elevation shaded surface plot. The first example was created in direct graphics. The second example was created in object graphics.

Elevation-Shaded Surface in Direct Graphics Elevation-Shaded Surface in Object Graphics

Web Coyote's Guide to IDL Programming