Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 mattanmohel · Jan 25, 2021 at 04:08 AM · meshtilemaprender order

Mesh quad rendering order

Hi, I'm working on creating a little custom tilemap system in which I use a single mesh to contain a grid of quads that displays the desired sprites. The issue arises when I have sprites that extend the size of one tile and therefore overlap. When this happens the quads higher on the y-axis always draw on top of quads lower on the y axis. I've tried flipping the order in which they're drawn and such but the issue persists. Is there any way to control the sorting order individual quads are rendered on in a mesh?

Comment
Add comment · Show 2
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 Owen-Reynolds · Jan 25, 2021 at 04:37 AM 0
Share

A single mesh? I think all of the usual solutions involve multiple meshes and playing with the shader layer

avatar image mattanmohel Owen-Reynolds · Jan 25, 2021 at 05:26 AM 0
Share

As it stands right now it's one mesh. I'm starting out small though, I'll probably separate bigger meshes in the future. Though there has to be a way to set the rendering order of quads in a mesh, otherwise that would entail each quad being an individual mesh

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by Eno-Khaon · Jan 25, 2021 at 09:23 AM

In most circumstances, when you have a transparent-capable shader for your mesh, the lowest-index vertices will draw on top of the higher-index vertices of a single mesh. I reversed the order I generated vertices in a dynamic mesh a few weeks ago for this very reason.

(Drawing a mesh based on faded-to-opaque gradient vertex colors, the faded portions would draw on top of opaque, so I reversed the vertex order to draw from the opaque end first, toward the faded end)

By contrast, an opaque shader type will instead sort more reliably by depth.

As a general rule, transparent shaders will draw a mesh like this to save on draw calls. A single draw call for a single mesh is far more sane than an indeterminate number of them (i.e. per triangle?).

Comment
Add comment · Show 2 · 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 Bunny83 · Jan 25, 2021 at 10:14 AM 0
Share

I'$$anonymous$$ a bit confused if you are talking about object sorting or per triangle sorting. Unity does not do per triangle sorting within a single mesh. The rendering order within a mesh is deter$$anonymous$$ed by the order of the triangles / primitives within the mesh. The vertex order is irrelevant as triangles could be made up of arbitrary vertices.


So when you procedurally generate a mesh with quads, just changing the order of the triangles / quads in the triangle / index buffer should be enough. Though of course spatial overlap could still cause issues when you use a shader that performs depth tests and writes to the depth buffer. Old isometric games did not use the depth buffer at all. they controlled everything with the rendering order.

avatar image Eno-Khaon Bunny83 · Jan 25, 2021 at 10:52 AM 1
Share

Ah, whoops. I did forget to think that part through as I typed it out. By reversing vertex order in my own experiments, I effectively reversed triangle order by extension, so that would make perfect sense to be the more important element here (It was easier to reverse vertex order than just triangles due to how I organized and used that data anyway).

At any rate, the question specifically addresses self-overlapping within a single mesh, and my own experiments I related were based around each of a 3D-space and UI-space mesh generation at a single depth, where self-overlapping rules varied depending on shader properties.

Considering the manner in which rendering rules can change (in Unity, at least) with multiple meshes (Z-fighting, for example), it's important to also distinguish why the rules could/would be different when a mesh overlaps itself. Granted, the shader will still control the final appearance, where the triangle order can influence it in the case of self-overlap.

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

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

Related Questions

What order are a mesh's triangles rendered in? 0 Answers

How do I apply a tilesheet to a procedural mesh and prevent bleeding? 0 Answers

How do you use submeshes correctly? 3 Answers

3D Terrain or Mesh Grid 1 Answer

UV Tiling/repeat 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