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 Oruji · Dec 29, 2015 at 04:49 PM · shadertransparent shadertransparent texture

Sorting semi-transparent pixels

I know similar questions have been asked before, but I can't find answers that are applicable to my problem.

I have an unlit cutout shader with a second pass that renders semi-transparent pixels.

It sorts the opaque pixels correctly, but the semi-transparent pixels often end up incorrect.

alt text

In this picture; everything is using the cutout shader with a semi-transparent pass. To the right you can see the semi-transparent pixels rendered correctly. To the left there is a semi-transparent white plane with the same shader behind the plant, as you can see the second pass (semi-transparent pixels) are rendered behind the white semi-transparent plane even though the plane is behind the plant.

Any idea how to fix this?

The shader looks like this:

 Shader "Unlit/AlphaTestBlend" {
     Properties{
         _Color("Main Color", Color) = (1, 1, 1, 1)
         _Cutoff("Base Alpha cutoff", Range(0,.9)) = .5
         _MainTex("MainTex", 2D) = ""
     }
 
         SubShader{
         Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
 
         Lighting off
         ZWrite on
         
         Pass{
         CGPROGRAM
 
 #pragma vertex vert
 #pragma fragment frag
 
 #include "UnityCG.cginc"
 
     struct appdata_t {
         float4 vertex : POSITION;
         float4 color : COLOR;
         float2 texcoord : TEXCOORD0;
     };
 
     struct v2f {
         float4 vertex : POSITION;
         float4 color : COLOR;
         float2 texcoord : TEXCOORD0;
     };
 
     sampler2D _MainTex;
     float4 _MainTex_ST;
     float _Cutoff;
 
     v2f vert(appdata_t v)
     {
         v2f o;
         o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
         o.color = v.color;
         o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
         return o;
     }
 
     float4 _Color;
     half4 frag(v2f i) : COLOR
     {
         half4 col = tex2D(_MainTex, i.texcoord);
         clip(col.a - _Cutoff);
         return col;
     }
         ENDCG
     }
         Tags{ "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
 
         ZWrite off
         Lighting off
 
         // Set up alpha blending
         Blend SrcAlpha OneMinusSrcAlpha
 
         Pass{
         CGPROGRAM
         #pragma vertex vert
         #pragma fragment frag
 
         #include "UnityCG.cginc"
 
     struct appdata_t {
         float4 vertex : POSITION;
         float4 color : COLOR;
         float2 texcoord : TEXCOORD0;
     };
 
     struct v2f {
         float4 vertex : POSITION;
         float4 color : COLOR;
         float2 texcoord : TEXCOORD0;
     };
 
     sampler2D _MainTex;
     float4 _MainTex_ST;
     float _Cutoff;
 
     v2f vert(appdata_t v)
     {
         v2f o;
         o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
         o.color = v.color;
         o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
         return o;
     }
 
     half4 frag(v2f i) : SV_Target
     {
         half4 col = tex2D(_MainTex, i.texcoord);
         clip(-(col.a - _Cutoff));
         return col;
     }
         ENDCG
     }
     }
 
     
     }

semi-transparent-pixel-sorting-issue.png (115.6 kB)
Comment
Add comment · 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 Oruji · Dec 29, 2015 at 09:31 PM 0
Share

I found another thread explaining that for the render queue in the shader to work I need to set the material render queue to -1, I tried that and managed to get the render queue in the shader to actually work. Which helps debugging.

I've successfully removed the artifacts seen in the image above by setting the second pass in the shader to Transparent+1, but when I tweak the render queue it always produces artifacts somewhere else.

And it's very inconsistent, one same mesh may have proper semi-transparent pixels on one side but no semi-transparent pixels on the other side.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oruji · Dec 30, 2015 at 08:28 AM

I have successfully eliminated all artifacts by using custom rendering queue in the material slot. It works but I'm interested in a better/automatic solution if anyone has any.

To adjust the custom rendering queue manually:

Set the inspector to debug, scroll down to the material component and find the "custom rendering queue" variable.

For my transparent passes I'm using values between 2000 and 3000 to manually sort the pixels.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

transparent mode does not work at alpha=255 1 Answer

How to cut or make transparent part of a mesh 0 Answers

How to make my brown circle transparent so i can see the green ground? 0 Answers

Standard Shader - Transparent/Fade Issue 6 Answers

2 sides-transparent shader ProblemA 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