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 Vorren · Jun 19, 2015 at 04:07 PM · 2d spritessorting orderz axis

Mixing 2d sprites with 3d environment - sorting issues

I want to achieve rendering similiar to "Don't Starve" - a mixture of 2d sprites and 3d projection on the same scene. Also my scene will use real 3d objects.

Camera is set to use orthographic projection.

My characters are gameobject hierarchies, some nodes of which contain sprite renderers. Those have default sorting layer and different layer order values (to layout various body parts). Then these characters are positioned in 3d-space.

The issue is that sorting order takes precedence over z-index. Is it possible to use sorting layers and z-ordering together? Where am I going wrong? How to implement that sorting of mine?

ps: the offending helmet of dark knight alt text

3d-sceneunity-the-guild-pc-mac-linux-standalone-20.png (437.2 kB)
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 _dns_ · Jun 19, 2015 at 05:27 PM 0
Share

Hi, default sprite shader doesn't write to the Z buffer and sprites are considered transparent (= with different alpha values, not only 0 or 1 alpha cut like your sprites have -as far as I can see-). Then, the sorting order of the transform is what will decide the rendering order.

So, you could use the transform sorting, changing hierarchy and sibling order to manage sorting.

You could also duplicate the default sprite shader and make some changes: removing the "ZWrite Off" line should be enough. If you have only alpha cut sprites, you could also change the Queue from "Transparent" to "Geometry" and the renderType to "TransparentCutout". Doing so might help sorting everything if you have other transparent objects like smoke/magic particle...

EDIT: don't forget to rename the (EDIT2: internal shader) name too (first line of the shader)

avatar image Vorren · Jun 21, 2015 at 10:18 AM 0
Share

I'm afraid that custom shader didn't fix the issue - it brought z-fighting and a need to modify all character animations (they animate z value back to 0 even if I do add z offsets).

avatar image _dns_ · Jun 21, 2015 at 03:14 PM 0
Share

Ho, yes, didn't think about animation messing with local Z, sorry.

If you know what sprite is in front of what other sprite in a character, you could add some LateUpdate script (=executed after animation is done) that restore the local Z to a predeter$$anonymous$$ed value, like a layer system local to each character. Then you wouldn't have to modify animations. This "z override" value could even be exposed to be animated if you need to change layer order during some animations.

Also, I can see that the shadows of the characters are cut by the ground. What I did in a previous project is to modify the Z offset in the sprite shader so the sprites are drawn a little "in front" of 3D geometry. This is a little tricky to tune and may not be possible in your game. It's quite easy to try: add a new line with "Offset 0, -3" next to the "ZWrite On" line. This -3 value is the one to tune, it will depend on your camera settings (I needed greater values for an orthographic camera)

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Sorting Layer Conflict 1 Answer

Special sprites ordering 1 Answer

Sprites rendering slightly off world coordinates 1 Answer

Unity 2020.3 URP shader color won't change properly 0 Answers

why are my sprites pixeleted in the game view? 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