Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Siccity · Oct 16, 2014 at 12:17 AM · shadermaterialoptimizationlayersorganization

Material optimization/organization

I have a lot (over 100) of models that the user can add to a scene. Most of these models share generic metal materials to reduce the amount of different materials I'd have to modify to change all of them. However, I want all my models to use different normal maps. The base materials for all of these models will still be the same, steel, brass, gold, iron etc.. One way to do this would be copying the generic materials for each and every model and then assign the desired normal maps, but that'd result in a near endless amount of materials to modify if i want to make a small change in the overall iron shader.

Is there any way to make materials derive from another material, sort of like a hierarchy? I am targeting computers, so draw calls isn't the biggest issue

alt text

example.png (10.0 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by KpjComp · Oct 16, 2014 at 01:28 AM

Yes, I've knocked up a script to get you started. This currently allows you to alter the Textures, but you can modify to add other stuff you want to override. Basically set a Source Material that you want to descend from, and a destination material you want to save to, you can then override the textures for Diffuse, Normal and ReflectionCube.

Hopefully this will help, ps it also works in editor mode. Basically attach this script to an EmptyObject and maybe say called it MaterialBuilder or something like.

 using UnityEngine;
 using System.Collections;
 
 [ExecuteInEditMode]
 public class MaterialBuilder : MonoBehaviour {
 
     public Material Source;
     public Material Dest;
 
     public Texture DiffuseTexture;
     public Texture NormalMap;
     public Texture ReflectionCubemap;
 
     void updateMat() {
         if (Source == null) return;
         if (Dest == null) return;
         Dest.CopyPropertiesFromMaterial(Source);
         if (DiffuseTexture != null) {
             Dest.SetTexture("_MainTex", DiffuseTexture);
         }
         if (NormalMap != null) {
             Dest.SetTexture("_BumpMap", NormalMap);
         }
         if (ReflectionCubemap != null) {
             Dest.SetTexture("_Cube", ReflectionCubemap);
         }    
     }
 
     // Use this for initialization
     void Start () {
         updateMat();
     }
     
     // Update is called once per frame
     #if UNITY_EDITOR
     void Update () {
         if(Application.isEditor) {
             updateMat();
         }
     }
     #endif
 }
 

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Siccity · Oct 16, 2014 at 09:40 AM 0
Share

Thanks, definitely a shot in the right direction, however this leaves me with a big list of empty GameObjects. Won't that hurt performance?

avatar image KpjComp · Oct 16, 2014 at 09:50 AM 0
Share

I believe Empty games objects should have $$anonymous$$imal effect on performance, the only event here that will get called a lot would be the Update, if you don't $$anonymous$$d not seeing the changes in the Editor you could even maybe leave this out, and then Start is only called once. Or even better wrap the Update inside a #define, I'll actually modify my script to do that, so that BUILD version won't have this unnecessary check.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

29 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Need help with Shaders and material layers! 2 Answers

Texture Layer help. 0 Answers

Material doesn't have a color property '_Color' 4 Answers

Do materials with same texture yet different shaders share the texture? 1 Answer

What is the Best Material Practice for Low-Poly Cube Style 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges