Tuesday, March 2, 2010

3D Digital Art 101

Today I'll go through the basic steps in creating a digital 3D image from a pre-made model using a program such as Poser or DAZ. You can, of course, create your own models, but if you're already doing that you don't need to read this. I'll be using the Anglo-Saxon Shield model from Merlin's Medieval Shields set (available at Renderosity), which I used in the recent illustration work I posted.

What you would be making, were you do make your own models, is a wire mesh geometry. This is the basis of all 3D objects, and consists of several, hundreds, or even tens of thousands of individual polygons, connected together to create vertices, the points in three-dimensional space at which they meet (a square, for example, consists of four vertices which, when connected, create a plane, while it takes only 8 vertices to create a cube, which consists of eight corners defining six planes). Both polygons and their associated vertices consist of mathematical data which can be defined in 3D space as a three digit number corresponding to their x-y-z position (width-height-depth) relative to a central 0-0-0 position. These data points can be prescribed and manipulated to define the shape any object (depending on your level of patience and proficiency, I imagine). Here you see the underlying geometry of the Anglo-Saxon shield model. This essentially looks much like a detailed line drawing at this stage. Or an image from a coloring book.

The simplest form of polygon is a single triangle, any number of which can be pieced together to form complex shapes with nearly smooth curvatures; the more polygons make up a shape, the smoother each angle will be between them. Each of these polygons contains a plane: the two-dimensional surface defined by their mathematical positions in space. Here those planes have been shaded to create a continuous surface as defined by the polygons. Those surfaces now cast shadows and catch highlights from light sources.

By default the planes defined by the polygon geometry are flat, as seen above. But among the many mathematical equations that define the 3D geometry is the sharpness of the angles between those planes. In the image above the angles are set at 100%, or exactly the sharpness defined by the degree of each angle. Here those angles have been smoothed by decreasing the sharpness of the angles, functionally rounding off each edge and corner. Were you to take a 3D cube and decrease the degree of each angle you could theoretically make a perfect sphere (although due to texture stretching on the surface it's better to model more angles into a curve, as we'll see shortly).

Of course, plain grey surfaces aren't all that interesting to look at. You could simply change the color data assigned to each plane or group of planes, to make them gold or silver, for example. But our object needs more detail to be realistic, so we'll want to add some "texture" to the surface. We can do this by either "painting" it with color data in a standard graphics application such Corel or Photoshop, or we can simply wrap it in a photographic image. Either way, we will need a flat surface to work with (although you can now paint on 3D surfaces in many applications). 

In order to do this, we can "unfold" the planes of the 3D geometry to lay flat, much like a cardboard box. This is easy enough for an object like the cube, but becomes vastly more difficult as the object becomes more organic and complex, such as a human face. You can simply tile a texture to cover every surface, or a group of surfaces, and that works fine for many objects whose textures are reasonably consistent, such as the forged metal rim of this shield, for which I'll use that technique in a bit. Fortunately there are programs such as UVMapper Pro (screenshot pictured at right) that can extract a two-dimensional map (called a UV map, or texture template) from the surface of even the most complex objects. There are freeware programs out there as well, but UVMapper is something of a universal standard, and it's worth it if you plan to use it often.
  
Once you have your UV map, you can either paint right on it any way you choose, or you can cut and paste and shade using actual photographic images, or a combination of both. Here's the basic texture set that comes with Merlin's Anglo-Saxon Shield, which has a nice wood grain and leather texture, but a fairly lame flat color for the metal surfaces, which we'll fix later. Essentially at this stage you just want to create a nice color map to lay over your geometry. Using nice high resolution images is key to getting really good detail, but remember that the bigger the image, the longer the render time will be, especially when you have a lot of objects in the final scene. This is one of the problems you'll find with cheaper models (and most game models), because they're UV maps are minuscule, so low resolution that they have no detail at all. This one is 2048 pixels square, a pretty good size image (with the practical upper range being around 4000x, which takes a lot more render time).

Here I've applied the basic texture to the model, using the default settings. Essentially at this point the color information has just been laid onto the surfaces planes, and so consequently looks pretty flat. The wood, for example, just looks like a picture of wood, which is exactly what it is. You may notice that the leather strap and handle are not on the UV map, and that's because the brown sections of the strap and handle have been mapped with sections of the leather shield cover (an efficient reuse of the same texture map), while the metal hardware portions are just given basic color data with no texture. This is done in the Materials Room of Poser, where we'll be spending quite a bit more time here in the next few steps. You can also see that there's a bit of shine (or specularity) on the metal, which is also added in the material room, but it doesn't look all that convincing.

I've been speaking of "texture" when referring to what is really surface color, and this is standard practice, though technically not correct. Because what actually creates your texture (aside from any built in to the model geometry), is either bump map or a displacement map (or both). Generally this is little more than a slightly manipulated grayscale version of your color texture map, but can be really anything you like. They don't have to correspond. For example, you can easily create a freakish Thing by applying a cracked lava texture to a human skin, or make ripples on the surface of a pond by applying a series of circular geometric patterns to an otherwise smooth and flat water surface. How this works is that where the color of the bump map is dark a corresponding depression is made in the actual surface of the 3D model, with the converse occurring for lighter hues: the darker the color, the deeper the indentation. The difference between bump and displacement maps is that the former only simulates the change with color shading while the latter actually displaces the geometry, which then catches actual light and shadow. The amount of this effect can be adjusted to achieve exactly the result you want. Of course, here we want our wood-grain texture to match the corresponding color data, so we use a de-saturated version of the color map, with the contrast kicked way up to accentuate the texture.


You can also create a variation of the bump map which is called a specularity map, and which provides light reflection data to the render engine. Here, instead of depth information, the relative lightness of the texture image tells the computer how bright or reflective that area of the surface is, giving more reflectivity to the lighter areas and less to the shadows. Related to this is a reflection map, which is not so much a map as these others are, but a gradiated color pattern or reflected image. The one to the right is just a landscape shot tinted gold, and can be used to add highlights to any reflective surface, such as a person's eyes or on a wine glass. This shows up more or less strongly in the final texture based on the specularity map. You can see how I employed it in the next and final step.

Here is my final rendered image with all the maps applied. You can see that there is now nice depth and roughness to the wood grain (more than any self-respecting Norse wood-crafter would leave, and far more than any Viking warrior would want have chafe his arm). The leather has a nice "tooth" to it, too, and the metal has a nice hand-beaten look. This is a custom touch, due to the fact that, as I said, I didn't care much for the default color and flat texture. To rectify that I've added a metal texture to the rim and boss sections of the bump map, using Photoshop, and at the last minute changed the color to a nice rich gold. In addition, the gold reflection map above was added to the Reflection box in the Materials Room, which gives that nice striation to the highlights on the boss, as if the nearby mountains were reflecting in the setting sun. This is likely stronger than you would want in a final product, especially if the shield were old and worn, but this one is freshly minted from the blacksmith's forge, and so it's still nice and shiny! You can add grunge and dust, and even displaced dents and sword strokes, using the methods described here.

So there you have it, a completed 3D image, complete with light and shadow. I've left the lighting at their default settings in this case, but as with every aspect of 3D model rendering, they are infinitely changeable. And this is just a very simple prop, one with no moving parts. Just wait until you see what you can do with a dragon!