Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Wasplay · Jul 31, 2019 at 05:19 PM · renderingshaderstransparencysorting layers

Models using transparent shader are overlapping themselves

Here's two examples :
Opaque : https://i.imgur.com/iaRX57X.png
Transparent : https://i.imgur.com/4fUtHVE.png
Seen from up :
Opaque : https://i.imgur.com/Sw2itEw.png
Transparent : https://i.imgur.com/8O1Hv2y.png
I need to have a shader compatible with Sorting Layers since my game is a mix of 2D and 3D, that's why I'm using the Standard transparent one

Any way to fix this issue ?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jul 31, 2019 at 06:25 PM

That's a common issue and no easy / cheap solution. First of all you should enable zWrite in your shader which transparent shaders most the time do not do. However depending on your model and if you want to see self occluded parts or not. The triangle of a mesh are usually rendered in order as they are defined in the mesh. This order is never changed.


Any kind of sorting happens on a per object basis. If you want to prevent any self overlapping for transparent shaders you would need a two pass approach. First just drawing into the depth buffer, second pass just drawing into the color buffer. That way only the closest visible surface of an object will be drawn.


Just like explained in the example here for the semi transparent shader.

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 Wasplay · Jul 31, 2019 at 08:47 PM 0
Share

ZWrite breaks the sorting layers.. :( I don't really understand what you wrote after that

avatar image
1

Answer by Lucinar · Jan 11, 2021 at 02:14 PM

In case someone search for this question like I just did, add following code into your shader:

 Blend SrcAlpha OneMinusSrcAlpha
 
             Stencil {
                  Ref 10
                  ReadMask 10
                  Comp NotEqual
                  Pass Replace
              }
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 krisventure · Sep 30, 2021 at 09:47 PM 0
Share

That worked. I've used the buit-in Legacy/Particles/Alpha blended shader downloaded from Unity download archive and simply added your lines and now I only see the nearest surface of the transparent object.

avatar image gregathee · May 19 at 11:54 PM 0
Share

Where exactly do you put this?

avatar image
0

Answer by contact_unity364 · Mar 03, 2021 at 01:37 PM

I found adding this to the "Transparent/Diffuse ZWrite" shader worked for me, not in a separate pass. Not an expert with shaders but was delighted my transparent scorch marks on the ground did not overlap each other cutting the others out, now they overlap nicely and fade into eachother.

 ZWrite On
 ColorMask 0

This is the full shader:

 Shader "Transparent/Diffuse ZWrite" {
     Properties{
         _Color("Main Color", Color) = (1,1,1,1)
         _MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
     }
     SubShader{
         Tags {"Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent"}
         LOD 200
        
         ZWrite On
         ColorMask 0
 
         // paste in forward rendering passes from Transparent/Diffuse
         UsePass "Transparent/Diffuse/FORWARD"
     }
     Fallback "Transparent/VertexLit"
 }


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

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

140 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

Related Questions

How to make make an object look like an Opaque but still have Alpha fading effect? 1 Answer

Can I draw Opaque geometry on top of Sprites, cheaply? 0 Answers

Standard shader's Fade rendering mode won't allow full opacity with a textured material 0 Answers

Rendering transparent objects back to back (HDRP Lit shader) 0 Answers

Make a complex object semi transparent without changing it 2 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