Rendering With Bitmaps31 Jan, 1998 By: John E. Wilson
Of all the new rendering capabilities in R14, those that can attach bitmap file images to surfaces are probably the most useful. These features enable you to make AutoCAD objects look like wood, marble, concrete, rusted steel, printed cloth and so forth. In fact, your limits in making realistic-looking materials in renderings are only controlled by the bitmap files you have to work with.
Moreover, you can combine images to simulate surfaces with bumps and protrusions, such as those on embossed metal, bricks and quilts. You can also use bitmap images to simulate reflections in a window or on an automobile hood. In addition to using bitmap images for materials and surfaces, you can use them to add extra objects such as trees, shrubs and signs within your renderings, and you can use them to add such things as clouds and mountains to the background of your renderings.
This month, we will explore the use of bitmap files in simulating surface materials. AutoCAD generally refers to images used for this purpose as "texture maps." This article will be hands-on, so you should go to your computer now and start up AutoCAD R14 (or even R13, provided you also have AutoVision R2). You will not need any prior experience in rendering or even in working in 3D space.
Let's start by exploring the use of texture maps on flat surfaces. Open a new drawing. It doesn't matter what the settings are for the drawing, since we will not make anything you will want to keep. Make a 3D face on the World Coordinate System xy plane by using the following command line input:
- Command: 3DFACE
- First point: 0,0
- Second point: 1,0
- Third point: 1,1
- Fourth point: 0,1
- Third point: Enter
The layer and color you use for this 3D face is not important. Now, set a SE Isometric viewpoint. It is easiest to do this through the Viewpoint flyout on the Standard toolbar. (Actually, the size and location of the 3D face is not critical, and neither is the viewpoint, but our selections are as good as any, and they are convenient to implement.) Since we will be repeatedly using several rendering commands, you should activate the Render Toolbar to avoid having to pull menus down or type in command names. You might also want to divide AutoCAD's graphic area into four viewports, so that you will be able compare the effects of various rendering settings. The following command line input sequence is an easy way to do this:
- Command: VPORTS
We will not use any lights in our rendering. When you do not install a light, AutoCAD automatically uses a direct light pointed in the view direction for rendering. That single light will serve our purposes.
Start the RMAT command. You can do this by selecting the button on the Render Toolbar that has the image of a paint brush and sphere, or you can enter RMAT on the command line. Either method will bring up the Materials dialog box. On the right side of this dialog box will be a button labeled New. Make sure that the word "Standard" is displayed below this button, and then click the button.
This action will bring up a dialog box titled New Standard Material. First, type in a name in the Material Name edit box. I used the name "TEST 1." Next, click the Color/Pattern radio button located on the left side of the dialog box. Then, click the Find File button in the lower-right corner of the dialog box. If you accepted the default directory (or folder, to use the latest terminology) names when you installed AutoCAD, the file you are looking for will be in the Textures folder. The name of the file is checker.tga. (A file named checkers.tga also exists. You don't want that one.) Double click on the file's name. This will return you to the New Standard Material dialog box, with the checker.tga file shown in the File Name edit box.
All of the files Autodesk provides for use as bitmap images are in the Targa True Vision file format, which has a TGA filename extension. Nevertheless, AutoCAD's renderer does accept bitmap files in other formats, including those with GIF and PCX filename extensions and formats.
Click the OK button to return to the Materials dialog box. The name of your new material will be shown in the list box on the left side of this dialog. Make sure the name is highlighted and click the Attach button that is located on the right side of the dialog box. When the dialog box disappears, pick a point on any edge of your 3D face, and press [Enter]. The Materials dialog box will reappear, and you should click the OK button to exit the RMAT command.
Invoke the RENDER command, either by typing it in the command line or by pressing the Render Toolbar button that has a green teapot. Within the Render dialog box, set Rendering Type to "Photo Real." Then, click the Background button to bring up the Background dialog box. Now, turn off the AutoCAD Background toggle, select Solid for the background type, set the red, green and blue color values to about 0.30 and click the OK button. When the Render dialog box reappears, click the Render button to render the current view.
Figure 2. These four renderings use the same bitmap image attached to the same 3D face. By changing the image's scale, offset and rotation, you can obtain a variety of appearances.
Your rendering should look like the one in the upper left corner of Figure 2. We chose a simple image of four squares-two are white and two are black-so that you will be able to easily spot the changes we will make to the image. AutoCAD automatically adjusted the size and shape of the bitmap image to fit the surface to which it is attached. Since our 3D face is square, as is the image in the bitmap file, the image on the surface is not distorted. If our 3D face had been rectangular, rather than square, the black and white squares in the image would have been squeezed into rectangles.
You can, though, control the shape and size of the image. To see how this is done, restart the RMAT command, highlight the name of your material in the Materials dialog box and press the Modify button. The dialog box that will be displayed will be named Modify Standard Material, but its contents will be identical to those in the one you used before. Make sure that the Color/Pattern radio button is active and press the Adjust Bitmap button that is located on the right side of the dialog box.
A dialog box named Adjust Material Bitmap Placement will appear. Through this dialog box, you can adjust both the position and the relative size of the bitmap image on the surface. Furthermore, the buttons labeled Tile and Crop determine whether the image will be repeated or just used once on the surface. For now, we want the image repeated, so make sure that the Tile radio button is active. Then, enter the value of 2.0 in the edit boxes for Scale u and v. You can do this with the inner slide bars around the image tile or by typing in the values directly. You might notice a quirk with these edit boxes because you must delete some digits before adding new ones. You can also activate the Maintain Aspect Ratio toggle to connect the u and v scale values. These scale values represent the number of times the image will be repeated in the u and v directions. AutoCAD uses the letters u and v because directions on a surface are independent of the x and y axes. When you have set the scales, click the OK button in the three dialog boxes to exit RMAT.
When you now render the current view, it should look like the one in the upper-right corner of Figure 2. Since we used a scale of 2.0 for both the u and v directions, the bitmap image has been repeated two times in each direction; consequently, the squares are half their original size.
Next, we will experiment with moving the origin of the bitmap image. Start the RMAT command again, click the Modify button and then click the Adjust Bitmap button to bring up the Adjust Material Bitmap Placement dialog box. Return Scale in the u and v directions to 1.0, and set Offset in the u and v directions to 0.25. You can see a preview of your settings by pressing the Preview button. Since we are working with a flat surface, you will first want to set the preview object to a cube rather than to a sphere. Exit the RMAT command, and render the current viewport. Your rendering should look like the one in the lower-left corner of Figure 2. Notice that the image has shifted in both directions by a distance equal to one-fourth of its size.
You can also rotate the bitmap image. To do this, invoke the SETUV command. The button on the Render toolbar for this command has a green teapot overlaid with u and v axes. You will be prompted to select one or more objects. Pick one edge of your 3D face and press [Enter]. As soon as you do this, a dialog box named Mapping will be displayed. Pick the button labeled Adjust Coordinates. AutoCAD will display a dialog box named Adjust Planar Coordinates. Near the bottom of this dialog box is an edit box labeled Rotation. Enter a value of 45 in this edit box by typing it in directly or by using the slider bar. Notice that the square in the image tile will rotate. You can also see a preview of the rotation. Press the OK button in two dialog boxes to exit the SETUV command. This time, your rendering should look like the one in the lower-right corner of Figure 2.
When bitmap images are attached to flat surfaces, AutoCAD assumes the surfaces are parallel with the World Coordinate System xy plane. Since 3D models will typically have many flat surfaces that are not parallel with the WCS xy plane, we'll explore images attached to flat surfaces that are skewed to the principal planes.
Erase the 3D face you have been working with and do a REGENALL to get rid of the rendered images of it in all of your viewports. Your current view direction should still be that of an SE Isometric view. Use the following command line input to rotate the xy plane to be perpendicular to the view direction:
- Command: UCS
You can also set this UCS from the View UCS button on the UCS flyout in the Standard Toolbar. Now, use the same command line input you used earlier to draw a 3D face. This 3D face will not be parallel to any of the principal planes. To emphasize this, change your viewpoint with the following command line input:
- Command: VPOINT
- Rotate/<View point>
- (1.0000,-1.0000,1.0000): .5,-1.5,.6
Figure 3. The 3D face that the bitmap image is attached to is not parallel with any of the principal planes. Consequently, you must align the image with the surface, or else it will be distorted, as shown on the left.
You can restore the World Coordinate System, too, but it is not necessary to do so. Invoke the RMAT command. Make sure that the name of the material you have been using is highlighted, click the Attach button, pick any edge on your new 3D face and press [Enter]. Then, click the OK button to exit RMAT. When you render the current viewport, the results should be similar to the one shown on the left in Figure 3. The bitmap image is distorted and is not aligned in any way with the attached 3D face.
We will use the SETUV command to align the bitmap image with the 3D face. Start this command and pick an edge on the 3D face in response to the prompt to select objects. When the Mapping dialog box appears, click the Adjust Coordinates button to bring up the Adjust Planar Coordinates dialog box. AutoCAD's renderer knows that the 3D face is planar, but it doesn't know anything about its orientation in space. Therefore, activate the Picked Plane radio button to define the plane of the 3D face. AutoCAD will temporarily dismiss the dialog box and will prompt you to pick the lower-left, lower-right and upper-left corners of the mapping plane. Use endpoint object snaps to pick these points. Click two consecutive OK buttons to leave the SETUV command.
When you render the viewport, your 3D face should look like the one on the right side of Figure 3. The image is now properly aligned and positioned in accordance with the material parameters. Since the SETUV parameters pertain to specific objects, the bitmap rotation angle you established for the old 3D face does not apply to this new one. Therefore, the bitmap image is not rotated as it was in your last rendering of your old 3D face.
Next, we will see how bitmap images work on tube-shaped surfaces. Erase the 3D face you have been working with and restore the World Coordinate System. You can leave the viewpoint as is. If you are using multiple viewports, use the VPORTS command to return to just a single viewport.
AutoCAD treats all of the surfaces on a solid model as a single object when materials are attached. That is not necessarily bad, but since we want our bitmap image to appear only along the length of the tube, and not on its ends, we will make a surface model tube, rather than a solid model cylinder. [Editor's note: you could also create a smaller diameter cylinder concentrate with the first and subtract it with a Boolean operation, creating a solid-modeled tube.]
Start by drawing a circle that has a radius of one unit. Then, place a copy of that circle one and one-half units in the positive z direction. Zoom-all so that the two circles fill the viewport. Now, use the following command line input to set up and make a surface between the two circles:
- Command: surftab1
- New value for SURFTAB1 <6>: 12
- Command: RULESURF
Select the first defining curve: Pick anywhere on one of the circles. Select the second defining curve: Pick anywhere on the other circle.
Even with a SURFTAB1 setting of 12, the tube surface is still angular, but in a rendering it will take on a smooth, rounded appearance. You might want to divide AutoCAD's screen into four viewports.
Start the RMAT command and begin another new standard material. Assign a name to your new material, make sure that the Color/Pattern attribute is checked and click the Find File button. This time, the bitmap file we want is named 3D.TGA. It should be the very first file in the directory the previous bitmap file was in. This file is good at demonstrating the effects of various parameters.
When you locate the file name, double click on it to associate the file with your material and return to the New Standard Material dialog box. Then, click the OK button to go back to the Materials dialog box. Make sure that the name of your new material is highlighted, and click the Attach button. Pick one of the vertical lines on the surface in response to the prompt to select objects (make certain not to include either of the circles in your selection set), and press [Enter]. Lastly, click the OK button to exit the RMAT command.
Figure 4. Bitmap images attached to non-planer surfaces follow the surface, but you have to take special steps to keep the image from being distorted. The two lower renderings show the difference between tiled and cropped images.
The colors in the bitmap will go well with a black background, so click the Background button in the Render dialog box, turn off the AutoCAD Background button and leave the three colors at zero to ensure that the rendering background will be black. Return to the Render dialog box, make sure that "Photo Real" rendering is in effect and render the current view. Your rendering will probably look like the one in the upper-left corner of Figure 4. The bitmap contains the word 3D, but it is not at all evident.
To fix the image, start the SETUV command, select the tube surface when you are prompted to select objects and press [Enter]. When the Mapping dialog box appears, notice that the bitmap projection is planar, which does not match the shape of our surface. Click the Cylindrical radio button and click the OK button to exit the SETUV command. When you render the current view this time, it should look similar to the one in the upper right corner of Figure 4. The letters "3D" in white letters on a red background are now evident, although they are distorted.
Start the SETUV command, and pick the tube surface when you are prompted to select objects. This time, click the Adjust Coordinates button in the Mapping dialog box to bring up the Adjust Cylindrical Projection dialog box. If the axis of our tube was not pointed in the z direction, we would use this dialog box to make some changes, but we are just passing through and don't need to change anything. Therefore, click the Adjust Bitmap button to move to a dialog box named Adjust Object Bitmap Placement.
This dialog box looks like and performs the same functions as the Adjust Material Bitmap Placement dialog box you used earlier. Their difference is that one controls the global parameters of a material while the other controls bitmap image parameters for specific objects. Set the bitmap Scale in the u direction to a value of 6.0 and the Scale in the v direction to 2.0. This action will cause the image to be repeated six times around the tube and two times along its length. Also, set the Offset in the v direction to a value of 0.25. Since AutoCAD starts the bitmap in the middle of the tube's length, this offset in the v direction will prevent the image from being clipped at the ends of the tube. Click three consecutive OK buttons to exit the SETUV command. Your rendered tube should look like the one in the lower left corner of Figure 4.
So far, all of our materials have used tiled images-the image is sized or repeated as often as necessary to fill the entire surface. For our last rendering, we will crop the image so that it only appears once on the tube. Start the SETUV command, pick the tube, click the Adjust Coordinates button and click the Adjust Bitmap button to reach the Adjust Material Bitmap Placement dialog box. Do not change the u and v scale, but return the v offset to zero, so that the bitmap will be centered along the length of the tube. Then, click the Crop radio button located on the right side of the dialog box and click three consecutive OK buttons to leave the SETUV command.
Your last rendering should be similar to the one in the lower right corner of Figure 4. The bitmap image looks as if it is a label on a can. Autodesk sometimes refers to cropped images as the "decal" effect. The rest of the surfaces are rendered in their object color, which (in this case) is white.
Although we have looked at just a fraction of what AutoCAD's R14 renderer can do with bitmap images, we will explore more of its capabilities in the future.
Running AutoCAD? Test Your Hardware! Designed to test and compare the performance of systems running AutoCAD, Cadalyst's Benchmark Test is a popular and long-time favorite.