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 pmraider10 · Jul 22, 2019 at 09:39 AM · shadersoptimizationassetbundlematerialsbatching

Shader / Material Refreshing, AssetBundles, and dynamic batching issues

Hey all, I've run into an optimization issue that I am struggling to find a lot of information for:

Basically I am creating a 3D WebGL game that downloads AssetBundles on every startup to get the model content from our servers. We have a business requirement to grab these models each time the game loads, so they cannot be packed into the webgl artifact.

If you have ever used AssetBundles in webgl in this way using the standard shader, you know that for every material that is being unpacked on the fly, you need to refresh its shader or it will not know how to render it properly. Here is my sample "RefreshShader" code:

 public static void RefreshShader(GameObject clone)
     {
         var renderers = clone.GetComponentsInChildren<Renderer>();
         for (int i = 0; i < renderers.Length; i++)
         {
             var materials = renderers[i].materials; //I have also tried sharedMaterials here, doesn't help
             foreach (var material in materials)
             {
                 var rq = material.renderQueue;
                 material.shader = Shader.Find(material.shader.name);
                 foreach (var s in material.shaderKeywords)
                     material.EnableKeyword(s);
                 material.renderQueue = rq;
             }
         }
     }


If I don't execute this code when I instantiate a model GameObject, the mesh does not render properly, since the shader does not know what properties to use. It doesn't seem like I have a choice in this matter (I welcome any suggestions otherwise!)

As a result of having to refresh each material shader, I am basically breaking Unity's ability to dynamically batch my objects that share materials, so I have WAY too many drawcalls when a scene gets busy. CPU draw calls seem to be the biggest performance bottleneck and I am trying to cut these down, but can't due to the material refresh issue.

Does anyone have a suggestion to 1. Avoid having to refresh materials/shaders in this manner that breaks batching, or 2. refresh these materials/shaders in such a way that it does not break batching (i tried to use sharedMaterials instead, the materials do work correctly when I use this, but it still does break batching for some reason). or 3. reduce my draw calls in an alternative way that is not dynamic batching or culling

Please also note that these objects are movable so I cannot use static batching to handle this.

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

0 Replies

· Add your reply
  • Sort: 

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

130 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

Related Questions

Dynamic batching 6 Answers

Batching draw calls? 2 Answers

Dynamic batching breaks with the material Mobile/Alpha Blended. 0 Answers

Optimizing bump map or luminous textures on spheres for mobile 1 Answer

Share material to reduce draw calls 3 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