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 /
This question was closed Dec 17, 2017 at 06:12 PM by Bunny83 for the following reason:

The question is answered, right answer was accepted

avatar image
13
Question by Essential · Jan 04, 2014 at 03:53 PM · shadertransparencyordering

How to fix transparent rendering problem

I'm getting incorrect rendering on objects that both are using the Unity transparent/diffuse shaders. If I move the camera back slightly the foliage gets obscured behind the tree trunk.

alt text alt text

I've tried researching this but I can't find what seems to be the accepted solution. Some unity forum posts say to change the transparent ordering in the shaders, some say to turn on Z-Write buffering for all shaders, some suggest changing the camera settings, some say it's a bug to do with occlusion culling. What is the actual problem and what is the correct solution in this circumstance?

Comment
Comments Locked · Show 1
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 · Dec 17, 2017 at 06:12 PM 0
Share

Since the question is answered and the images of the question are no longer available (due to external hosting) I'll close this question and lock the comments to prevent further bumping

3 Replies

  • Sort: 
avatar image
49
Best Answer

Answer by Hoeloe · Jan 04, 2014 at 08:33 PM

The problem is due to how transparent objects are sorted in Unity. Usually, objects are drawn using the z-buffer, which draws a depth image as it renders the scene. This ensures that only the closest pixel is drawn, so everything appears in the right order. The problem occurs with transparent objects, or, more precisely, semi-transparent pixels. When objects are semi-transparent, they cannot be accurately written into the depth buffer. This is because the z-buffer makes the assumption that only one object will need to be drawn in any one pixel on the screen, in exchange for extremely fast sorting. Semi-transparent objects require multiple pixels to be drawn at the same point, and so they have to be drawn either before or after the rest of the image. Naturally, this produces some sorting errors, because per-pixel sorting, as found in the depth buffer, is not feasible. In Unity, the sorting method just takes the centre point of the mesh, and assumes that the entire mesh lies at the same depth value. The practical upshot of this is that if the centre of your transparent object goes behind another object, then the entire object will be rendered behind it.

Now that we've discussed the cause, let's talk about solutions. There are, in fact, a few possible ones, though they all involve trade-offs. I'll discuss 3 here:

  1. Cutout Shaders. Cutout shaders solve this problem by applying a filter to the texture, giving every pixel a boolean value: visible or not visible. This allows complex shapes to be drawn, and since no pixel is semi-transparent, the depth buffer to be used. The trade-off here is with smoothness - you will lose the nice, soft edges you get with transparent objects. This is the most accurate solution, and for small, distant, or high-res textures, this is definitely the best one.

  2. Segmented Meshes. This is a little more difficult to get right, and is only an approximation. The idea is that instead of having one large mesh, you separate it into several small ones, each carrying a part of the texture. Since the transparency sorting is on a per-mesh basis, this will allow the problem to become rarer, as each part of the object can be sorted individually. The trade-offs here are in performance, and difficulty of implementation.

  3. Z-Writing. Another option is simply to write to the z-buffer anyway. This does work, but does produce some artefacts. Any other semi-transparent object drawn will either always be above, or always be behind, the object you're drawing, meaning depth sorting between this object and other transparent ones will simply disappear. This is often a good solution if you will very rarely overlap objects, or if your object is against a surface such that no other transparent object will pass beneath it.

There are more possible solutions, but these are some of the more common ones. The reason you have so much trouble finding one solution is that there isn't one - there are several. Each has their benefits and their drawbacks, and it's up to you to decide which suits your needs best.

Comment
Comments Locked · Show 8 · 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 Essential · Jan 06, 2014 at 02:58 PM 0
Share

Thanks so much for the in-depth explanation Hoeloe. Either cut-out shaders or Z-Writing seems to be my best options. Forest scenes with transparent bushes like $$anonymous$$e have been done a hundred times in games, what approach do you think you would personally go for in this situation?

avatar image Essential · Jan 06, 2014 at 03:09 PM 0
Share

I think it's important to mention I am targeting iOS with this game. And I'm aware cutout (alpha test) is not as good as alpha blend... cutout looks good, but do you know if Z-writing will be better for iOS performance?

avatar image Hoeloe · Jan 06, 2014 at 03:17 PM 1
Share

Cutout is easily the best option for performance, and the one I would go for.

avatar image Essential · Jan 06, 2014 at 04:11 PM 0
Share

Thanks again :)

avatar image Wolfram · Sep 07, 2015 at 02:30 PM 6
Share

There are two more possibilities to consider:

4) renderQueue: if we are talking about different meshes (i.e., not within a single mesh), you can control the render order of these objects (or more precisely: of each material) using the shader/material property "renderQueue", which can be set via script. This will group all objects with the same queue and render them from low to high. (for example, opaque objects use 2000 as default, transparent objects use 3000, and so on. Disadvantage: each unique renderQueue value means an additional render pass/drawcall.

5) Z-pre-pass: you can modify your shader code to create an adittional first pass which does nothing except rendering the object(s) exclusively in the Z-buffer. See http://wiki.unity3d.com/index.php?title=AlphaVertexLitZ Advantage: transparent objects use z-Buffer information, and for complex meshes (which are unsortable) you can get smooth transitions especially when fading/switching between transparent and opaque. Disadvantages: You can no longer look "inside" semi-transparent objects, and other transparent objects behind the one you want to render will be invisible. Also, as it is an additional pass, it might be more expenstive (depending heavily on the shape of your objects).

Show more comments
avatar image
37

Answer by vollchecker · Apr 14, 2016 at 12:16 PM

simply change the render queue: - select Object Material - change view to Debug Mode (Inspector Window top right drop down menu) - change Custom Render Queue value for example 3000 => 3100 - now your object will be rendered before other transparent objects

Comment
Comments Locked · Show 6 · 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 Johannski · May 03, 2016 at 06:54 PM 0
Share

Thanks a lot, I totally forgot about that possibility, this solves my problem really well!

avatar image blastoformity7 · Jul 08, 2016 at 04:09 AM 0
Share

thanks so much.

avatar image Phantomb · Nov 11, 2016 at 06:40 AM 0
Share

This solved my problem as well. (I had one larger tile-based mesh that forms a terrain/map in 3D, and wanted a plane the size of a tile to be able to draw over one of the tiles of the big mesh, semi transparent) $$anonymous$$any thanks.

avatar image kalibcrone · May 22, 2017 at 01:29 PM 0
Share

Thanks, this helped a ton! I was able to set my particle's shader to 2900 so that they are behind my other transparent objects. Question though: The render queue value is not available for Unity's Standard shader with render mode set to Transparent. Is there another way to set the render queue value for this type of shader? Thanks!

avatar image kevinlakhani · Jun 05, 2017 at 07:23 PM 0
Share

Thanks, this makes so much sense and helped me a ton.

Show more comments
avatar image
0

Answer by JEsteras · Apr 07, 2017 at 03:04 PM

Thnxx so much for the help!!!

In my case I had an open, top-down look into an apartment-like area. Since I wanted "sunlight" to come in through the windows I created a transparent plane to "block" the sunlight and prevent it from seeping in through the open roof, allowing it to shine through the windows...and THAT is why the Occlusion effect was NIOT rendering...as soon as I eliminated the transparent plane everything came back to normal...so THNXX!!! :)

Comment
Comments Locked · 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

Follow this Question

Answers Answers and Comments

32 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

Related Questions

Transparency ordering within a single mesh using the Standard shader 0 Answers

Transparency / depth problem 0 Answers

Changing material color´s alpha in self iluminated shader 1 Answer

transparency shader faster then diffuse... 0 Answers

Receiving Shadows On a Tranparent Shader 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