Last Sunday, I sat down with game-developer friend of mine for a cuppa Joe. Up until then, I hadn’t realized how expensive (in terms of system resources) draw-calls can be. Sure, I’d rendered, modeled and done god-knows-what-else with 3D models, but I’d never thought what it would be like in a restricted environment, say, a normal PC with consumer-level parts. Heck, I didn’t even use back-face culling! So that evening, I learned a lot about little optimizations that can go a long way on consumer hardware, so I thought I’d write a buncha posts –aimed at indie/startup/beginner game developers- on how exactly you can increase performance on little computers.
Our point-of-interest today is, materials. Or more precisely, why you should use less of those. For those of you who haven’t the foggiest what draw-calls are; think of them as tiny instructions sent to the GPU (politely) asking it to do something (stop whining! I know very well what draw-calls are. I’m just dumbin’ it down for the novices). Thing is, the more materials you have per scene, the more draw-calls are needed to render said scene. This might not be a problem on a beefy workstation with a coupla’ A-list GPUs at your disposal, but on a teensy little SOC, it can be the difference between enjoyable and non-playable!
That said, let’s move on to the “how” of reducing draw-calls. There are two ways. One of which; is reducing the number of materials by hand (i.e. using one black material for all black-ish materials). The other, although painstaking, is quite rewarding in terms of quality and performance; it involves converting materials to textures and using just one material for that one texture. Most AAA games (like the Forza series and the NFS franchise) use this method quite a lot. Interested? Let’s begin!
Before we start, a note on what can, and cannot be converted: you’ll need a model with pure materials (AKA non-texture pure color). If you’re unsure what this means, checkout these models:
Nissan GT-R Nismo – Sketchfab
Tesla Model S – Sketchfab
Tesla Roadster – Sketchfab
I’ll use that gorgeous Tesla Roadster for the purpose of this tutorial. You can purchase it and follow-along, if you like.
Since this is an anybody-can-do-thing, we’ll be using Blender. If you would rather use 3ds MAX or Maya, you’re welcome to try.
Open Blender and load the model.
Make a note of what meshes are already texture mapped (you know, tire treads, leather textures… that kinda stuff?), and move them to another layer. If a mesh has more than one materials, separate the mesh by going into edit mode (TAB) and pressing “P”, and selecting Separate by materials.
Now comes the hard part: go through the materials and decide which need to be matte/glossy/metallic etc. Then move the specific meshes (matte/gloss etc.) to different layers. You don’t have to do this, but this’ll make your life a lot easier.
Then, make a color map of all the materials in one texture file, like this:
Now you’re all set to turn material mayhem into a texture tantrum! Select a mesh and go into edit mode and open the UV editor (Shift + (Fn) +F10).
Click Open and select your color map.
Select all the vertices (A), and press “U”. In UV Mapping menu, select “Unwrap”.
Now select all vertices within the UV editor (A) and scale it down (S) to fit inside the designated color strip.
That’s it! Now all you need to do is UV map all the rest of the meshes onto that color map. See? Simple! Don’t worry about overlapping issues ‘cause they won’t be a problem.
Once you’re done, create a new material and assign the color map to that material. Then apply that material to all those meshes you unwrapped. In the end, it should look like this (The lack of, ah… objects is ‘cause I was too lazy to convert all the meshes!):
Now enable texture shading and see your hard work in action!
Well, most of it, anyhow. You still have to configure the materials properly (‘cause right now, that caliper looks a bit too shiny). Since this is not an exhaustive guide, I’ll leave PBR material configurations up to you. See ya’ll next time in “Symmetrical Duplicate-Rendering”.
Not so fast! Remember how I told you split the model depending on how the material should look like? Once you’re done UV mapping your model, and you’ve imported it into Unity or Unreal (or whatever engine you use!), make a few materials (preferably just 3: metallic, rough, non-metallic shiny. But you can do whatever!) , and apply those materials to your model (I know this sounds rather mediocre, but most folk tend to use materials embedded in the model itself, and then complain about how dull their art looks!).
Remember to untick “Import Materials” when importing the model, else all that work would’ve been for nothing!