• 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 Quantanaut · Jul 07, 2021 at 09:24 PM · shaderrenderingtransparencyopacity

Opaque object still being transparent glitch

I'm a bit new to Unity, and currently I'm working with multiple transparent objects using the "Transparent/Diffuse" shader, and I noticed that you can sometimes still see through objects even when the opacity is set to 1, depending on the angle the camera is facing. I still want the option for the objects to be transparent, so is there a way to fix this bug without simply using an opaque shader? Thanks! alt text

glitch.png (34.7 kB)
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

2 Replies

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

Answer by Quantanaut · Jul 08, 2021 at 08:30 PM

So, I managed to find a solution that works for me. All I needed to do was find the order I wanted my objects to be layered as (higher values will be rendered on top of lower values), set material.renderQueue = value; when creating the object (`value` being the render order number I prefer), and then making sure that whenever I replace the materials of one of these objects, I make sure to include newMaterial.renderQueue = oldMaterial.renderQueue;.

I didn't have to do this, but if someone wants to change the render order depending on where the camera is, they could have an update function that updates the materials of the objects with the new render order whenever the camera moves to a new location (say, on the other side of the objects when their ordering changes relative to the camera).

I'm not sure if this is the "proper" method, and it would get a bit cumbersome for a large amount of transparent objects scattered through a scene, but it works.

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

Answer by Eno-Khaon · Jul 08, 2021 at 06:16 AM

There are multiple stages involved in the rendering process. In terms of order-of-operations, a Shader that is *capable* of having transparency will be rendered after a Shader that only supports opaque objects.

The "Transparent/Diffuse" Shader supports transparency. Therefore, it does not render at the same time as a basic opaque shader, regardless of the opacity it's being drawn with.

Furthermore, transparent object ordering will generally be simplified by using the origin point of each GameObject to determine whether it's assumed to be closer or further away than others. By having multiple GameObjects in the same location, it's largely luck and coincidence that decides which ones render in front of which other ones.

All in all, the short answer is that there aren't really super-duper-simple ways of layering multiple transparent objects and getting them to always look the way you want them to. Mainly, this is to keep the rendering pipeline more efficient. If you had 1000 objects in the same location, all slightly different sizes, all carefully calculating which pixels are on top of which others, that's up to 1000 passes per pixel (or more, if the same logic held true for self-overlapping transparent meshes), which is woefully inefficient/computationally expensive.

Comment
Add comment · Show 1 · 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 Quantanaut · Jul 08, 2021 at 02:24 PM 0
Share

That makes sense, but would there be a way I can fix it for this case? I'm not working with many objects, so would there be some way I could manually tell the shader which object to render first / last so the inner layers will be properly hidden?

EDIT: I think my workaround will be to create a new custom shader copied from "Transparent/Diffuse" and set ZTest LEqual to ZTest Always, then manually change their position in the Rendering Queue. I'll update this when I try that. Currently I can't seem to find the Transparent/Diffuse shader in the Unity 2020 2020.3.12 built-in shaders file...

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

195 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 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

Customised shader script? 2 Answers

Depth texture override leaves black skybox 2 Answers

GrabPass and Transparent geometry 0 Answers

Banding Problem With Game View,Banding Problem With Game View URP 0 Answers

How to make transparent only colliding part of object? 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