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 warfronts · May 10, 2015 at 06:49 PM · spriteoptimizationspriterenderersorting orderdraw calls

Draw call depending of sorting Order of SpriteRedenderer(2D)

Hello,

Clear problem:

  • 2 sprites Atlasses A and B.

  • One sprite form Atlasses A (SA) and another from B (SB).

The drawCalls increasses if the order of the sprites is

Sorting Order: SA - SB - SA

This will draw SA first, after the GPU will change to TextureAtlass B (+1 drawcall). Finally the GPU will change the TextureAtlass again to Atlass A to draw SA(+1 drawcall).

Total drawCalls = 3. Expected drawcalls = 2. (Because only 2 Atlasses)

Is this normal or Can it be optimized for less drawcalls? The order is important for the game, and also I already know that one possibility is combine the 2 TextureAtlass.

Thanks.

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 codebeans · Apr 08, 2016 at 09:07 PM

3 draw calls is correct in this case, here is why.

A sprite is really just a bunch of vertices, triangles, uvs and a shader that has information like the current texture. read more These information will then be gathered and sent to GPU. Unity reduces draw calls under the hood by batching these sprite data together and sends them in one big chunk to the gpu instead of each sprite's data individually.Each sending operation means one addional drawcall.

The first criteria to batch sprites is that they reference the same texture.

So why does SA1-SB-SA2 result in 3 draw calls instead of 2 then?

Having the sprite (SB) between SA1,SA2 will break the batch because it references a different texture

Step by step:

  1. Unity figures out render order by depth to be SA1-SB-SA2

  2. Open first drawcall (vertexbuffer, indexbuffer,...) and add SA1

  3. Find next sprite SB

  4. Textures do not match (stop batch, send to GPU)

  5. Open second drawcall and add SB

  6. Find next sprite SA2

  7. Textures do not match (stop batch, send to GPU)

  8. Open third drawcall and add SA2

  9. No more sprites, finish and send to GPU

Now what about SA1-SA2-SB

  1. Unity figures out render order by depth to be SA1-SA2-SB

  2. Open first drawcall (vertexbuffer, indexbuffer,...) and add SA1

  3. Find next sprite SA2

  4. Textures do match, append SA2's data to the drawcall

  5. Find next sprite SB

  6. Textures do not match (stop batch, send to GPU)

  7. Open second drawcall and add SB

  8. No more sprites, finish and send to GPU

Bad news is unless you want to dig deep into OpenGL that you have to combine both your Atlases A and B.

Note: If this happens a lot in your scene (SA-SB-SC-SA-SC......) and you can't combine the atlases that makes texture atlasing useless and you shouldn't use it then.

In that case runtime packing is the way to go.

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
avatar image
2

Answer by RotemAV · Jan 17, 2018 at 04:34 PM

@youtilities I think Sorting Group solve the problem

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 Frolky · May 19, 2020 at 09:17 AM 0
Share

Thank you, it helped!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How come setting sprite tint/alpha does not increase draw calls? 0 Answers

How can i get my gameobject as a sprite from its collider name? 1 Answer

Sprite Alpha Performance 0 Answers

Is there a way to change the sprite for all instances of the same object simultaneously? 1 Answer

Sorting Layer Logic Issue 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