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
1
Question by radonthetyrant · Apr 04, 2015 at 08:33 PM · shaderblendingvertexcoloralphablend

Shader question: Alpha value of 0 not entirely transparent

Hi

I'm writing a shader for terrain surface, which supports multitexture blending according to the local vertex color. Now, the alpha value of the vertex color should render areas of the texture completely transparent, revealing surfaces below if needed, like a water stream for example.

So far this works out well, save from the transparent part. Here a screenshot:

alt text

the left half of the material has an vertex color alpha value of 0, the right side has an alpha value of 255. Behind are some test objects and the problem is that I can't get the blending right. I want the left area to be invisible completely, not just a bit translucent.

Here is the shadercode:

 Shader "fornax/test/VertexMultiBlend" {
 
     Properties {
         _MainTex0 ("Layer0", 2D) = "white" {}
         _MainTex1 ("Layer1", 2D) = "white" {}
         _MainTex2 ("Layer2", 2D) = "white" {}
     }
     SubShader {
         Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "ForceNoShadowCasting"="True" }
         LOD 200
        
         CGPROGRAM
         #pragma surface surf Lambert alpha
        
         sampler2D _MainTex0;
         sampler2D _MainTex1;
         sampler2D _MainTex2;
  
         struct Input {
             float2 uv_MainTex0;
             float4 color: Color; // Vertex color
         };
  
         void surf (Input IN, inout SurfaceOutput o) {
             half4 c0 = tex2D (_MainTex0, IN.uv_MainTex0);
             half4 c1 = tex2D (_MainTex1, IN.uv_MainTex0);
             half4 c2 = tex2D (_MainTex2, IN.uv_MainTex0);
             o.Albedo = IN.color.r * c0.rgb + IN.color.g * c1.rgb + IN.color.b * c2.rgb; // vertex RGB
             o.Alpha = IN.color.a; // vertex Alpha
         }
         ENDCG
     }
     FallBack "Diffuse"
 }
 

I am not very vell with shaders and I can't find how I adjust the blending type, if that's what I need to do anyway. Any help is apreciated!

// edit: To add onto this: I experimented with the renderqueue and rendertype a lot. Most sense to me makes rendertype="TransparentCutout" and renderqueue="Background" since the ground is always the first rendered object, nothing needs to be displayed behind it, save from other background shaders of the same type. I couldn't see any difference tho which confuses me. All Rendertypes and queues seem to create the same result.

Current status: (Note how the plane with the grass texture is in front of those 3 objects but rendered behind.)

alt text

sw2.png (456.4 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 saykou · Jan 11, 2019 at 02:34 PM 0
Share

I have the same issue ... :/ have you found a solution?

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by WILEz1975 · May 16, 2015 at 03:45 PM

Same problem...

    Tags {
      "Queue"="Transparent"
      "IgnoreProjector"="false"
      "RenderType"="Transparent"
    }
      Blend SrcAlpha OneMinusSrcAlpha // use alpha blending
      ZWrite Off // don't write to depth buffer 

.... ....

  void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
 
             
             o.Emission = c.rgb*_Color.a;
           
             o.Alpha =0 ; //Try to set 0
         }

I put o.Alpha =0 but does not work. It is not completely transparent (invisible). Why?

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
0

Answer by LexDeKogel · Sep 01, 2019 at 12:14 AM

Late answer but multiplying the rgb values by the alpha value seems to completely solve the problem. So c.rgb *= c.a; for a color c.

I still don't entirely understand why it works this way.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Blending 2 textures using vertex COLOR 0 Answers

Vertex color blending shader 1 Answer

Problem with texture blending and vertex color shader for iOS 1 Answer

shader for light replacement blending, instead of additive blending? 0 Answers

Blending/Fading Camera & Pixel Shader 1.1 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