4. Materials
In order to advance our model past a single block colour, we need to be able to apply materials on to its surfaces. But to apply materials, we first need a UV map.
What is a UV map?
If you think of what an image is, it is a square that has an X
and Y
axis. For example, an image with the dimensions 512x256
, has an X
axis going from 0 - 512
, and a Y
axis going from 0 - 256
. UV
coordinates are much the same, but they instead always go from 0 - 1
, so they can be thought of as a percentage. As images exist on a 2d plane, we need to a way to convert our 3d models to 2d. If we were to take a cube and try to lay it out flat, we could do something like this:
This process is called unwrapping
, and the final 2d shape is our UV map. Now we can apply a material on top and the computer will be able to figure out how to apply it back onto the 3d model.
Creating a UV map
Waveform will automatically create UV maps for us, all we need to do is specify the seams (where to cut the model). To begin, let's open the materials
tutorial project. We'll want to change the 3d View
view settings to show a textured model. From left to right on the toolbar:
- Switch the view to
Textured
. - Select the
Cube
pattern from theFocus
menu. - Select the
CubeUV
layout from theUV
menu. - Select
Show UV Seams
from theShow...
menu.
You should see the following:
Notice the red lines on the cube, these are the seams it has been split at. You can switch to the UV Map
view to see the generated UV
. Let's now click on the CubeUV
item to see how the UV layout is specified.
Note new UV layouts can be created by selecting
[+] -> New UV Layout
in the workspace explorer.
The CubeUV
uses the default layout for tutorial purposes:
This is the header, and specifies the name of the layout.
Here we specify the pattern to actually attach this material to. By specifying the Cube
, Waveform will add this pattern to the UV map. There is also the ranges
field which is left blank. This is an advanced field which can be used to select a range of islands from the result, which can be used to generate more compact UV maps. Examples of usage can be found in the samples.
By default all materials start with the Checker Board
. This can be useful to see if stretching is going on. There is also the Plain
texture, which can be used in conjuction with a tint, to apply different plain colours to the model. To add your own textures, just drop a .png
file into the Textures
folder, which is inside the project root folder. Any new files will be picked up and shown as an option in the dropdown.
This colour is applied on top of the texture.
This can be thought of as how reflective the material is. A black colour specifies no shininess, and white specifies full shininess.
This is the light that pours out of the material. Useful for glowing objects like computer screens.
This control the size of the texture that is applied. A default scale is given that does nothing. Try increasing or decreasing the number to see what the effect is.
This controls the size of the texture on the UV map. By default, Waveform tries to give each pattern a fair amount of space by using the volume of the mesh. Use this transform to increase it's relative size on the UV.
UV Seams
Seams are un-avoidable, but we can make the result look better by hiding the seams below the model, or placing them at more natural locations (for example, with clothing there are often visible attachment lines on the fabric where the arms meet the body).
Select the Cylinder
item, as well as the Cylinder UV
item, and turn off culling in the Enable
menu so you can see the inside. Also make sure UV Seams
are being shown:
Open the extrude surface for the Cylinder and click on the top left point. Here you can see it has been given a UV seam with the name a
. Try giving the other points seam names, to see the seams that get generated on the model. Also if you switch to the UV Map
view, you can see two unwraps have been done for the single pattern, as it has been split in half by the seams.
You can also see the separate UV meshes, by clicking on the UV meshes option in the
Vis
menu, and using the+/-
keys to navigate between them. This is covered in more detail in the Visualisation tutorial.
This is the most basic way to do UV seams; by specifying a point as a seam on the surface, a full seam is produced as the surface is extruded along the position curve. But what if we wanted more control to say, split the cylinder down the middle? Open the the Position
curve and add a point in the middle of it by double-clicking. With the point selected you will see there is a UV ranges
box - this is capable of joining up points on the surface itself. Try putting a-a
in the box to see the Cylinder get a seam down the middle.
You'll notice there is also a UV Enabled
checkbox too which is ticked by default. Unticking it will disable all seams from the previous point to this point, as well as the seams from this point to the next point. You can disable seams on half of the cylinder by unticking this option at either end point of the position curve.
The Cube
If you view the Cube
pattern you'll find it uses all three of the tools mentioned above (seams, ranges and disabling) to achieve it's unwrap.
UV Packing
Generally we want the UV map to have as little whitespace as possible, so that our textures have more room to work with and the model ends up looking more detailed. By default Waveform will simply list all the textures on the UV in a single row. We can have some control over this by specifying that it should start a new row. Open the MultiLayerUV
item to see how it does this.
Composition
Layouts can be composed together as well, and you will find the samples make use of multiple UV layouts in order to do stacking
. This is a way to fit more islands into a row. You can for example create a layout with several rows of smaller islands, which then gets appended next to a large item on the main UV layout. This can lead to tighter packing, while still being simple to reason about. The HornedLanternFish
sample uses this for example:
If the same pattern is repeatedly used in a composition, it will still only be added once to the UV and the texture coordinates shared. For example in the above UV, the fin
and eye
are only added once, despite being used more than once on the final model. The tooth
is also added less than it is used, but more than once as the model has some size variations. If you want to edit a specific pattern, you can use the UV ranges
textbox to do so.