• 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 fleity · Jul 29, 2019 at 08:14 AM · renderingsorting order

Submesh Sorting, draw as if in transparent queue

Hey everyone,

I have a few objects from spine using multiple materials. For reasons (mostly effects) our entire game is rendering in the geometry queue which works fine for most 1 Texture 1 Material objects, but objects with multiple materials get sorted in the wrong way. They are sorted by material, first submesh has material A assigend second submesh material B, third submesh material A again. In the transparent queue it would draw ABA, but in geometry it draws as AAB.

Is there a way to a have a material be sorted as if it was in the transparent queue? Or any other workaround for this issue really?

thanks a lot for your help

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Jul 29, 2019 at 10:31 AM

No, opaque geometry (everything below the transparent render queue start) will be sorted front to back. Transparent geometry has to be sorted back to front.


Of course no one prevents you to give a material a render queue that is in the transparent range, however since transparent shaders and opaque shaders in most cases work entirely different, the result might not be what you expect. Opaque shaders generally write to the depth buffer that's why they are drawn front to back to avoid overdraw. Transparent shaders (not cutout shaders!) usually do not write into the depth buffer since they have to be drawn with the painters algorithm anyways. However all those shaders do perform depth testing.


All meshes are drawn based on the material because the material actually specifies the shader and how it should be drawn. It doesn't really matter if you have submeshes or seperate objects.


Note the main advantage of using a single shared material is that Unity can actually batch all geometry together and draw everything that uses this material at the same time.


You haven't really mentioned what your issue is. If A is an opaque material it would hide everything that a transparent material would draw "behind" that opaque geometry. Transparent geometry always has to be drawn after all opaque geometry has been drawn. You can not fill in opaque geometry behind an already drawn transparent object.


We can not suggest any workarounds without knowing the actual issue. You just said that the materials are sorted the wrong way, but they are not. They have to be drawn that way. So we still miss an actual description of your issue.

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 fleity · Jul 29, 2019 at 12:57 PM 0
Share

Thanks for your help it's very much appreciated. I know that opaque objects get sorted front to back and with a good reason. I would love to share some images as the issue gets much clearer but it's all under NDA and its a critical asset I'm afraid :(.

$$anonymous$$y shaders does not write to the depth buffer. The best way is to imagine a character made up of sprites using alpha textures being rendering in the geometry queue (I know that this is a weird case, but of course you can do alpha blending in the opaque queue). Let's say both arms are each a quad. Both use the same material one needs to be behind the body one in front. But what happens is both arms are drawn at the same time.

I can not change the queue. I can assign different instances of the same material.

I am at the point where I tried issuing the drawing of each submesh manually with an instanced unique copy of each material offsetting the z-position using Graphics.Draw$$anonymous$$esh but even if the meshes are ordered front to back in the scene view they are not rendered in that order. I tried overwriting Camera.opaqueSort$$anonymous$$ode and NoDistanceSort gives me a very consistent but exactly reversed order from what I would need.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

Rendering objects by their y position with a script 0 Answers

Ensuring new sprites render over existing sprites 1 Answer

how to change the render sequence in 2D game ? 2 Answers

2D bone based prefab render order 2 Answers

separate vert and frag shader functions in two distinct URP Render Features 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