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
0
Question by NathanJSmith · Sep 11, 2018 at 08:01 AM · materialslodmaterialpropertyblockshared materials

SetPropertyBlock for LOD?

I use SetPropertyBlock to paint color for my model. My model has 5 level of details (LOD0 to LOD4).

The problem is LODs in Unity doesn't share the same materials array (sharedMaterials), thus I paint color for LOD0 doesn't affect LOD1,.., LOD4. So I tried painting for other LOD too:

 Transform[] arrLods;//The array of LODs
 //Assign arrLods
 //...
 
 MaterialPropertyBlock propBlock = new MaterialPropertyBlock();
 Renderer renderer = arrLods[0].GetComponent<Renderer>();
 
 //Paint for LOD0
 //...
 
 //Paint for other LODs
 Material[] matLODs;
 Renderer rendererLODs;
 for (int i = 1; i < arrLods.Length; ++i)
 {
     rendererLODs = arrLods[i].GetComponent<Renderer>();
     matLODs = rendererLODs.sharedMaterials;
     for (int m = 0; m < mat.Length; ++m)
     {
         for(int mLODs = 0; mLODs < matLODs.Length; ++mLODs)
         {
             if (mat[m].name == matLODs[mLODs].name)
             {
                 rendererLODs.GetPropertyBlock(propBlock, mLODs);
                 if(propBlock.isEmpty)
                 {
                     renderer.GetPropertyBlock(propBlock, m);
                     rendererLODs.SetPropertyBlock(propBlock, mLODs);
                     break;
                 }
             }
         }
     }
 }

Because the order of other LODs doesn't match the order of LOD0, the code "Paint for other LODs" is a little complex, but I still have bug in case the materials have same name (Brick1, Brick2,... use same material Brick, but difference color)

so I wonder if there is a better way to properly SetPropertyBlock for LOD?

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 NathanJSmith · Oct 24, 2018 at 01:07 PM

I think there are 2 solutions:

Solution 1 - Do something in your modeling software so that the order of material the same for each LOD, then you can manually paint each LOD.

Solution 2 - Paint only for LOD0, other LODs (LOD1, LOD2,...) will have 1 material only (thus we don't need to paint it). I see that in GTA IV's ped, they do this, when the ped is far away, it turns gray.

I'll take solution 2, because each material in the model requires one draw-call, so I want to save draw-call for far objects.

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

140 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 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 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 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 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

Shader Animation (and PerRendererData) 1 Answer

MaterialPropertyBlock ignored when rendering with replaced shaders? 0 Answers

Can Material Property Blocks be serialized? 1 Answer

Renderer with multiple materials -- per-material MaterialPropertyBlocks? 1 Answer

Switching all Materials on objects using the same. 1 Answer


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