7/24/2012

Material Scripts Revisited

Since we use the material scripts (MaterialAnalyzer and MaterialReplacer) in our production pipeline I´ve received a few notes regarding current limitations.

As it happens the MaterialAnalyzer has been recently used with a prefab with missing components. Although it can be argued that something is substantially wrong with an input like this I decided to just add a quick check to handle these components gracefully. Obviously, missing components are excluded from the analysis process. The changes have been added to the UnifyCommunity article.

A more interesting issue came up with the MaterialReplacer script. I´ve just added Allegorithmic Substances support which was missing in the initial version of the script. So now its possible to replace a material with a substance by name defined in the material transition file.This feature was not as straight forward to implement as the standard material approach since substances are structurally different. As the documentation describes each individual substances file ("*.sbsar") does not represent an individual substance (wrt Unity materials) but is actually an archive containing one or more ProceduralMaterials. You can think of it as class->instance relationship. A substance actually defines a class describing the resources and algorithms used as well as public parameters. A procedural material acts as an instance of the substance which has individual parameter settings which eventually define the look of the material in Unity.
To retrieve all procedural materials in the projects asset folder it is therefore not enough to just find all "*.sbsar" files like the script does with material files, but its necessary to actually open all substances and retrieve the contained instances. This is not as efficient as it should be but I did not find a better solution yet. Anyway having around 40 substances in the project took around 2 seconds extra on my laptop. Additionally the parsing only happens when loading material transitions from file.
The changes have been applied to UnifyCommunity. Drop me a message if you encounter problems with the script or if something could be improved.

No comments:

Post a Comment