Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Julien-Lynge · Oct 05, 2011 at 10:22 PM · depth-bufferrenderqueuerenderorder

Rendering Order Revisited

I know that there are plenty of questions out there related to rendering order:

  • http://answers.unity3d.com/questions/14752/forcing-a-gameobject-to-the-highest-depth-closest.html

  • http://answers.unity3d.com/questions/8220/rendering-order.html

and more closely related to my issue

  • http://answers.unity3d.com/questions/11594/how-do-i-specify-the-render-order-of-gameobjects.html

However, I'm either misunderstanding this whole concept, or I'm doing something wrong, because I just can't get it to work at all.

What I want to do is: make sure that a certain object / material / shader is rendered on top of everything else in the scene. That is to say: set the shader to a queue sometime after all the other geometry is rendered, clear the depth buffer, and then render the object so that it appears 'written over' the rest of the scene. That way, no matter what other objects get between it and the camera it will always be drawn on top.

I know that this can be done with multiple cameras, but we run into the same problems as the last example above: trying to manage a whole bunch of cameras, framerates dropping, etc. From other folks' statements (e.g. the top example above that talks about drawing a gizmo that is inside a mesh object) it sounds like what I'm trying to do should be possible, but I've tried changing the shader tags, the renderQueue of the material, and everything else I can think of, and nothing seems to have an effect on the depth buffer.

Does the queue actually do what I'm trying to do here, or if not is there another way to do it at any level (shader, object, camera) without resorting to one camera for each object?

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
1
Best Answer

Answer by KvanteTore · Oct 06, 2011 at 11:59 AM

Even if use set the render queue, it will still do depth testing, and therefore not draw your object if something is closer to the camera. To achieve what you want, I believe you can disable zbuffer testing by setting

 [ZTest Always][1]

as well as a sufficiently high renderqueue in your shader.

Of course, this will only work if your mesh is simple enough to not have any overdraw artifacts.

Another (untested) approach would be to do a two pass render, where the first pass has

 ZTest Always 
 ZWrite On
 ColorMask 0

The second pass has

 ZTest LEqual
 ZWrite On

and renders the object normally

The effect of the first pass would be to "clear" the zbuffer where you want your object to be drawn and the second pass to actually draw the object

[1]: http://unity3d.com/support/documentation/Components/SL-Pass.html

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 Julien-Lynge · Oct 07, 2011 at 08:46 PM 0
Share

Thanks $$anonymous$$vanteTore

I did a bit of poking around on ZTest and found these great tutorial clips, that expand on what you've said here:

http://www.burgzergarcade.com/tutorials/game-engines/unity3d/unity-ios-shaderlab-tutorial-9-ztest

avatar image remyb · Nov 14, 2016 at 11:07 AM 0
Share

Thanks for the tip!

To be able to use the gameobjects renderQueue i also had to create two custom shaders both for the object that i wanted to be shown in front and the object that would be shown behind, even though the main object was sometimes in 3d space behind it.

The shader for the object that would be shown at the back at all times had ZWrite Off in the pass.

Then it was able to use the renderQueue.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Control render order of geometry besides queues 1 Answer

How do I specify the render order of GameObjects? 2 Answers

Combining multiple layers and water 0 Answers

Camera depthbuffer question. 0 Answers

Rendering to DepthTextureMode.Depth 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