How many materials ?
Hi there ! I'm trying to build a game that looks 2D but with property of 3d building (lights mostly). I tried a few things but the Sprite shader doesn't suit my purpose so instead I'm heading toward 3D shaders and stop using sprites in favour of quads with the drawing as its texture. I would use normal maps to emulate 3D rendering with the lights in the scene (I already achieved promising results), quads as the floor and walls with (again) drawings and normal maps as texture... So, my questsion is this : is there a number of materials that's too many ? Because in order to achieve the look I'm going for, I would need to create a material per object which in the end could be a great bunch. If adding a huge amount of different materials doesn't take much ressources then cool, if it's a drop in performance, I would like to know before I base my game around this...
I hope I've been clear enough, if not feel free to ask what I didn't explain right ! Thanks in advance !
Answer by UrielKane · Feb 25, 2018 at 08:34 AM
Hi. This depends on wich is your target platform, for example for desktop pc games you should kept the drawcall below 3.000 or as too much les than 4.000, more than thar will become in really bad performance even on a mid range gamer pc. For mobile i'm not to well informed since im working from the begining for a pc game project, but as far as i can tell you should try to stay below 1.000.
That being said, i have to point out that drawcalls are not equal to materials on screen. Most of the time one single material can being draw more than twice even, for example when doing the realtime shadow pass, or when using complex shaders like tessellation wich some times draw almost like five times if using realtime shadows and realtime reflections.
I can't tell you how many materials are too much or good. But as far as i can tell the best approach for what you are doing and supposing that you are developing for mobile or some kind of low performance device. You should go with atlases. Atlases are similar to sprite atlas, where you have several texture packed on one for performance. So for example a typical scenario is when you make a 3d model for a character or a house or a car, where you can have in the house case the textures for walls, roof, celling, doors, windows, details, even furniture props, all in one texture of 2k zise or more for quality.
So this way you can reduce draw calls drasticly, you can pass from 4.000 to 500 by using atlases. There are too diferent ways of approaching them, maybe you want all metalicnes materials to be in the same atlas to share same material properties, and generic ones on other. But this can be solved with PBR materials too, but to have PBR ready textures you need a material editor like bitmap2material or like that, to have metallicnes maps, ao maps, specular maps. That way you can use one materials for objects that behave diferent on shader level.
I'm not an expert on materials and shaders not even on textures, but this is the way i whould go for in your case. In fact any serious project should use at least a decent amount of atlases and well configured materials and shaders. If i where you i whould invest some time researching on those subject i mention.
Answer by Tritonmosquito · Feb 25, 2018 at 10:59 AM
Thank you very much for your detailed answer ! I will check out atlases, since if I understand correctly this could be very useful. The thing is with my game I kind of need to create a lot of materials, but each one wouldn't weight much since it would only contain an albedo of my drawing (the head of the character for example) and the corresponding normal map. Maybe with using atlases I could regroup all the materials of a character (head, body, legs, etc...) and reduce the drawcalls ?
I'm aiming for pc as the target platform but I'd like my game to run on low-middle budget pcs though. Thanks again ! I'll get more information on what you suggested !
That's correct. And that is for the atlas texture solution. Ins$$anonymous$$d of having diferent materials for diferent parts of the same object. The only cases where you could prefer not to use atlases is where you need too many details on a single object and maybe some of them use diferent propertys like transparency, emision, diferent tint on the albedo, and so on. But yes, for a character and level design the best solution is atlases, since they will be many of them on screen, so you want them to draw as low calls as possible to improve performance.
Answer by astracat111 · Jan 20, 2019 at 06:49 PM
So, the more unique materials per game object the more draw calls you're going to have, and that's everything for performance.
Furthermore, you want to use the most optimal shaders that you could use for your target platform. When I first started creating my game I had up to 8 unique materials per game object, and my draw calls shot up, and it was an intense load on the cpu, and this is with 64x64 minecraft-like textures! I was getting good performance on my Geforce 1050 Ti, but I was CHOKING on both my snapdragon cel phone and my internal Intel 620 UHD gpu.
If at all possible, you want to combine all of your game objects WITHIN YOUR MODELLING SOFTWARE, not within Unity, and texture atlas to get everything on one texture. Otherwise, you want to look at game objects and figure out which ones are similar looking so you can use the same few materials over and over and over on them, then make them all static so that Unity will static batch them.
On a single bookcase I had my draw calls up to 80 PER BOOKCASE because I was using up to 14 materials, one for the back of the bookcase, one for the front, like 4 unique ones for each book. I went into Blender and, even though it's a pain in the *ss, painstakingly creating a single UV Map for the entire bookcase, then brought that UV Map into Photoshop and copy and pasted each book image so that I had a bunch of books, the bookcase texture, everything in a single image.
I exported the PNG from Photoshop, then exported the fbx of the bookcase from Blender, and from there brought it into Unity. The draw calls dropped from 80 to 3 or 4 (1 for the png, and then I had dynamic lighting and shadow passes).
All in all, it's absolutely essential that you use as few materials/textures as you can in your project! Texture atlasing is done within your 3d modelling software, whether that's blender or 3ds max or even pro builder inside of Unity. It's done in photoshop, it's a pain in the *ss and takes a bit of time, but it's well worth the performance!
That's a really unneccessary process. You can add a second UV map in blender, then select all objects and unwrap automatically. Then bake the textures from the individual ones to the new atlas texture in one go. It's only a few mouseclicks.
Your answer
Follow this Question
Related Questions
Texture issue 0 Answers
Texture/Material changes but is not reflected in the game world 0 Answers
How do you draw a sprite from an atlas on to a mesh? 1 Answer
Runtime Normal Map Import Issues 1 Answer
Model replacement via c# Script 0 Answers