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 /
avatar image
0
Question by CaptainFailCode · Feb 05, 2014 at 04:00 PM · shadertransparencyalpha

Alpha Transparency Shader Issue

So having some issues with my simple shader I've put together, it's really basic, and I just would like alpha transparency working correctly.

Here's my code:

 Shader "Test/AlphaFINAL" 
 {
     Properties 
     {
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader 
     {
         Pass 
         {
             //Render Back Faces
             Cull Front
             ZWrite Off
             Blend SrcAlpha OneMinusSrcAlpha
             CGPROGRAM
             #pragma vertex vert_img
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             uniform sampler2D _MainTex;
 
             float4 frag(v2f_img i) : COLOR {
                 return tex2D(_MainTex, i.uv);
             }
             ENDCG
         }
         Pass
         {
             //Render Front Faces
             Cull Back
             ZWrite On
             Blend SrcAlpha OneMinusSrcAlpha
             CGPROGRAM
             #pragma vertex vert_img
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             uniform sampler2D _MainTex;
 
             float4 frag(v2f_img i) : COLOR 
             {
                 return tex2D(_MainTex, i.uv);
             }
             ENDCG
         }
         
     }
 }

and here's the result:

alt text

Now after a lot of reading and the such, I get this is down to the draw order, in fact that's how I got to this result in the first place. I understand that I have now drawn the back first and as it comes forward I am blending the colours of the foreground and background together.

The issue here is it doesn't entirely seem to be using the alpha the bits of the model that are supposed to be "solid" for example the face and is just adding the back over the front.

This is where I'm stuck. I want it to respect alpha transparency with blending, but then not just show everything with an alpha of > 0 through itself.

I tried turning zwrite on for the second pass, this fixes that to a degree, but then you end up with these errors.

alt text

alt text

So. Any help or enlightenment on how to fix this would be amazing as I'm kinda stuck on my learning about shaders because of it. scurries off to try and find the answer himself..

Sorry for asking tbh, I really love to work things out on my own, but... this one just stumps me and it's probably a dead simple fix.

Thank you in advance.

draworder.png (445.8 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 SunnyChow · Feb 06, 2014 at 02:24 AM

I suggest you separate it into 2 shaders: one for solid part, one for transparent.

Unity would try to render transparent objects from back to front, but it doesn't sort every triangles individually. Therefore it's possible that a triangle in back renders over a triangle in front (transparent shader don't do z-write so it can't z-test itself).

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

18 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

Related Questions

How to make a submesh from part of my character 1 Answer

Adding Alpha-Transparency to Shader 0 Answers

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

Alpha self illum. shader issue 0 Answers

Transparent / Vertex Lit Ignore Sides 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