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
1
Question by Pauls · Feb 11, 2013 at 06:27 PM · meshmaterialdrawcalls

2 materials on one mesh = 2 draw calls?

Hi,

i have 2 materials for one mesh, my character, which has a jersey (the first material) and a number on the jersey (i used a second material to assign exactly the vertices and avoid the stretch effect, and each jersey will have its specific number). So i am not sure about the draw calls: does it mean unity call twice to paint each material on the same mesh?

thanks a lot

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
2
Best Answer

Answer by $$anonymous$$ · Feb 11, 2013 at 11:24 PM

You will get one draw call per material you use inside of Unity. So to avoid this, you could use one material that accepts two textures and combine then inside the shader, instead of using two shaders (two materials) to show the two textures.

Create a new Shader and paste this code in it. Then add one material to your mesh and choose 'TextureCombine_One_Drawcall' shader from the shader drop down.

 Shader "TextureCombine_One_Drawcall" {
 Properties {
     _MainTex ("Base (RGB)", 2D) = "white" {}
     _SecondTex ("Base (RGB)", 2D) = "white" {}
 }
 SubShader {
     Pass {            
             // Apply base texture
             SetTexture [_MainTex] {
                 combine texture
             }
             
             // Blend in the _SecondTex texture using the lerp operator
             SetTexture [_SecondTex] {
                 combine texture lerp (texture) previous
             }
     }
 }
 
 Fallback "VertexLit"
 }

Obviously you could optimise this shader a lot. But this should be pretty decent in terms of performance.

Hope this help.

Comment
Add comment · Show 6 · 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 numberkruncher · Feb 12, 2013 at 01:19 AM 0
Share

I wouldn't take this approach just to provide multiple textures for a mesh. It is usually better to use atlases. From a previous conversation on IRC it seems that mobile platforms are often limited in the maximum number of textures that can be added to a single material.

avatar image Pauls · Feb 12, 2013 at 10:37 AM 0
Share

@hdsenevi thanks! so, how could i change dynamically the second texture, whenever i want? (the number on the jersey will be different for each player) @numberkruncher : thanks! okay i think i see how to gather the textures in one texture atlas, but i should put all the texture of the numbers, with the texture of the jersey? this last one is 1024x1024 already, and my number is the same size i think... (x 6,7 textures...) can they be all in the same texture atlas?

avatar image $$anonymous$$ · Feb 12, 2013 at 10:48 AM 1
Share

Of cause. But the question says that he needs to have two textures, not an atlas. So thats why I proposed this, as a quick fix. I'm well aware that this is not the most optimised way.

If you only have a given number of small permutations of the jersey and the number that can go on top of it, you could create an atlas with all the possible combinations of the number and jersey colour and refer only that in the single material. But I got the feeling that 'Pauls' needed more flexibility than that.

And just for your information, I've sometimes used three or four textures in some of the shaders that I've used in the past. I've tested them running well on iPhone 4 upwards.

And another thing. It's not worth just considering the draw call count alone, when you are trying to measure performance and trying to optimise things (in my experience). Don't get me wrong, draw calls matter. $$anonymous$$eeping them to a $$anonymous$$imum is good. But another important thing is the resolution and the compression of your textures that you use.

It's generally considered a good practice to have around 30 draw calls for a mobile game. But I've sometimes had more (draw calls) with good fps since I was using lower res, compressed textures rather than having fewer draw calls with high res, uncompressed (true colour) textures.

I'm no means an expert on the subject. These are just a couple of things that I've picked up along the way.

But you must be right 'agonumberkruncher', there must be a maximum number of textures that you can add to a single material on mobile platforms. Do yo know what that is on some popular mobile devices?.

avatar image $$anonymous$$ · Feb 12, 2013 at 11:01 AM 1
Share

@Pauls : You can set the properties of your shader from your script. Try something like this in your script.

 renderer.material.SetTexture("_$$anonymous$$ainTex", other$$anonymous$$ainTexture);
 renderer.material.SetTexture("_SecondTex", otherSecondTexture);

Take a look at this for more info.

avatar image Pauls · Feb 12, 2013 at 12:09 PM 0
Share

@hdsenevi thanks hdsenevi i really appreciate your help!

Show more comments
avatar image
2

Answer by bcullis · Feb 11, 2013 at 07:07 PM

A change in material means settings in the rendering pipeline need to change, so that will require a new drawcall with the new material active.

FWIW: I'm new to Unity (but not graphics in general) so I'm about 70% certain this is the case. For example, I'm not sure how efficient batching of materials might be under the hood, which might minimize the number of calls across the whole scene, but in the case of that particular mesh, each material needs to be "drawn", hence your two drawcalls.

Comment
Add comment · Show 6 · 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 Pauls · Feb 11, 2013 at 10:06 PM 0
Share

thanks, and would you know how to gather 2 material in a single draw call?

avatar image bcullis · Feb 11, 2013 at 11:29 PM 0
Share

@robertbu: possible reference here

avatar image robertbu · Feb 12, 2013 at 12:22 AM 0
Share

@bcullius - the reference is for dynamic batching. That is multiple game objects with the same material. The original question is about a single mesh with multiple materials. In this case, I believe it uses the submesh array and the materials array. I though this resulted in a single draw call, but according to my searches in the last few $$anonymous$$utes, you are correct there is one draw call per unique material. There are some packages I use (like Vectrosity) that builds meshes and has unique colors for all the lines, yet draws in a single draw call. I'm not sure how they are getting their single draw call.

avatar image numberkruncher · Feb 12, 2013 at 01:16 AM 0
Share

Yes, there is one draw call for each mesh for each material. Also note that applying the same material to multiple slots in the renderer will also incur additional draw calls. The previous fact may seem pointless, though it is certainly relevant in scenarios where some modelling packages do this for one reason or another. The best solution is to bundle as many textures as possible into a single atlas texture and then share the same material between objects. The asset store offers some tools which make this process easy, and the performance benefits are worth it, especially on mobile devices!

avatar image Pauls · Feb 12, 2013 at 10:38 AM 0
Share

thanks for the answers

Show more comments

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

12 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

Related Questions

Does a mesh HAVE to have two UV sets? 1 Answer

Dynamic batching not working? 0 Answers

Character lighting issues 0 Answers

Material doesn't have a color property '_Color' 4 Answers

How to assign different colorsets to objects that are using the same mesh? 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