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
8
Question by Novodantis 1 · Nov 24, 2009 at 10:06 AM · renderinggraphicsqueuerenderqueuez-depth

Rendering Order

How would I go about changing the order an object is rendered to the screen? I have a crosshair sprite that is drawn -120 units down the Z axis of the player ship, but I'd like it to be rendered after everything else on the scene so it is always on top.

Note that, due to the camera following the ship smoothly and not exactly, I cannot put the crosshair on the GUI as it will be very inaccurate.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
9
Best Answer

Answer by Kuba · Nov 24, 2009 at 10:13 AM

In your shader use the appriopriate tag that defines the rendering order (subshader tags):

Tags {"Queue" = "Overlay" }
Comment
Add comment · Show 4 · 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 Novodantis 1 · Nov 26, 2009 at 12:45 PM 0
Share

Thanks. I shall have to look into shaders a little more.

avatar image CiberX15 · Dec 20, 2013 at 10:59 PM 0
Share

Could someone post an example, how was this resolved? I have tried both setting the objects: renderer.material.renderQueue = 4000; and also creating a custom shader that uses: Tags { "Queue" = "Overlay" } and neither of these methods worked on their own nor in concert. I got no compile errors but the item continues to be rendered behind other geometry.

avatar image ChricKCK · May 23, 2014 at 05:24 PM 3
Share

Changing the rendering order does not necessarily mean that geometry won't occlude later render passes. In fact, it may actually lead to the opposite. Geometry drawn earlier will block areas of the screen if it writes to the depth buffer and the later passes do a depth test (ZTest) to deter$$anonymous$$e if it should draw or not.

To make sure that an object always draws, use a shader which has ZTest turned off.

avatar image faraz · Sep 03, 2014 at 06:51 PM 0
Share

Thanks for the help man :) *unity2diy*

avatar image
13

Answer by yoyo · Jan 06, 2011 at 07:49 PM

No need to modify the shader, you can set Material.renderQueue instead.

[EDIT] In my project, I've added a render queue enum that I use to manage queues project-wide. Various bits of code around the project use this enum to set material.renderQueue. I use the convention of indenting my in-between layers. (A lot of materials stay at their defaults, this is just when I need procedural control.)

// RenderQueue provides ID's for Unity render queues. These can be applied to sub-shader tags, // but it's easier to just set material.renderQueue. Static class instead of enum because these // are int's, so this way client code doesn't need to use typecasting. // // From the documentation: // For special uses in-between queues can be used. Internally each queue is represented // by integer index; Background is 1000, Geometry is 2000, Transparent is 3000 and // Overlay is 4000. // // NOTE: Keep these in numerical order for ease of understanding. Use plurals for start of // a group of layers. public static class RenderQueue { public const int Background = 1000;

     // Mid-ground.
     public const int ParallaxLayers = Background + 100;       // +1, 2, 3, ... for additional layers

     // Lines on the ground.
     public const int GroundLines = Background + 200;

     public const int Tracks = GroundLines + 0;
     public const int Routes = GroundLines + 1;
     public const int IndicatorRings = GroundLines + 2;

 public const int Geometry = 2000;


 public const int Transparent = 3000;

     // Lines on the screen. (Over world, but under GUI.)
     public const int ScreenLines = Transparent + 100;

 public const int Overlay = 4000;

}

Comment
Add comment · Show 3 · 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 Novodantis 1 · Jan 11, 2011 at 05:55 PM 0
Share

What sort of number would I need to make something on top of all other objects in the scene? A really large number? Would 1024 be sufficient or is it much more than necessary? Cheers, this looks like an interesting prospect.

avatar image yoyo · Jan 11, 2011 at 06:16 PM 0
Share

Click through to this link and it explains where things go by default, which should help you figure out where to insert your stuff. Bigger numbers are on top. http://unity3d.com/support/documentation/Components/SL-SubshaderTags.html

avatar image yoyo · Jan 11, 2011 at 06:18 PM 0
Share

(wow, just realized how old your question is! :-)

avatar image
5

Answer by Jaap Kreijkamp · Nov 24, 2009 at 11:40 PM

Although you already got a good answer, I was wondering why you dismiss placing the crosshair using the GUI layer (or a sprite manager on a orthographic camera). With:

Camera.WorldToScreenPoint(position : Vector3) : Vector3

you could get the screen coordinates of your target and get pinpoint precision placing it on screen without worrying about scaling and lighting effects you could get when placing a mesh in the scene (although both are solvable).

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 Novodantis 1 · Nov 26, 2009 at 12:53 PM 0
Share

I did also consider linepicking afterward, although it seemed a lot more complex in my head and this actually makes it look very simple. I will experiment with both methods, I think! Cheers.

avatar image monohe · Jan 05, 2013 at 02:00 AM 0
Share

This really helps me out. Thank you guys!

avatar image
1

Answer by KevinBKnaus · Jan 16, 2015 at 05:38 PM

If you can create a new layer in the Cross Hair Inspector's Sprite Renderer you can then assign the Crosshair the new layer and it should render "last", and that means in the foreground.

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

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem with rendering? 0 Answers

Strange Render Order Issue 0 Answers

Blank screen on Android 0 Answers

Unity 5 Custom Deferred shader 0 Answers

Why is this issue occurring with my models? 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