7/03/2012

Material Analyzer

Working with Unity3D it happens from time to time that I´m confronted with 3D models (usually in ".fbx" format) which haven´t been optimized for real-time simulation environments. Although the triangle count is not that high I often find a substantial amount of materials applied to these models (typically resulting in a spike of draw calls whenever the object is visible).

Recently I got in touch with a car model which originated from a Sketchup pipeline. This single car had a few thousand triangles, which was fine for the setup. The performance significantly dropped after adding it into a test environment though. Since it consisted of about twenty different game objects (some of them were just empty nodes) it was hard to get an overview of how much materials where used by the model and which.

I finally decided to write an editor script to get a better understanding which now does the following:
  • it checks every selected game object and its children for MeshRenderer and ParticleRenderer
  • it list all materials used by these components alphabetically within the editor window together with their shader
  • clicking on one or more list items selects the game objects using the material(s)
  • clicking on a small button beside each item selects the material asset to view it in the inspector
  • the button "Dump Hierarchy" dumps the hierarchy of the analyzed selection to a text file including the materials used by each game object
  • the button "Dump List" dumps the current list of materials to a text file with the list of game objects using each material
This script does everything so far to analyze the materials used by objects I need. I´ve implemented the dump options especially for logging, e.g. if other people in a team need to become aware of certain configuration issues.

I´ve uploaded the "MaterialAnalyzer" editor script to Unify Community to help other developers struggling with similar issues. I hope it helps. :-)

Mirko

No comments:

Post a Comment