DGUnreal Tips-UT 3 Material Instance Constants

 

Unreal Tournament III Tips and Information
This information is provided by DGUnreal.  Please do not copy this and post it elsewhere.

Material Instance Constants

A Material that contains any of the parameterized expressions, for example a VectorParameter, can have a MaterialInstanceConstant object based on it. A MaterialInstanceConstant is an “instanced” copy of a parent Material.  The MaterialInstanceConstant simply allows changes to the exposed parameterized expressions of the parent Material.  The only real technical advantage to using MaterialInstanceConstants is the fact that they do not require multiple Material compiles.

The use of MaterialInstanceConstants has its main benefit simply in the area of workflow.
This is most useful in creating, for example, a set of similar metal Materials that have a different Texture and possibly variances in Specular or NormalMaps. Also, by making changes to the parent Material, all of the MaterialInstanceConstants can be changed map-wide, allowing for faster visualization and design choices.

One might assume that always using a Material plus MaterialInstanceConstant is better than using two distinct Materials, but that simply isn’t true. It depends entirely on the designs of the Materials in question.

It is incorrect to believe that “if I create a base Material that has every common permutation that I want to use, then create multiple MaterialInstanceConstants based on that, it will be better because they are instanced versions”. That isn’t true.
MaterialInstanceConstants are essentially only for creating reduced Material counts by allowing parametric equivalents of effectively identical Material expression layouts.  In other words, if I have two Materials with all of the identical internal expressions except that I want one to have a different multiplied Specular and/or NormalMap, then a MaterialInstanceConstant could have a benefit. However, if the set of Materials I need are quite distinct, there is little advantage to using MaterialInstanceConstants.  For example, with two Materials that are only a single different Diffuse Texture Sample, there is no advantage as the two Materials have nothing in common.

I personally use Materials set up for use with MaterialInstanceConstants only if the Material is relatively complex and if I can save some time and hassle of not having to create multiple duplicates of the Material, and if there is a sufficiently large amount of Materials I will be using that have the same expression layout and the same Material “type”, such as “metals”.  In this case using MaterialInstanceConstants is a good idea, since if I need to change something in the parent Material, such as adjusting the SpecularPower to look more metallic, it is inherited by all of the child MaterialInstanceConstants. Otherwise, had I not used MaterialInstanceConstants in this example, I might have to change six or eight individual metal Materials.

There are no substantial memory savings since shader instructions don’t require much memory.
There is no substantial performance difference since the performance factor is the total number of shaders, and that is shared in both cases of Materials only or Materials plus MaterialInstanceConstants.

MaterialInstanceConstants have their greatest use in the fact that it can help to manage large sets of identical Material expression layouts, it is mainly a workflow efficiency benefit.

One example is if I created a MaterialInstanceConstant based on Epic’s Engine_MI_Shaders.M_Shader_Simple Material, which is a simple basic all-purpose Material of 69 Instructions and 5 Textures.  If the MaterialInstanceConstant that I am creating does not require the entire Emissive branch, the Specular Mult, and the entire NormalMap Detail branch, then I am better off creating a different Material that properly fits within my needs. This will result in an improved Instruction count for the desired Material.  For example a basic Material with only Diffuse, Specular and NormalMap Texture Samples, and a Constant for SpecularPower, is only 54 Instructions and 3 Textures. In other words, creating a single high-Instruction-count master Material is a bad way to manage things.

Another example is if I use any static parameters in my Material.  In this case, a new Material is compiled out for every combination of static parameters used, which can cause an excessive amount of shaders being compiled.

MaterialInstanceConstants can also cause issues on Terrain due to the parameter namings, and the fact that all Terrain layer Materials are combined into one large master Material.

Master “Parent” Material and its custom Fallback Material.

ut3-tut-ut3tips-mics-mat

Master “Parent” Material in Editor.  Note use of parameter expressions (highlighted in red).

ut3-tut-ut3tips-mics-mateditor

MaterialInstanceConstant based on Parent Material.

ut3-tut-ut3tips-mics-mic

MaterialInstanceConstant showing exposed Parent Material parameters.

ut3-tut-ut3tips-mics-miceditor

With permission, I am hosting this information for the UT 3 editor.  A big thanks to DGUnreal for allowing this useful information to live on.  I duplicated the tutorials as they were given to me.  There may be information that was going to be added by DGUnreal. But take this information on this page as completed.

© 2010 Odedge Level Design Suffusion theme by Sayontan Sinha