Material optimization considerations.

Hi! how you folks doing? i hope you are doing great and making awesome art!

Haven’t found a thread or threads that specifically points to material optimization. If im mistaken please, point out as much reference as you can, but for now i would like to ask some questions and maybe centralize all the references and comments in one post.

Im working on a VR project for HTC Vive, and being the only env artist in there (a newbie is gonna be added soon) i have to be my own tech artist, which is exciting and terrifying at the same time. These are my first questions after reading a few articles (2 of which i share below):

  • It is suggested to combine meshes into the same material, usually creating a texture atlas if needed, two questions arise:

        – Does this suggestion apply even if the meshes aren’t in the same .fbx? Mesh A and Mesh B are imported into the engine as separate files, but then the same material is applied inside the engine. Is there any difference if a import them as one file? or it doesn’t matter?.
    
         – In the pipeline we are creating the minimun texture resolution per asset that works well is 1K (let’s say for the Base Color), if we combine 4 of those assets into one material and pretend to keep the same resolution restriction, then we would have each asset with a 512×512 square of resolution assigned to it in the atlas, and some assets look bad. What’s the tradeoff of having one material assigned to 4 assets but with a 2K resolution texture set (or even greater if we, for example, group 16 assets into one atlas), it is still worth it to combine meshes into one material?
    
  • What about bleding materials?. For example, Unreal Engine does support a lot of blending options, what would be better from an optimization POV: to have two materials combined using a blending node inside another material, or to create one material that asks as inputs two of each textures and combines it directly inside of it?. It seems that the later option is the best, specially if we are doing blending using vertex info, because one material is (roughly) one draw call, instead of at least 2 drawcalls that are blended together. Did i get that right? any other thoutgh on blending, because it is insanely important for env art.

  • It’s usual practice to have a Master Material in Unreal Engine which then is instanced for. In our case it is needed for our Master Material to support some blending options for some 3D assets, but for other 3D assets there is no blending needed, actually, our project uses photogrammetry and we tested results with just a material with Albedo, Roughness and Normal simply plugged into it and it looks great for us. The question is: what would be more efficient, to keep that Master Material for all the meshes, or create 2 masters, one that handles blending and one that is a lot simpler? as i understood it, having one material is more effective, but i want to take into account shader instructions to make a better judgement.

I do and totally understand that much of this is content and project dependent that needs to be profiled properly, but i also do need some starting point for comparisson sake.

The articles that are my main references:

https://simonschreibt.de/gat/renderhell/

Thanks everyone!

-for your question regarding the number of meshes per material: try to keep both the number of meshes and the number of materials as low as possible, as draw calls are a big performance hit for VR, and the number of draw calls in a scene is made worse with both more materials and more meshes.
Try to keep each mesh with 1 material each, though for things like windows it is better to have 1 mesh with 2 materials than to have two meshes each with 1 material (for the window and sill).
The number of meshes on screen is a balancing act between object culling (for meshes outside your FOV) and the number of draw calls (for meshes within your FOV). Find a good balance for this in your specific project.

-As for texture atlases, afaik the number of smaller textures vs. larger ones i dont think matters all that much, until you reach a point at which a 2k texture is only used for a small part of your scene (resulting in a lot of wasted VRAM space for the rest of the texture that isnt used), though I’m not the most knowledgeable on that.

-For blending materials, I prefer to keep it at 1 material with different blended textures within it, as often I find there are parts of the material that don’t contribute enough to the blending to warrant any extra effort, and can be removed from the effect. With multiple blended materials inside their own function w/the material blend nodes doing all the work, you’ll often find that more work is being done than may be necessary to get the effect you’re after (specular, AO, etc… are the usual culprits).

-for the master materials vs material instances: the smaller the number of master materials the better (for workflow and shader reasons), but if a material does a different kind of thing (say one has emmissive, and one doesnt. or one has parallax, or an animation), then separate master materials can help make the shaders cheaper (unless you’re using switch parameters) or take less time to compile (as it doesnt have to compile for each switch state). afaik if one master material has a switch in it with two effects, you end up with the same number of shader instructions as you would if you had two separate materials, so i prefer to separate them so that my shader compile time and my authoring time is optimised better.

Thanks! that was helpful.