Local UV Texture

The body has now a procedurally defined color texture that covers the surface everywhere. This is a good starting point. However, details, which follow the geometry in a unique, irregular way - for example color bands around the mouth - can be hard to add procedurally. The easiest solution is to use a painted texture, which is wrapped onto the face of the character. We will do this next using so called UV Set object, which defines the texture only locally.

Start situation for this chapter: tutorprojects/harry/body_and_skin.r3d

Take a side view. Select the body mesh. In the screen shots below, we have turned off OpenGL shading of the skin textures. OpenGL visualization will not be accurate enough for estimating texture continuity. Also, when later pasting hair and animating the character, non-textured body renders much faster in OpenGL. To turn off the skin textures, open the property window, go to the Wire tab and set Texture quality to None.

Put the SDS mesh to the face edit mode. Activate all SDS faces at the face area of the body.

The tool control bar includes a tool called UV Set. It is at the right edge of the control bar, so you may have to Ctrl-RMB drag the control bar to find it. Click the tool. A new item 'SDS UV Set' appears to the hierarchy.

UV Set created

By default, this UV set object takes the UV coordinates from the parent SDS mesh. Those were defined using a parallel projection, which we adjusted for the reptile skin. Such UV coordinates are probably not suitable for mapping a texture image to the face.

To improve this, select the SDS UV Set and take a front view (=view against the UV set area), zoom the view so that the UV set fills the view area and click the From View tool (while SDS UV Set is selected) in the tool control bar. This tool uses the current view projection to define UV coordinates.

Open the UV editor from the pull down menu Windows/UV Editor. You can now see the defined UV mesh; hit the spacebar to set it to the edit mode. If the object is in face edit mode, choose Edit Points from the UV Editor's pop-up menu. Point edit vertices to adjust the result. For example, the mouth area may contain overlapping points - move them apart. The Unwrap UV tool can be helpful in fixing dense areas and folded surfaces. Close the UV editor when UV mesh is good enough.

We can 'bake' the existing color pattern to a texture map. This will make it easier to join the painted area to other skin. To initialize the texture, make sure that UV Set is still selected, go to the Materials tab of the tool bar and activate the UVImage tool. Set a suitable resolution to X and Y fields, for example 400*400 pixels. Change Type to Evaluate and change the file name to a more suitable form, such as 'facemap'. Hit Accept and wait until the evaluation is finished.

The tool adds a new material mapping under the UV Set object: Default Mapping(SDS UV Set Colormap)

In the material library, you can find the respective material, which textures the UV set area. Open the UV editor; you can see the created texture map as a background image. It may look grainy because of a low default resolution, but you can increase the quality by selecting the UV Set and by increasing the Texture quality value in the Wire tab of the property window. Then UV editor will display the background image accurately.

A test rendering shows that the edges of the new UV Set texture match the surrounding area quite well. However, the new texture mapping material does not include the same antialiasing mechanism as the procedural shaders created earlier in this tutorial. We can add antialiasing to the texture map object, too. Switch to the material library of the select window, select the new material 'SDS_UV_Set_Colormap', open the property window and check the advanced option. Select the Texture object from the shader tree and switch to the General tab. Set Antialiasing to a high value, for example 30, and the Threshold to 0.01. U and V samples can be for example 8. The higher the value, the better antialiasing you will get. 8*8 samples out of a 400*400 pixel image is a reasonable compromise between speed and quality.

You can test antialiasing factors by making a couple of test rendering cycles. Skin patterns should appear sharp when you view the object from a close distance and fade away when you move camera further away.

Both the procedural skin and the painted skin have now antialiasing enabled. This does not ensure continuity at the border, because mechanisms are quite different. Therefore, we will next set up a gradual fading of the texture map towards its boundary. We need a new channel for that purpose. Switch to the Channels tab of the select window and create a new channel using the popup menu New/Float Channel. Rename the channel as 'fweight' or something similarly descriptive - the channel is the weight for the face texture map.

Switch back to the geometry tab of the select window. Open both the UV editor and the property window. Go to the Spec tab of the property window. Select the UV Set and put it into point edit mode using 'Edit Points' popup menu of the UV Editor. Use for example the lasso selector (hotkey '4' + LMB drag) to select only the interior points of the UV Set.

On the property window, choose fweight to the Selected Points/Attribute field. UV Set has no values assigned to this channel, so the value field shows red conflict color. Type the value 1.0 and hit enter. Now the interior has full weight, but vertices at the UV Set boundary got a default channel value 0. You can verify this by activating one of the boundary points.

Close the UV editor. The UV Set is ready, so you can turn off its wireframe using the WF-Invisible button in the toolbar or the 'i' hotkey.

Switch to the material library of the select window. The last material, SDS UV Set Colormap, should be still active and in the Advanced edit state. To enhance visibility of the blending process, add a Constant object after the Texture object, set its value to e.g. medium red (0.5 0 0) and change General/Operation to +. In other words, we make the face area redder as other parts of the body. A test render shows now a very clear boundary between the materials.

In the VSL editor, drop a Copy object to the end of the Surface properties shader. Click the In/Out tab and set Source to Surface:fweight and Destination to Surface:Scope. The blending setup is now ready - test render to see that materials blend smoothly.

The Scope channel is the system channel, which defines how strongly a material affects the target. Scope 0 makes the material invisible and Scope 1 gives a full effect. In the configuration we created above, Scope values were taken from a vertex channel, which gives us is a simple and intuitive control.

Advanced users might wonder why we did not assign the scope channel directly to the UV Set vertices but used another fweight channel to carry the value. The reason is simply the order of material evaluation: the Default Map under the UV Set is evaluated last. Its default scope 1 would overwrite the scope values from UV Set vertices. Therefore we use another, private channel to carry the values to the required shading level.

Now you can finish the face texturing. Paint some details to the created texture map (realsoft3d/facemap in the example above) in your favorite paint software, or use the 3D painting tools of Realsoft 3D. Then save the project.