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 topgun128 · Nov 16, 2016 at 04:41 AM · unity 5shadertransparencyalpha

Cant get Alpha Channel to Work with Custom Shader

Hey Guys

Im pretty new to Unity and still learning, so be gentle. Im currenty working through the brilliant hex map tutorial by Catlike Coding.

In part 1 we create our custom shader. Since Im planning to do something slightly different with my game I want to introduce transparency to my shader.

After trying to learn more about shaders with this tutorial, I have reduced my shader to this which still does the job:

 Shader "Custom/VertexColors" {
     SubShader{
         Tags{ "RenderType" = "Opaque" }
 
         CGPROGRAM
         #pragma surface surf Standard fullforwardshadows
         #pragma target 3.0
 
         struct Input {
             float4 color : COLOR;
         };
 
         void surf(Input IN, inout SurfaceOutputStandard o)
         {
             o.Albedo = IN.color;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }

I now want to add transparency to my shader. As I understand it if I want to change all cells to just be 50% transparent this should work:

 Shader "Custom/VertexColors" {
     SubShader{
         Tags{ "RenderType" = "Transparent" }
 
         CGPROGRAM
         #pragma surface surf Standard fullforwardshadows
         #pragma target 3.0
 
         struct Input {
             float4 color : COLOR;
         };
 
         void surf(Input IN, inout SurfaceOutputStandard o)
         {
             o.Albedo = IN.color;
             o.Alpha = 0.5;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }

But of course, this doesnt change anything. I have been working on this for hours now. Really looking forward to your help.

Lucas

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
1
Best Answer

Answer by Namey5 · Nov 16, 2016 at 04:42 AM

  Shader "Custom/VertexColors" {
      SubShader{
          Tags{ "RenderType" = "Transparent" }
  
          CGPROGRAM
          #pragma surface surf Standard fullforwardshadows alpha
          #pragma target 3.0
  
          struct Input {
              float4 color : COLOR;
          };
  
          void surf(Input IN, inout SurfaceOutputStandard o)
          {
              o.Albedo = IN.color;
              o.Alpha = 0.5;
          }
          ENDCG
      }
      FallBack "Diffuse"
  }

You have to actually enable blending for transparency to happen in a shader. In your case, because you are using a surface shader, you can simply add the 'alpha' keyword to the surface declaration.

Comment
Add comment · Show 7 · 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 topgun128 · Nov 16, 2016 at 07:05 AM 0
Share

Thank you for you help. I already tried this and my mesh just disappears. But since I assumed your solution has to be correct, I just realized when I place an object behind the tiles, it seems to work. Screenshot.

What do I have to change so that the tiles always render? I mean I also want them to render against the background.

best regards Lucas

1.jpg (41.1 kB)
avatar image Namey5 topgun128 · Nov 16, 2016 at 08:54 AM 0
Share
 //Change
 Tags{ "RenderType" = "Transparent" }
 
 //To
 Tags{ "RenderType" = "Transparent" "Queue"="Transparent" }
avatar image topgun128 Namey5 · Nov 16, 2016 at 04:17 PM 0
Share

Thank you again for your answer. Already tried that. Doesn't work. Doesn't change anything in fact. Are you sure it has to do with the order of compilation, and not something with the skybox? I mean I have absolutely no object in the back ground. I want the hex fields to render against the void basically.

best regards Lucas

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

All objects are getting transparent ? 1 Answer

Shader help (Animating Alpha values does not work on it!) 1 Answer

How do I add transparency to a cg vertex lit shader 2 Answers

Adding Alpha-Transparency to Shader 0 Answers

Transparent Diffuse Specular Normal Shader problem 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