Gingerbread – Materials & UVs (#2)

Spread the love

In part II of “Make a simple animated Gingerbread character” the mesh is textured with the image previously used as the Scene’s background. This essentially involves the creation and assignment of a “Material”, to which the image is linked before then being applied over the models surface once its been marked up for, and UV unwrapped.

Materials & UV unwrapping

Once the mesh has been made its ready for the next step; the application of material(s) and UV map(s). What these components do when applied is lend objects the appearance of being made from something, typically through the use of one or more bitmap images assigned to its surface(s), like baked ginger biscuit for example. Whilst the process can be much more complex reduced to it’s core ‘materials’ provide the ‘what‘, UV maps the ‘where‘ (or ‘how‘).

Design note: as with modelling the process of applying materials, UV maps and getting them to display correct is in principle quite straightforward, the complication tends to come from making sure everything appears as, and where, it should, especially when applied to a relatively low resolution mesh with little structure available hide or obfuscate problematic areas.

What are Materials

As briefly mentioned above materials give objects the appearance of being made from a particular substance – brick, wood, glass etc. They can be relatively simple, or complex, with different levels of surface reflection, shininess, bumpiness and so on, all of which aid the illusion presented to the Viewer.

Design note: although outside the remit of this tutorial it should be noted that discussion of “Materials” in this context generally refers to Blenders default “Blender Render” system and standard “Multitexture” properties, or optionally “Blender Game” and “GLSL“; “Blender Cycles” render mode and “Node” base materials and system operate in a different way and are not expressly applicable to game content creation processes outside the Blender environment.

Materials generally comprise three distinct ‘slots’ or ‘stages’; a “Material” slot, providing a means to assign basic surface characteristics to the mesh; a “Texture” slot, allows for difference supplemental effects and images to be referenced; and an “Image” slot, catering to the assignment of difference images or pictorial type reference(s). In practice what this means for the Gingerbread character is that the single “Material” assigned will have an underlying uniform ‘ginger’ colour, a “Texture” slot occupied by a single bitmap, which is in turn referenced as an “Image” slot property. In other words the Materials hierarchical structure in principle looks similar to the following;

Assigned material
» Material slot (colour)
» » Texture slot (type)
» » » Image slot (bitmap)

Design note: the word “Material” as used refers to all three stages collated together as a single (unique) grouping, and the individual ‘material’ slot within. Because of this, the distinction between the two can sometimes seem confusing where further clarification is not available or slightly ambiguous.

When starting a new project however, the default Cube object from which the Gingerbread character was built, had a Material pre-assigned that contained both a Material and Texture slot; the former included some basic surface attributes, a light-grey diffuse colour, a ‘flat’ specular level etc., which lends the object its current ‘matt’ appearance; whilst the latter includes a series of properties that will eventually affect the bitmap to be assigned.

Design note: the muted colour serves as a uniform ‘null’ surface tone that mitigates reflective or shiny surface ‘flashing’ that can occur when working, which can be problematic for Users with PSE (Photo-Sensitive Epilepsy).

Default Material give surfaces light-grey colouration

Default Material assignment showing the basic properties therein contained, essentially a light-grey surface colouration with low specular highlights lending the mesh a reasonably flat-matt appearance

Without Material assigned mesh is darker-grey colour

When no Material is assigned the mesh appears a slightly darker-grey but still flat-matt – reflections and other surface affectations can ‘flash’ and be problematic for some Users over time, especially those subject to PSE and other issues of photo-sensitivity [“material.blend“]

Assigning a Material to the mesh

If the Gingerbread character was made using the start-up files default Cube, as mentioned above it already has a basic Material pre-assigned (in which case skip ahead to bitmap assignment). If not “RMB” select the object and to the right side of Blender, the “Properties” section, click the button illustrated with the a sphere to access the “Material” panel. Here a small aperture window is displayed near the top with a button below titled “New“. Click it to load into the Material slot an initial set of options. The mesh will change colour slightly to a lighter grey colour in confirmation. Leave these new properties as is for now.

Design note: if the mesh has no Material assigned, when the initial data is generated after click the “New” button, Blender should automatically apply it to the model regardless of the active ‘mode’. In other words,for single Material assignments it’s not absolutely necessary to be in “Object Mode” for application (this may varydepending upon the version of Blender used however) as materials can be assigned in both Object and Edit modes.

Next, to access “Texture” Properties click the button displaying the red-grey grid (to the right of the previously clicked “Material” button). Another panel appears with a similarly empty windowed area. Again beneath that click the button marked “New” to add another set of basic values and options pertaining to the newly created slot.

Design note: in instances where a mesh doesn’t have a Material and the addition of “Texture” properties here is part of the process to create one, at this point it will match what would have been the Material assigned to the default Scene Cube, i.e. the new Material will have the same ‘material’ and basic ‘texture’ slot properties as would be attributed to the default instance assigned to the cube.

Although not absolutely necessarily it’s often helpful to ‘colour’ the mesh as a means to aid production, in this instance it can be changed to ‘ginger’ by altering the “Diffuse” property of the Material slot. If not already in “Material” Properties, click the “Material” button and scroll down to the “Diffuse” subsection (directly below the preview window) and click the tinted sample box (rectangular shape currently tinted a light-grey). A pop-up will appear showing a number of options pertaining to colour. This is the “Color Picker” or “Color Chooser“. To set a colour left-click drag the small dot inside the colour-wheel to alter RGB saturation levels (0% to 100% of a given ‘red’, ‘green’ or ‘blue’ colour); slide the tonal level on the right to darken or lighten the selection; or in the “R:“, “G:” and “B:” input fields below left-click each in turn and type “0.800“, “0.187” and “0.032” respectively (“R: 0.800“, “G: 0.187” and “B: 0.032“). Press “Enter” or “LMB” click elsewhere to confirm. The mesh will update to display the new “Diffuse” colour, ‘ginger’.

Design note: the advantage of using the Color Pickers input fields is ‘replication’; if the diffuse colour from one Material needs to be copied to another, and nothing else, the values can be entered for the exact same colour to be achieved.

Changing 'Diffuse' material property to 'ginger' (colour)

Setting the Materials “Diffuse” colour to ‘ginger’ using the “Color Picker” and its “R:“, “G:” and “B:” input fields respectively [“material_diffuse.blend“]

Whilst changing the Materials “Diffuse” colour is optional, it having a “Texture” and “Image” slot is often not because the latter at least is often required for proper export when making content for games. As the basic properties for the “Texture” slot were created previously, all that remains is to inform the overall Material what type of Image the Texture slot is supposed to be referencing; in this instance a ‘bitmap’, the image previously loaded into Blender as the background for the 3D View.

Design note: the way Blender works allows it to use the same ‘root’ data, or “dataBlocks“, for different reasons, the bitmap image previously loaded can be used for the background of the 3D View and within the Material as its “Image” slot. This obviously saves Blender having to resort to unnecessary data replication.

Click the “Texture” button to access the appropriate properties panel (if not already active). Before adding the bitmap a number of settings need to be changes so Blender knows what ‘type‘ of texture data it’s supposed to be using; directly below the preview window is a text input field (“Tex“), and under that is a drop-down menu currently displaying “None“. Click this and select “Image or Movie” from the list. The Texture Properties panel will update with a set of new options one of which is an “Image” subsection. Scroll down to this and, as the image to be used was loaded previously, click the small picture icon with a double-headed arrow to the left of “+ New“, the “Browse Image to be linked” button. A pop-up appears listing the background image, “LMB” click the entry to select. The pop-up will disappear and the preview window, previously black, will update to show the newly assigned bitmap, confirming the association and completing the basic Texture slot set-up. With the Material now completed it can be assigned to the mesh. For this a UV map is required.

Assigning the background image to 'Texture' properties

From “Texture” properties, once the correct texture ‘type’ has been set – “Image or Movie“, the bitmap previously loaded can be selected and assigned from “Image” properties

'Image' properties showing assigned bitmap path

Once assigned the Preview window will update to display the image, confirming the association between bitmap, “Image” and “Texture” slot properties in the process [“material_bitmap.blend“]

What are UV’s, maps & UV unwrapping

UVW’s (usually just referred to simply as “UV’s” – see note below) are essentially points on a two-dimensional plane (flat surface) that correspond to the XYZ coordinates of similarly located mesh vertices (they represent the same points in space). If, for example, the top-right vertex of a box has an XYZ of “0,0,1“, its UVW ‘twin’ will similarly reference that point in a way that no matter where that particular UVW is placed on a bitmap during the ‘mapping’ process, those areas will be displayed on the mesh at “0,0,1“.

Design note: ‘mapping’ or ‘unwrapping’ generally refers to the process of generating a ‘map’, the latter essentially being the sum of the part – a collection of individual UV vertex coordinates each representing a corresponding vertex of the mesh.

Another way to think about it would be to imagine a box split down the sides and laid flat on a piece of wrapping paper. In this state each corner represents an individual coordinate, a fixed point on a flat plane (the sheet of paper), that collected together results in an overall ‘map’ of the box that can then be used as a template to cut a shape from the paper. When the box is reconstructed to form a thee-dimensional object again, the paper cut using the ‘map’ will neatly ‘wrap’ around the box. So, a “UV” is an individual coordinate, a collection of “UV’s” is a “UV map“, and the process of assigning said “UV map” to an object is “UV unwrapping” or “UV mapping“.

Design note: the “W” coordinate aspect of “UVW” usually relates to ‘depth’ where each of the “U”, “V” and “W” represents a coordinate on an axis of orientation (‘front/back’, ‘side/side’ and ‘up/down’). It, “W”, is rarely used in game content creation because objects are largely textured using two-dimensional bitmaps (flat planes) wrapped around a mesh – generally speaking the only time “W” comes in to play is for procedural texture generation where an assigned ‘material’ might require ‘substance’ – a wood texture assigned to a mesh with a section removed will show a ‘true-to-life’ inner continuation of wood grain for example, something not ordinarily possible with 2D, UV, texture assignments/mapping.

UV unwrapping a mesh

UV maps then are essentially two-dimensional representations of three-dimensional objects. They’re not quite just flattened or squashed versions of a model though, they tend instead to result from meshes being split in ways that facilitate the necessary break-down required for an object to be properly mapped (flat). This is done not by physically breaking the mesh apart, rather it’s done through the use of a special edge property, a “Seam“, that does this virtually. In other words the object can remain whole whilst the UV layer can be broken, guided by the presence of Seams marked on the mesh. Once the mesh is mapped an image can be assigned and edited using the “UV/Image Editor“. All this is done manually because the structure of the UV map is similarly determined by the structure and appearance of the object (and where Seams are placed). The first thing to do then is generate a “UV Map“.

Design note: the default cube present in the start-up file usually doesn’t have any “UV” data assigned, but this may vary depending upon the version of Blender used (this can be seen under “UV Maps” in “Object Data” Properties). Further, objects added to the Scene similarly shouldn’t contain “UV” data but again this may vary depending the type of object and/or Blender version used.

Before generating the initial “UV map” switch the upper-right window from the “Outliner” currently on display to the “UV/Image Editor” by clicking the “Editor Type” button to the extreme-left of the Header, selecting “UV/Image Editor” from the list. The window will change to show an empty grid, the editors “Texture Space“, surrounded by a workspace where the UV map and image will appear once defined and assigned, and where most of the general UV editing process occurs.

Design note: the “Outliner” is usually sufficient for most of the initial generation and editing work that needs to be done but the window itself can be enlarged where needed using “Ctrl+Up/Down” to toggle the window full screen (ensure mouse cursor is over the view), or by adjusting border dividers – move the mouse over a border until a double-header arrow appears, “LMB+drag” left/right, up/down, depending on the border orientation, to alter its relationship to, and increase or decrease the size of, windows, panels and/or views the respective border/s define.

To generate an initial “UV Map” then, in “Edit Mode” (“Tab“) make sure the entire mesh is selected (“A“), then from the Header menu select “Mesh » UV Unwrap… » Unwrap“, or alternatively press “U” to access the “UV Mapping” menu, selecting “Unwrap” from the list of similar options. Immediately upon doing this the UV/Image Editor will update to display an orange square with a diagonal line bisection (usually bottom-left to top-right). This is the initial “UV Map” which occupies the entire “Texture Space” area because each face is mapped to it on a one-to-one basis. This will change as the UV’s are edited.

Design note: unwrapping UV’s is a selection based process, only the surfaces selected are processed, it’s important to make sure that, if a map is to be applied to the entirety of an object, the entire surface is selected; using “A” to do this might require pressing the shortcut key twice (alternatively “Select » (De)Select All” from the Header menu)once to DEselect, or clear, any previous or active selections, then once again to REselect all.

Generating UV map

Mesh objects don’t contain any “UV” data by default so they have to be generated manually -the initial result is usually an amorphous ‘square’ and nondescript (has no bearing on the object) because the mesh has not yet to been appropriately marked with “Seams” to split the UV’s so they flattens out and better represents the object being mapped [“unmapped_initial.blend“]

As discussed above, for the UV map to make sense relative to the object it’s needs to be treated so it can unwrap properly. This is done using the “Mark Seam” property and assigning it to strategic edges around the mesh; wherever it appears UV’s are split causing the map to break apart, relax and flatten out as either a single shape or several “Islands” that are easier to manipulate and shape as needed.

Design note: where an overallUV map contains a number of ‘segments’, each self-contained area is a “UV Island“. For general UV map editing care should be taken to keep the number of such segments to a minimum, largely to avoid issues of resolution (issues due to there not beingenough texturemapped to a given area resulting in pixelation) and over-complicating UV map management.

To assign the “Mark Seam” property then, whilst still in Edit Mode, click the “Edge Select” button in the 3D View Header, or alternatively use “Ctrl+Tab” to access the “Mesh Select Mode” menu, selecting “Edge“. Then using “Shift+RMB” select all the edges around the back-side perimeter of mesh, making sure not to leave any gaps. Once done from the Header click “Mesh » Edges » Mark Seam“, or press “Ctrl+E” to access the “Edges” pop-up menu, selecting “Mark Seam” from the options available. The highlighted elements will change slightly indicating the properties assignment.

Design note: because Blenders default selection colour is orange and edges marked with the seam property are also orange, it can be difficult to determine if the property has been assigned. To double-check simply press “A” to deselect everything, leaving marked edges clearly visible. Adjust, reassign as needed.

Marking the mesh with 'Seams' to split UV's

Shown in “Wireframe” for clarity (click the “Viewport Shading” button and select “Wireframe“), the highlighted edges around the perimeter of the character are assigned the “Mark Seam” property which forces Blender to break the UV Map and treat the ‘front’ and ‘back’ of the mesh as distinct areas [“unmapped_seams.blend“]

Once Seams have been marked the UV map can be rebuilt. From the 3D View Header menu again select “Mesh » UV Unwrap… » Unwrap” or press “U” then select “Unwrap” from the pop-up. The UV’s will be recalculated to better resembling the Gingerbread character, which can then be given context and meaning having the previously set-up image assigned to it. To do this, in the “UV/Image Editor” Header click the ‘picture’ icon to the left of the button marked “+ New” – “Browse Image to be linked” appears on mouse-over. A drop-down menu will appear listing the image previously assigned to Material and used as the Scenes background, “LMB” to select it. Upon doing so the UV/Image Editor will update to show the image inside the “Texture Space” area, albeit off-kilter, confirming assignment.

Design note: the UV/Image Editor grid defines two aspects of the way images are mapped to UV’s; 1) “Texture Space” – the active area within which an image appears, the height/width of an image in pixels; and 2) “Texture Bounds” – the border at which point “Texture Space” repeats (tiles) usually defined as 0,0, 1,0, 1,1, 0,1 (bottom left, top-left, top-right, bottom-right corners). Basically what this means is that UV coordinates associated with “Texture Space“, i.e. the position of a given UV vertex within the bounds of the texture, are used largely to position a mapped image across a mesh. Whereas the latter, those associated with “Texture Bounds“, are typically just a boundary reference after which UV’s outside the area ’tile’ (repeat) the image.

UV map split into two 'Islands' due to 'Seams'

Mesh shown in “Wireframe” for clarity, rebuilding the UV Map after marking Seams around the back-side edge of the mesh to separate ‘front’ from ‘back’ and into two ‘Islands’ – the map now resembles the object (note the editor view has been enlarged slightly by moving the border between it and the 3D View in and the Properties panel border down) [“unmapped_2nd_pass.blend“]

In spite of this, it’s likely the change won’t be visible on the mesh because the Scene, and objects contained within, are not being displayed properly being in “Wireframe” or “Solid” display mode. To remedy this press “Alt+Z” to switch into “Texture” mode, or click the “Viewport Shading” (“Display Mode“) button in the 3D View’s Header and select “Texture” from the list. The Scene will update to show the bitmap applied to the mesh.

Design note: the “Display Mode” button is the same one used previously to switch from “Solid” to “Wireframe” mode, and currently displays a white sphere (for “Solid” mode”) or a sphere outlined with black lines (representing “Wireframe”).

However, because “Texture” mode is a ‘real time’ display mode, the “Lamp” object in the Scene will be adversely effecting the object, shading it in a way that makes it difficult to see what’s going on. To solve this, press “Tab” to exit Edit Mode (if still active), zoom out of the Scene a little, “RMB” select the Lamp object, then do one of the following; 1) press “Delete” to remove it complete, or 2) press “M” (or from the Header menu click “Object » Move to Layer…“) to access the “Move to Layer” pop-up menu and click one of the small boxes. The Lamp will disappear from the current ‘layer’ to the one selected. In either instance the Scene lighting will update making the mesh, and assigned image, easier to see.

Design note: the “Lamp“, being an independent “Object“, cannot be selected whilst another ‘mode’ is active, i.e. whilst modifying the mesh in Edit Mode; ‘objects’ can only be selected in “Object Mode”.

Assigning background image to UV map in 'UV/Image Editor'

To actually ‘map’ the UV’s to something an image needs to be assigned, the previously used background image -using the “UV/Image Editor” click the “Browse Image to be linked” button (picture icon) and select it from the list (note additionally the removal of the default “Lamp” which adversely shades the mesh, making it difficult to see what’s going on – press “M” to move it to another ‘layer’ or “Delete” to remove it completely) [“unmapped_image_assigned.blend“]

Once the basic UV Map has been generated it can then be tweaked and modified in the UV/Image Editor so the’front’ and ‘back’ UV islands sit over their respective image sections. This is done largely though the use of the same/similar (with one or two additions) selection,manipulation (“Transform“) and editing tools as used previously to make the Gingerbread character.

Design note: it’s largely impractical to perform any significant editing in the small window that is the UV/Image Editor as it currently stands so either; 1) with the mouse over that view press “Ctrl+Up” toggling the view full-screen (“Ctrl+Down” to toggle back, although either/or combination used twice in succession will toggle in and out of full screen). 2) use select “UV Editing“, one of Blenders default “Screen Layout” options in the main application Header menu (top of the application). 3) or readjust the borders between windows to expand them as desired.

To select an entire UV section for example, use “Border Select“, “B” or click “Select » Border Select” from the UV/Image Editor Header menu, to draw a box selection across an area, or click the “Island” button in the menu Header to set the “UV display and selection” option so individual sections can be “RMB” single-click selected. Then move (“G“), rotate (“R“) or scale (“S“) the Islands to fit their respective area of the mapped texture (“LMB” to confirm after each manipulation, “A” to clear selections). Once done change to “Vertex” or “Face” select mode (see note below) then select and move individual selections or small groups or vertices so the overall UV Islands fits within their respective image section confines, ‘front’ and ‘back’. The end result should have both sections sitting reasonably comfortably with the space allotted them.

Design note: switching “UV selection and display mode:” can be done in the UV/Image Editor using the Header menu buttons or “Ctrl+Tab” to access the “UV Select Mode” menu where the same “Vertex“, “Edge“, “Face” and “Island” options are available. They are the main mechanism through which UV’s are selected and manipulated in addition to Blenders standard object and Scene manipulation tools and functions: “G“, “R” and “S” to “Translate” (move left/right, up/down), “Rotate” or “Scale“; “RMB” and “Shift+RMB” to make individual and multi-selections; and “Vertex“, “Edge“, “Face” and “Island” display and selection types. The UV/Image Editor is a 2D surface/work area so MMB rather than “Shift+MMB” strafes up/down, left/right, with “Ctrl+MMB” or “MMB+scroll up/down” zooming in/out.

It’s important to point out here that although the principle of UV mapping and editing is relatively simple, in practice getting everything where it supposed to be can be, and often is, extremely time consuming, fiddly, and nearly always requires minor alterations to the mesh, typically the placement of additional Seams, for example under the arms, either side of the neck and between the legs to split the UV’s so they relax and better fit/align to the image. Due to the nature of the process it’s not something that can be automated. Once done it’s then time to prepare and rig the mesh for animation.

Editing the UV map so it fits over the Gingerbread character image

Using Blenders standard, and some specific to the UV/Image Editor, manipulation tools, the rebuilt UV map is moved into place front and back and then manipulated in detail so the outer perimeter of the UV’s fit within the bounds of their respective image sections [“uvmapped_editing.blend“]

Final UV map shown in 'UV Editing' mode

For clarity and ease of editing the UV’s, either make the UV/Image Editor full-screen or, as shown above, switch to the “UV Editing” layout, one of Blender inbuilt “Screen Layout” options (menu Header running across the top) [“uvmapped.blend“]

Spread the love