Search

How to Skin a Cow: Modeling and Materials (Part II)

Updated: Aug 22, 2019

As I mentioned last time, the second big problem with creating a game entirely out of Unity's default primitive assets is one of materials. While Unity has a ton of great shaders and customization options built-in, you can still only apply them to your whole object at once in an all-or-nothing approach. For anything more complicated, we're back to importing models from elsewhere...not because the geometry needs to be any more complicated, but because of the UVs.


The process of UVing an object involves "unwrapping" the model into one surface, a single, 2D image. I'm sure you've seen this picture of an unwrapped cube:

Shamelessly stolen from Google

Each of the six surfaces is now laid out flat in 2D space, so you can apply your custom texture to it (by taking the image template into Photoshop or your other program of choice). The letters U and V don't really stand for anything, they're just used to denote the coordinate-like dimensions of your image, like X, Y, and Z in 3D space. But in terms of vocabulary, there is a difference between a material and a texture. A texture is literally just a 2D image like the one I'm talking about creating here. A material has a texture property which it combines with a whole lot of other things (like what shader it uses, shininess, transparency, and emission values, and more).


The thing about UVing is that pressing the "Unwrap" button in Maya or blender actually changes the physical geometry of the shape. A cube is pretty simple, but there are multiple different ways to unwrap a sphere or any more complicated shape, and the one you choose will result in a different 2D image and a different, unseen modification to your geometry. See where I'm going with this? With no way to know what unwrapping technique Unity uses on its primitives, there's no way to design accurate textures for them, and especially once you start stretch-scaling them like I needed to do. So, back to blender just to create the same geometry as I had in Unity.


The unwrapping method I chose for my cow body resulted in UVs that look like this. Other options would have provided less "seams", or breaks in the pattern, but typically the less seams, the more stretching and skewing as the algorithm tries to flatten out the rest. This one provided a pretty good compromise.

I took this guy into Photoshop and added a bunch of random blobs to create the below image. In the version I saved-out for my game, I hid the lines of the UV pattern, but here you can see how the spots correlate.


Finally, I took my new texture into Unity and created a Cow_Body_Material from it. Remember, I also had to export the geometry from blender that these UVs were created from, because a normal Unity sphere, even one of the exact same dimensions, wouldn't have the same UVs so the pattern would get messed up. I found some cool outline shaders to play around with, and even changed the material's tint color to create some chocolate cows and other variations. I used a similar process to create the light decals for the rings of my UFO.


The last thing I want to mention is that you can layer materials onto your objects, as long as you put them on in the right order and set their render queue settings correctly. For someone like me, that just meant a lot of trial and error, but in the end it resulted in some additional cool effects like both a metallic sheen and an outline for my cow helmets, or being able to change the UFO's ring and light colors independently. My game is still very visually simple when compared to many, but I needed to include blender into my workflow because of how fundamental UVing really is.


Next time: splitscreen cameras!