Assigning Multiple Materials to SDS Objects

This example explains how to map materials to a subdivision object. Mapping is defined so that material patterns follow surface deformations (bending of skeletally controlled human figure, for example). You will also learn how to restrict each material to affect only desired parts of the surface.

Level: Medium/Advanced

Sample files: 'tutorprojects/material/sdsmaterial/torso' and 'tutorprojects/material/sdsmaterial/sdsmat'

First, model a simple human figure, like the upper body shape of the example image, which was created by extruding the head and two arms out from a 4*4*4 subdivision cube. Rename the figure as 'Torso'.

We will assign two materials, wood and brushed steel (both include color and bump patterns) to the torso. Therefore, we have to attach suitable mapping coordinates to the object (the patterns will follow the assigned coordinates). Both the wood and steel material are designed to work best with parallel mapped coordinates. Therefore, make sure that the torso is selected, go to the materials tab of the select window, drag and drop the wood material of the default material library into the view window. This creates a suitable parallel mapping. Ray trace the view and you will see a wooden figure.

Subdivision modeled torso

Go back to the geometric objects tab of the select window. Open the hierarchy of the created torso+wood level. You can now adjust the density of the wood pattern by selecting the parallel mapping object and by applying the usual Transformation/Scale tool. The smaller the mapping object, the denser the wooden pattern.

This kind of wood mapping works fine for rigid objects. However, the strictly geometric parallel mapping cannot follow arbitrary flexible deformations. For example, if the arm of the torso were now bent, the arm would move across wood patterns, which looks strange in animations. Therefore, we have to convert geometrically defined parallel coordinates to pointwise defined parallel coordinates.

To do this, select the torso object and the parallel mapping from the select window. Go to the Materials tab of the toolbar and click the Map2Obj tool icon. The tool controls display various options: Target=points and Source=Map coords should already be selected by default, but change Destination to Map coords. Then click the Accept button.

Map2Obj tool stores mapping coordinates to surface points

You may now delete the parallel mapping object from the scene. Then select the parent level of the torso. Click the Default mapping tool icon on the toolbar (it is included in the same Materials section of the toolbar as the Map2Obj tool explained above). Make sure that the tool controls display Wood as the selected material and change Mapping type to Null. Then click Accept.

It you render the scene, the wooden torso should look pretty much the same as before. However, now the mapping coordinates follow nicely with all kinds of deformations. We used Null mapping above, because the surface itself computes mapping coordinates from the stored pointwise information and the default mapping should not overwrite this by some other coordinates.

Defining the influence area of a material using 3D painting

The next task is to limit the area of the wooden surface to some sub area of the torso. For example, let's try to write the text 'Wood' to the chest of the torso with wooden letters, the rest being the usual default material.

For this purpose, we need another set of pointwise coordinates. A nice way to define the text area is to use 3D painting. This method requires two-dimensional coordinates, which run along the surface. We can define these coordinates using the Map2Obj tool with a cylinder mapping.

Therefore, select the parent level of the torso, take a top view and pick Cylinder mapping from the toolbar's Materials section. Click in the middle of the torso, and shape the cylinder around the torso. The diameter is not important, but the seam direction sometimes is, so click a second time behind the torso to finish the cylinder mapping. The used material is not important, because this is just a temporary step.

Take a front view. Select the created cylinder mapping, extend and move it so that it covers the torso in the height direction (use Transformation/Move and Transformation/Extend tools or object handles to do this).

Then select the torso and the cylinder mapping and activate the Map2Obj tool. Target=Points and Source=Map coords are again suitable, but set Destination to UV coords. Then click the Accept button. Now the torso has parallel mapped pointwise mapping coordinates and cylinder mapped pointwise UV coordinates. Delete the cylinder map object.

The cylinder map does not always unwrap the surface of a target mesh properly. For example, if the arms of the torso were bent, some surface areas might get badly folded over other areas in unwrapped UV space. If this happens, the UV editor can be used to fix problematic areas.

Cylinder mapping defines uv coordinates for surface points

You can find the UV editor from the Windows menu. By comparing point selection on a normal view window and on the UV editor, it is easy to figure out how the cylinder map unwrapped the surface. Note that points can be selected on the normal view and moved on the UV editor.

We will assign materials to the middle chest of the torso, which is a neatly unwrapped area, so UV point editing is not necessary this time. If the purpose was to paint the arms, then some editing would be necessary, because the arms cover a very small area of the UV space and 3D painting is therefore inaccurate there. In a worst case, only a couple of pixels of the used texture map might cover the arms.

Next we define the wooden area. Select the torso and activate the UVimage tool (it is located in the Materials tab of the toolbar). This tool is for creating and assigning a bitmap texture to an object. The activated tool displays several new controls. The X and Y fields display the resolution of the image to be created. Default x=128, y=128 is a somewhat low resolution, so change it to x=256, y=256. Type=Constant is suitable; this means that the image will be initialized to a given color. Set the constant color to black by typing 0 0 0 to the Color field or by using the color selector which opens by clicking the small sample color square. The next option, Attach should also be set, so that we will see the image wrapped on the object as a color texture. Finally, enter a suitable File name, for example 'woodmask'. Then press the Accept button.

Turn shaded OpenGL on if not yet selected (you can find this option for example, from the view compass). The created texture map makes the object appear totally black. Activate Airbrush tool from the toolbar's Materials tab. Pick a medium size brush from the airbrush controls (for example 4 units wide brush) and set pure white color 1,1,1,1 into the color field. Then take a suitable look at the chest of the torso and draw the letters 'Wood' over the body. The white text becomes visible on the chest. Then press Accept to finish using the tool.

3D painted mask image

Now the mask image for the wooden area is ready and we will convert it from a color texture map to another form. Make sure that the torso is the selected object and select Object properties from the view window's popup menu. Select Col tab from the property window and empty the Texture field displaying the name 'woodmask.bmp'. Close the property window.

Building the materials

The next step is to create some materials. We could use easy to use templates for this purpose, but let's practice using the Visual Shading language a bit and build the materials step by step.

Go to the select window, switch to the material tab and pick New/VSL material from the select window's popup menu. A blank material appears in the material library. Double click the icon of the new material to open the property window. When the property window appears, first change the name appearing at the top to 'woodmask'. Enable the Advanced option and also open the Available objects frame, in case it was closed.

The wood material defines both surface properties and some illumination properties. Therefore we need to define the same properties for the mask material controlling the strength of wood. Drag and drop the Shader object twice onto the top most Material level node of the VSL hierarchy. Then activate the lower shader and change the Type field from Surface properties to Surface illumination.

Drag&drop a Texture object from available objects onto the Surface properties node. Open the popup menu on top of the created texture node and set Output to Surface:Scope and Input0 to Surface:UV coords. The scope channel is a special channel that is used to control the effect of other channels. The selected input channel UV channel, is the same point assigned channel that we used to bind the wood pattern to the torso. Now we use the same channel to bind the mask pattern to the model. Define the texture name woodmask.bmp to the File gadget at the lowest part of the property window (use the browse button labeled as '...' if you are not sure about the file name or path). Then enable the Tile X and Tile Y options. The mask image is wrapped only once over the torso (one single tile), but the UV coordinates must usually run continuously over the seams of a cylindrical surface like the torso. Tiling improves the continuity.

Also activate the Gradient X and Gradient Y options. The airbrush tool already created smooth edges to the painted area, but the gradient option improves the quality even more, so that the wooden area becomes smoothly blended to the background.

Finally, select the texture object, then select Copy from the popup menu. Select the shader node Surface illumination and select Paste from the popup. The mask material is now ready and looks like in the adjacent image.

The material defining the influence of wood

Go to the select window and select New/Level material from the material tab's popup menu. Rename the new material as 'Wood+mask' using the property window. The property window displays the available materials on the upper area and the contents of the level material on the lower area. Drag and drop the Wood and Woodmask materials from the upper material list onto the 'Wood+mask' node on the lower area. The result is shown in the exampel image.

A level material consisting of two sub materials

Average mapping

The next step is mapping the 'wood+mask' material to the torso. Change the select window to show the object hierarchy. Select the Wood default map object. Select property window's Spec tab. The top most gadget, Material, displays the target material of the mapping. Change it from Wood to Wood+mask level material. Then activate the Average map tool from the right end of the toolbar's Materials section and click Accept. This creates a new hierarchy level containing the default map object.

The hierarchy of the average map

The new Average map level is actually a special mapping object that averages the effect of materials mapped by its child mapping objects. Each material has a weight defined by the scope channel. If only one material is applied, an averaging object is not necessary, but we will also add some steel areas and the average map object makes sure that steel and wood are treated similarly. The following sample equation shows the difference between using and not using the average map, in a point where both wood and steel have scope 0.5:

Average map: result = 0.5*wood + 0.5*steel

Direct mapping: result = 0.5*(0.5*wood+0.5*default) + 0.5*steel

Without Average map, the blending of a new material to the previous situation is repeated until all materials have been evaluated and therefore the first material will have a weaker effect than the last material.

Close the property window and save the project with a suitable name. This step is important because project saving stores the changes in the images, including airbrush painting to the woodmask.bmp. Render the view window. You should see wooden text on a white torso.

Masked wood area

Inserting more materials

Adding some steel areas happens exactly the same way. Before painting the steel areas, we have to protect the woodmask.bmp image temporarily, because 3D painting tools affect all bitmap textures hit by the brush. Therefore, select the Average map level object and open the object property window. Enable Invisible in photorealistic rendering option from the General tab. This makes the object in question inactive in all rendering actions, including 3D painting.

Next select the torso and use the UVimage tool to initialize a black bitmap called steelmask.bmp exactly the same way as woodmask.bmp above. Use white airbrush to paint the word 'Steel' to the torso. Note that the steel and wood texts may overlap without problems. When the steel mask is drawn and ready, go to property window's Col tab to remove the Texture field contents. The 'steelmask.bmp' was temporarily used as a color texture to see the painting on the surface, but from now on it will be used for masking the steel area. Use the color gadget to change the color of the torso to for example, darkish green, so that the mapped materials will be more clearly visible.

The easiest way to attach the masked steel material is to copy the already created wood items. Therefore, duplicate the material woodmask, rename the copy as steelmask and use the property window to examine its Advanced VSL hierarchy. Change the texture file name of the two texture VSL objects from woodmask.bmp to steelmask.bmp.

Create a new level material called 'steel+mask' and add the Brushsteel and steelmask materials into it (the same way as wood and woodmask above). Go to the object hierarchy tab of the select window and disable Invisible in photorealistic rendering property from the Average map level, so that the mapping starts working again in rendering. Make sure that the Average map level is selected and create a default mapping of type Null (see the beginning of this tutorial) referring to the new steel+mask material.

The tutorial project is now ready. Save it and render.

Blended materials