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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
1
Question by Emirk · Apr 03, 2015 at 01:28 PM · shaderspriteoptimizationfillrate

How does transparent sprites affect mobile performance?

I have a 2D platformer/runner game and I'm trying to optimize it so it runs fine on older devices. As one of several aspects, I'm currently investigating fill rate. As explained here by Robot Invader, fill rate issues occur when you write to a pixel many times. The more times you write the same pixel, the higher the performance cost. Transparent sprites causes pixels to be written to several times, since the engine can't tell if something behind that pixel should also be drawn. That is at least my understanding of it.

When we use sprites in our game, we use the SpriteRenderer component with the Sprites-Default shader. From the quote below (again, Robot Invader), it seems that the Sprites-Default shader would be highly inefficient for sprites that are opaque.

You pay for transparency anytime you render anything with a transparent shader, whether or not the texture you are rendering actually has an alpha channel. If it’s marked as a transparent object (i.e. put in Unity’s “Transparent” queue), it will be sorted back to front, and drawn with a shader that performs a multiplication of the current pixel value with the value of the computed color the shader is drawing (the actual math can be controlled using the Blend command in the shader’s pass). The way to think about this cost is in terms of the number of pixels that are touched by potentially-transparent things.

This tells me that anytime we use the Sprites-Default shader to render opaque sprites, and then render more sprites behind that sprite (i.e overdraw), those pixels will be drawn to several times because the Sprites-Default shader always calculates transparency. This eventually leads to poor performance on mobile devices because the fill rate skyrockets.

So what should I do about it? The obvious answer I come up with is to use another shader for sprites that are opaque. A shader that doesn't take transparency into account and thus doesn't draw stuff behind that opaque sprite. Yet when I google "Unity3D Sprites-Default Opaque" or something similar, I can't find a shader like that. Either it's really easy to do and being sucky at shaders, I don't know how, or this whole theory is wrong and Unity3D handles opaque sprites correctly anyway. In the latter case Robot Invader is wrong.

tl;dr: Is there a sprite shader for opaque sprites that is fill-rate efficient because it doesn't use the transparent queue?

Comment
Add comment · Show 3
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 supernat · Apr 03, 2015 at 01:29 PM 0
Share

Just for clarification, what version of Unity are you using?

avatar image Emirk · Apr 03, 2015 at 01:49 PM 0
Share

4.6.4 is what I'm using.

avatar image supernat · Apr 03, 2015 at 02:25 PM 0
Share

This is just my paltry assessment (and thus not an answer) by taking a quick look at the sprite shader. I have Unity 5, but it's probably similar to 4.6. The default sprite shader indeed is always in the Transparent queue and turns Z Write off, so it will always be sorted. Now you could take the default shader (download from unity3d.com) and duplicate this, modifying it for opaque sprites, but you can't really modify the behavior of the sprite code, so I don't know what the behavior will be. I assume if you use a duplicate but opaque shader, the game engine will not sort it, but I'm not 100% sure. They could be perfor$$anonymous$$g sorting of all Sprites internally, although I'd have to think they'd just use the existing Transparent shader sorting to do that... The real problem I see is that Unity creates the atlases, and you'd need to mark those textures as opaque as well as "hope" that Unity would create separate atlases for the opaque and transparent materials. I don't even know if those atlases are available to you, could be auto generated out of sight.

If you still have performance issues, consider using a plugin from the Asset Store as you'll have more control over all aspects and can modify the code/shaders as you please. I do think this is an issue Unity needs to address though.

In my experience, some devices get bogged down with overdraw while other devices get bogged down with vertex count (especially Android where you are trying to support the lowest end devices anywhere), so the alternate solution of using a 3D model (really just a planar mesh that defines the alpha boundaries so you can use an opaque texture on it, but it simulates alpha by the fact that you only draw the texture on the visible parts of the mesh) is not always the best solution either. You just have to profile as much as you can and make adjustments to optimize everything, but you already knew that.

You could kind of trick the game engine into preventing overdraw by making anything that gets drawn on top of the 2D artwork a 3D object with an opaque shader, but you'd have to change the default sprite shader to enable z writing to get any benefit which means you'd also have to explicitly set the Z value of all sprites.

Could you post a screenshot showing the overdraw problems? $$anonymous$$aybe we can make suggestions to help.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sekari · May 26, 2017 at 12:43 PM

I know this is an old thread. But I would like to share what we have discovered in order to reduce overdraw.

Unity has Screen.SetResolution function which can update the current resolution of the device. If you lower the resolution, the amount of overdraw reduces.

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 JonPQ · Nov 17, 2017 at 08:48 PM 0
Share

this is called screen Up-Sampling you render whole screen at lower res... saves on rendering (and is very handy improvement... I suggest 75% of original screen width) . but it does not really reduce overdraw (layering of sprites)

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 to render a sprite in the opaque pass 0 Answers

Sprite color invert 1 Answer

Optimise adding shadows in scene using Unity iPhone 2 Answers

Fixing fill rate issue on Android - best approach? 0 Answers

Reflect Fresnel Mobile VR 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