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 Sonic4305 · Dec 22, 2011 at 01:23 AM · colorscalebatching

Batch Objects with Different Colors and Scales

I am fairly new to Unity so this may be my own simple failure but I am currently converting an XNA game to Unity. I have about 8000 objects that need to use the same texture but have random colors and scale that constantly change.

I have noticed that nothing is getting batched and have determined it is because of the different colors/scales.

How can I have objects with different colors and scales still be batched together?

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

2 Replies

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

Answer by ytao · Dec 22, 2011 at 07:27 AM

The failure of batching is most likely the material color. If you have ever modified any properties of a material, like color, uv, it will create an instance of the material. You can verify this by checking the [Material] field of the GameObject in the Hierarchy view at run time, and you should see "(Instance)" at the end of each material name.

The "bucket" technique may be helpful. You need to limit the random set (namely infinite) to some finite set. For instance, pre-create 100 random colors and choose from them to simulate random effect. Then, pre-create 100 materials for these colors and every object will be linked to one of them. So, objects that "falls" to the same bucket (color) will share the same material and will be batched accordingly.

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 Sonic4305 · Dec 22, 2011 at 06:35 PM 0
Share

I isolated both color and scale, because I didn't believe scaling was a problem either, and have found they both cause objects to not batch. The color I understand but scaling I do not. I think it may be because the scaling is very dynamic and changes essentially every frame but I don't understand how it's not batching because the material is not instanced.

avatar image reefwirrax · Dec 30, 2013 at 07:55 PM 0
Share

you can do it in shaderlanguage if you dont need to send the color info every frame to shader, overlay a color on a shader.

also around here is a question from zoomdomain saying how to batch colors by changing uv's of each mesh and using the same multicolor texture on all them.

avatar image
1

Answer by reefwirrax · Dec 30, 2013 at 07:59 PM

Renderer.SetPropertyBlock.

Unity's terrain engine uses MaterialPropertyBlock to draw trees; all of them use the same material, but each tree has different color, scale & wind factor. The block passed to Graphics.DrawMesh or Renderer.SetPropertyBlock is copied, so the most efficient way of using it is to create one block and reuse it for all DrawMesh calls. Use Clear to clear block's values, and AddFloat, AddVector, AddColor, AddMatrix to add values.

Comment
Add comment · Show 1 · 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 jknight-nc · Apr 17, 2016 at 06:06 PM 0
Share

$$anonymous$$y tests show that using $$anonymous$$aterial Property Blocks achieves (at best) the same performance as using different materials (but the same shader).

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

7 People are following this question.

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

Related Questions

Changing two different objects renderer colour 1 Answer

Vertex colours - can they improve performance? Do they affect batching? 1 Answer

Surface Shader issue: property color gets changed 0 Answers

Changing vertex colors break batching? 3 Answers

Is it possible to batch Unity TextMesh objects, which share the same material, but with different opacity values? 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