Material Manager
1106
post-template-default,single,single-post,postid-1106,single-format-standard,bridge-core-3.2.0,ajax_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,qode-content-sidebar-responsive,qode-child-theme-ver-1.0.0,qode-theme-ver-23.2,qode-theme-bridge,disabled_footer_bottom,qode_header_in_grid,wpb-js-composer js-comp-ver-7.7.2,vc_responsive
 

Material Manager

Material Manager

The Material Manager is a free repository of tools and techniques for updating and maintaining Materials and Textures in your Unity project.

https://github.com/Dicewrench-Designs/DWD.Toolkit.MaterialManager

  • Material Collections
  • Texture Packer Configs
  • Sealed Material Properties
  • Material Shader Variant Maker

Material Collections

Material Collections are ScriptableObjects that make it easy to keep property settings in sync across many Materials at once. This can be useful at Edit Time, if you want to update visuals across many Materials at once. And at Run Time if you want to update lots of Materials at once but don’t have or want to use Global Shader Properties.

You can Create new Material Collections via the Create Asset Menu by selecting DWD > Material Collection.

Next, add Managed Material Properties using the the Buttons provided in the Inspector. Assign the Shader Property Names you want to modify as you add Properties. Add Materials you want to Manage to the Materials Array. Now, as you change Property Values your changes will be propagated to every assigned Material!

Managed Properties may be of the following types: Color, HDR, Float, Texture, Vector, Keyword.

I like to use this pattern to calibrate Scene Materials for different environments or keep the stylized effects on all of my Character Materials in sync across the entire Project.

Texture Packer Configs

Texture Packer Configs are ScriptableObjects that allow you to non-destructively take the Channels from one or more Textures and rearrange them into one or more new Output Textures. This is ideal for packing specific data into the smallest number of Texture Samples for highly optimized shaders like Foliage Renderer Deluxe Shader.

You can Create new Texture Packer Configs from the Create Asset Menu by selecting DWD > Texture Packer Config.

When you Create a new Texture Packer Config make sure you give the asset a clear name! The name of your Texture Packer Config asset will be used as the Prefix of the name of each newly created Texture!

Next, set your output Path by clicking the Path button and selecting a folder in your Project. Assign Input Textures to the Input Texture Array on the left side of the Inspector. Then setup your Output Textures.

  • Provide an Output Suffix to complete the final file name of your Output Texture. The result will be [The Asset’s Name] + [Output Suffix].png.
  • For each Channel:
    • Enable or Disable the output. Disabled outputs will write out 0.0 to that pixel.
    • Set an Input Texture INDEX.
    • Select the Channel of the Input Texture to Copy from (R,G,B,A).

Finally, hit Pack and check your Output Textures!

Sealed Properties

Often in development you’ll want to hook up Material Properties in some class, modify those properties, and set them. Sealed Properties give you a defensive pattern for exposing values for rapid iteration without bloating your Inspectors or risking typos.

They function much the same as the ManageableMaterialProperty<T> generics you see in use in Material Collections but are not backed by ScriptableObjects so they can easily be in-lined in your code. If you want to tightly bind your Shader Properties to code this is the class to use. If you want to expose an unknown number of properties or property names use a MaterialCollection.

Sealed Properties may be of the following types: Color, HDR, Float, Texture, Vector, Keyword.

API

Sealed Properties inherit the SealedMaterialProperty<T> generic. They have two properties:

  • string _materialPropertyName: The name of the Shader Property to modify, set in the Constructor.
  • T PropertyValue: The value to Apply to the Shader Property, T depends on the type of Sealed Property.

The Public Functions you may call are:

  • ApplyPropertyToMaterial(Material m): Sets the Shader Property on the provided Material, if present, to the Property Value;
  • ApplyPropertyToMaterialPropertyBlock(MaterialPropertyBlock block): Sets the Shader Property on the provided MaterialPropertyBlock to the Property Value.
  • GetMaterialPropertyType(): Returns the MaterialPropertyType enum of the current Sealed Property class. This is primarily for Editor handling of input displays and validation.

Material Shader Variant Maker

Material Shader Variant Makers are ScriptableObject Assets that automate the populating of Unity’s ShaderVariantCollections for you! Material Shader Variant Makers take all Materials in Search Folders you specify using Shaders you specify and scrapes all the Keyword combinations and applys them to the ShaderVariantCollection you assign.

You can create new Material Shader Variant Makers from the Create menu by selecting DWD > MaterialShaderVariantMaker.

Next you will need to provide the Material Shader Variant Maker some references to make use of it.

  • Assign a Target Shader Variant Collection. If you don’t already have one, you can make one from the Create menu and selecting Shader Variant Collection.
  • Expand the Target Shaders foldout, and assign any Shaders you want to be part of this Variant Collection. At this point you don’t need to click ‘Find Mats’.
  • Select any Search Folders you want to use to specify which Materials in the Project to scrape. You can leave this empty and the ENTIRE PROJECT will get scraped but be careful because this can get slow if you have tons of assets. Toggle the Recursive checkbox on the Search Folder if necessary for your needs.
  • Hit the Refresh Button to find all the Materials in your Search Folders, figure out the Shader Variants, and update the Variant Collection.

If you want to Preload this Shader Variant Collection make sure you assign it to the Preloaded Shaders Array in Project Settings > Graphics.