Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by RSpicer · May 29, 2017 at 06:30 AM · materialsmeshrenderermaterialpropertyblock

Renderer with multiple materials -- per-material MaterialPropertyBlocks?

I am working with imported assets that have multiple materials per mesh (eg: a single MeshFilter and MeshRenderer, with the MeshRenderer's materials[] array containing 2 or more entries). Each Material has a unique albedo texture but shares other parameters with every other material. For Meshes that contain only a single material, I've been using MaterialPropertyBlocks to quickly change properties across every material. (I'm ingesting models from photogrammetry software, and adding overlays, different shading strategies, etc -- this is data viz in a game engine, not really a 'game').

This breaks when Models have two or more Materials, though -- I can only set a single MaterialPropertyBlock for the MeshRenderer, so Material[0] gets the correct albedo, but Material[1] through whatever end up sharing that albedo, which of course looks horrible since the UVs are all wrong.

To work around the issue I could create several shaders with texture samplers named eg _MainTex0, _MainTex1, etc, and make sure the variant with _MainTex1 is always assigned to materials[1], etc, but this seems like a silly hack.

Is there a "right" way to get this done?

Comment
Add comment · Show 1
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 bjo_dev · Jun 29, 2017 at 06:24 PM 0
Share

Did you ever find a way to do this? Currently running into the same situation.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Glurth · Nov 26, 2017 at 07:56 PM

One workaround option is to call the Graphics.DrawMesh function, rather than using a MeshRenderer component. https://docs.unity3d.com/ScriptReference/Graphics.DrawMesh.html This function has versions that take a MaterialPropertyBlock, a Mesh, and a sub-mesh index. So, obviously, you would need to call this function once per sub-mesh.

In my experience, this is far less efficient (speed-wise) than using a MeshFilter and MeshRenderer.

I don't really LIKE this workaround, I'd rather be able to actually set a particular sub-mesh's MaterialPropertyBlock, and just use the Regular MeshRenderer, but I just don't see how- other than breaking up the mesh's sub-meshs into multiple "full" meshes (and putting them in the scene as their own GameObject, with their own meshFilter and meshRenderer).

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Can Material Property Blocks be serialized? 1 Answer

Material vs. SharedMaterial - difference in SETTING? 1 Answer

Getting mesh material length 1 Answer

Assigning Materials[] produces populated array. 1 Answer

How Do I Apply An Additional Mesh, So That Both Meshes Show Up? 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