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
2
Question by Jjules · Feb 04, 2017 at 05:09 AM · shadermaterialbufferz-bufferz-depth

Unity 5 Standard Shader Transparent render order issues

I have a problem (obviously) with Unity 5's standard shader. I have a model that i'm trying to fade in and out, but the render order is messed up:

alt text

I know semi-transparent objects aren't compatible with the z buffer (or something like that) I know as a result, Unity's fade/transparent shader modes have this problem quite often. I know I should avoid semi-transparent objects whenever I could

The issue is in this particular case, there's no way around it. I can guarantee all the meshes I'm doing this with will be one piece, and the entire mesh will always have the same transparency, but I need the order to be correct.

When in the opaque rendering mode, the issue is gone, as you might expect: alt text

I need the model to look exactly like this, but in the fade rendering mode with an alpha of 1

I'm good to hear any C# explanation, but I'm a complete shader noob. So if you explain any shader stuff, please talk to me like im a 5th grader lol.

Also, if there is a way around it, like I dunno, a canvas group or a camera trick or something, that would be even better

Thank you!

render-issues.png (62.0 kB)
render-nonissues.png (56.0 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JaredHD · Feb 04, 2017 at 05:27 AM

I had a very similar problem a few months ago. Here is my topic and it has the solution to what i did. Basically you have to change the shader to a transparent shader, Then once you've finished with that, set the shader back. (No need to make any new shaders)

To reset the Paper plane use:

 private void RevertTransparent(GameObject g)
  {
      for (int i = 0; i < g.renderer.materials.Length; i++)
      {
          if (g.renderer.materials[i].name == "Optimized Bark Material (Instance)")
              g.renderer.materials[i].shader = 
                             Shader.Find("Nature/Tree Creator Bark");
          else if (g.renderer.materials[i].name == 
                             "Optimized Leaf Material (Instance)")
              g.renderer.materials[i].shader = 
                             Shader.Find("Nature/Tree Creator Leaves Fast");
          else
                  g.renderer.materials[i].shader = Shader.Find("Default/Diffuse");
              g.renderer.materials[i].SetColor("_Color", new Color(1,1,1));
      }
      for (int i = 0; i < g.transform.childCount; i++)
          SetTransparent(g.transform.GetChild(i).gameObject);
  }

You'd need to change the name of the shader below also. On top of that you'll come to a bug that when in a stand alone player (Built game) the shaders might turn pink. You'll need to tell unity to add the shaders in a build game because it doesn't. Go to Unity-Edit-Project settings-Graphics and you'll see the "Always included Shaders".

TADA! :P

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 Jjules · Feb 04, 2017 at 05:01 PM 0
Share

Thanks for the response! After playing around with the script a bit, I realized I might not have explained the problem as well as I could. The Plane's alpha is at 1 at the moment. The problem is that even at an alpha of 1, the sorting is still wrong. That's my bad, and I updated the question. This ugly overlap shouldn't happen when the object is set to be fully opaque, and I have no clue how to fix it

avatar image JaredHD Jjules · Feb 05, 2017 at 09:37 AM 0
Share

What shader are you using? if you are using the Transparent shader I'd suggest you change between that shader when you need the plane to fade and the Standard shader when you need it to be fully opaque.

avatar image CarpeFunSoftware · Feb 05, 2017 at 01:22 PM 1
Share

Transparency draw issues are USUALLY between different meshes so that's what I think you're saying...multiple meshes and render order.

$$anonymous$$y admittedly limited understanding is as follows: If it's multiple meshes (the usual transparency issue)...you have a draw order problem DUE TO OBJECT CENTERS. Unity sorts transparent draws by the object's center position and uses that depth to clip against the z-buffer (it has to use SO$$anonymous$$E depth value to clip with, even if it doesn't set a new value itself). It will draw your meshes in order, back to front for transparent and IF you can make the mesh centers be in the proper place for your desired order it should draw them in the proper order. Note you could have too many meshes with odd centers or, not enough meshes...lol. They don't sort by polygon, they sort by mesh. So maybe breaking it up into different meshes is what's needed, maybe one for each plane on the plane ;) . Regardless, you have to think about your models and their centers and what gets drawn in what order. Because you're using the transparent queue. Of course with backface culling on, any polygons with normals not facing the camera will cull (I think, not 100% for transparent if culling is still on.) There's info in the shader tutorials that talks about transparency and backface culling and lighting, etc. It starts to get complex rather quickly with various issues.

I hope this makes sense. You shouldn't have to swap shaders out just to get a mesh to fade (no offense to previous answers, that's a creative solution, but ideally you shouldn't HAVE to do that.) It looks to be just what you said...a sorting issue. So the render order is wrong. Check models for their center. ID$$anonymous$$ if it's using bounding box center, or mesh's origin. I've had cases with transparent queue object where I had to move the object's center somehow to get it to "fit" into the scene properly. Anyway, think about the meshes and their centers and the back-to-front draw order for some clues.

Another option may be to dynamically combine your meshes into one? https://docs.unity3d.com/ScriptReference/$$anonymous$$esh.Combine$$anonymous$$eshes.html ID$$anonymous$$ what the result will be and I hope that's not a wild-goose chase.

Not really sure what's going on since I don't have your models, so I can't do a test case and help more, sorry. Also, you may have issues with rendering in the scene itself (clipping with scene objects outside the plane meshes) so check into that too. Same issue really, zbuffer clipping vs object center. I hope I don't mislead you and this gives you some ideas, or at least things to search for. So think about it and take this as food for thought. :)

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

94 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

Related Questions

Material doesn't have a color property '_Color' 4 Answers

How come edititng "_Glossiness" through script doesn't work? 1 Answer

Represent Land 3D Area End 0 Answers

Glowing material/shader ? 1 Answer

Find all materials using a specific 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