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 sotirosn · Jun 06, 2016 at 03:41 PM · transparent shaderztest

Can I use both alpha and depth to test for pixel rendering?

So I am making a game with many many semi-transparent objects. There is no definite order in which these objects will be stacked. It seems the Ztest Lequal is stopping the object from being drawn at all if it is behind another transparent object and if I use Ztest Always then it draws even behind opaque objects. AlphaTest seems to do nothing maybe because I am using vertex and fragment shaders. Is there a way to do something like 'If pixel is behind an opaque pixel then don't draw, otherwise blend'? I think there should be a way to do this because the pixel already drawn should have an alpha and depth value right? And the pixel to be drawn also has these, so just compare both the alpha and depth. Is this possible?

Comment
Add comment · Show 6
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 tanoshimi · Jun 06, 2016 at 04:51 PM 0
Share

As far as I can tell, you should get the behaviour you want from ZTest Lequal, ZWrite On, and "Queue" = "Transparent". If this isn't the case, you may want to post the shader you're using.

avatar image sotirosn tanoshimi · Jun 06, 2016 at 04:55 PM 0
Share

No because all objects are in the transparent queue. So one may or may not be drawn first or last. If a object that is farther away is drawn first then great, otherwise ZTest Lequal fails and it is not drawn at all.

I am using the Hard Surface Pro transparent shaders that I modified to work with Unity 5.0. https://www.assetstore.unity3d.com/en/#!/content/724

avatar image tanoshimi sotirosn · Jun 06, 2016 at 05:04 PM 0
Share

That's the reason to use the Transparent queue: "this render queue is rendered after Geometry and AlphaTest, in back-to-front order" - http://docs.unity3d.com/$$anonymous$$anual/SL-SubShaderTags.html

Show more comments
avatar image Glurth · Jun 06, 2016 at 05:16 PM 0
Share

I think @tanoshimi has the right idea: selecting the right queue and Ztest should get it working for you. But if you have some special situation that is not covered by these options, you can look at using the stencil buffer in your shaders. " 'If pixel is behind an opaque pixel then don't draw, otherwise blend'? " If you draw the opaque pixel, with a shader of your choice, you can use the "stencil" bit in the opaque shader to specify the pixel should not drawn with subsequent transparent shader calls. Of course, those "subsequent transparent shader calls" will need to include code that specifically checks the stencil bit. http://docs.unity3d.com/$$anonymous$$anual/SL-Stencil.html Edit: sorry, I keep calling it the stencil BIT rather than the stencil BUFFER- probably because that the way I usually USE it ;)

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

44 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

Related Questions

Certain Materials visible behind objects 0 Answers

Unity Occlusion unable to recognize Occludee and Occluder? 1 Answer

Transparent shader render issue/glitch 0 Answers

Glow Outline effect 0 Answers

Problem combining standard shader with image effects on ios 8 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