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 CagatayYildiz · Nov 20, 2013 at 03:24 AM · material colordraw calls

Erratic DrawCall batching behavior, I'm going crazy

Hi guys, sorry for the dramatic title but this is absolutely driving me nuts!

I'm making a hex-based 'grand strategy' game for Android. I will have around 300 hex cells on the screen which will be colored based on which country they belong to. (I will add border effects etc. but that's for later)

I have one material which is the diffused hex texture. I use material.color for changing its color.

The way I did it apparently created new material instances for every hex so I ended up with 400 draw calls which is too much.

Then I thought of making just two new materials (one for each country) and applying it to every hexcell that the country owns.

When I do it, create two countries but give the whole map to only one country, voila! It's only 3 drawcalls. (saved 315 by batching)

But when I give some cells to the second country (with the second material) things start getting bad. Every cell I add to the second country adds 2 draw calls.

What's more interesting - the more cells I give to the second country, the draw calls added per cell gets fewer and fewer. At the beginning (as I said) it's 2 draw calls per cell. Then it becomes 2 draw calls per every 2 cells, then 5 cells... and then the total number of draw calls hits a peak (~200) when the map is exactly divided into two countries.

And after that, as I give more cells to the second country, the total number of draw calls actually declines.

Finally, when the second country has taken over the whole map, the number of draw calls has fallen back to 3.

What gives - anyone has any ideas?

edit: Some more info - the objects don't cast or receive shadows, total Tris on the scene: 2.1k, total Verts 2.4k, no scale (all 1)

Comment
Add comment · Show 2
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 robertbu · Nov 20, 2013 at 04:58 AM 0
Share

I don't have a solution to the specific scenario you outline, but I have three alternate ideas that should solve your batching issue:

1) Use a shader that supports Vertex color and change the colors array in the mesh to change color for selection.

2) Use a texture atlas (just two textures for what you have outlined), and change the texture using the uv array in the mesh to indicate selection.

3) Create two hex objects for each cell. One object is for the selected state, one for the normal state. Turn on/off the renderer to change state. Each set of 300 (one set for selected one for normal) shares a material, so all your hexes should draw in two draw calls.

avatar image CagatayYildiz · Nov 20, 2013 at 05:59 AM 0
Share

Thank you for listening to my problem and offering some solutions. I'm very thankful. $$anonymous$$y problems though:

  1. Would that not result in there being instances of $$anonymous$$esh ins$$anonymous$$d of a single mesh - essentially the same problem I have now, only with meshes ins$$anonymous$$d of materials? Won't that possibly result in additional draw calls too?

  2. Again the same problem - when I change the UV array in the mesh now I have more than one mesh.

  3. This is actually a great idea but I've thought of it before and the problem is: I plan on having more than 2 countries, also plan to have some effects on the border cells etc. which will all require different cell 'layers' and will multiply the total cell count by 300 each. Won't that be a problem?

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

17 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

Related Questions

Baked Light Maps 2 Answers

Problem with 2D Sprites and draw calls 1 Answer

Multiple Shaders vs. Single Texture - Please help me overthink this. 2 Answers

How can i make the ball in a Pong game move without using rigidbody function and bouncy (Physics Material) 0 Answers

material.SetColor ("_EmissionColor", Color.white) 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