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 Bentoon · Mar 27, 2020 at 04:30 AM · shadershaderstransparency

shader Transparency

Hello all I found a wonderful shader that mixes three colors but I need alpha transparency to work for the .png textures I have searched and tried to code no avail

Any Ideas

     Properties
     {
         _MainTex("Main Tex", 2D) = "tranparent" {}
         _Color("Color", Color) = (1.0, 1.0, 1.0, .0)
         _Color1("Color 1", Color) = (1.0, 0.5, 0.5, .0)
         _Color2("Color 2", Color) = (0.5, 0.5, 1.0, .0)
         _Rim("Rim", Float) = 1.0
         _Shift("Shift", Float) = 1.0
     }
 
     SubShader
     {
         Tags
         {
             "Queue" = "Geometry"
             "PreviewType" = "Sphere"
             "DisableBatching" = "True"
         }
 
         Pass
         {
             CGPROGRAM
             #pragma vertex Vert
             #pragma fragment Frag
 
             sampler2D _MainTex;
             float4    _Color;
             float4    _Color1;
             float4    _Color2;
             float     _Rim;
             float     _Shift;
 
             struct a2v
             {
                 float4 vertex    : POSITION;
                 float2 texcoord0 : TEXCOORD0;
                 float3 normal    : NORMAL;
                 float4 color     : COLOR;
                 
             };
 
             struct v2f
             {
                 float4 vertex : SV_POSITION;
                 float2 uv     : TEXCOORD0;
                 float3 normal : TEXCOORD1;
                 float4 color  : COLOR;
             };
 
             struct f2g
             {
                 float4 color : SV_TARGET;
             };
 
             void Vert(a2v i, out v2f o)
             {
                 o.vertex = UnityObjectToClipPos(i.vertex);
                 o.uv     = i.texcoord0;
                 o.normal = mul((float3x3)UNITY_MATRIX_IT_MV, i.normal);
                 o.color  = i.color * _Color;
                 
             }
 
             void Frag(v2f i, out f2g o)
             {
                 float rim = _Shift - pow(saturate(1.0f - normalize(i.normal).z), _Rim);
 
                 o.color = tex2D(_MainTex, i.uv) * lerp(_Color1, _Color2, rim) * i.color;
             }
             ENDCG
         } // Pass
     } // SubShader




Thanks !

~be

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 Namey5 · Mar 28, 2020 at 02:52 AM

 ...
 
 Tags
 {
     "Queue" = "Transparent"    //Set queue to sort transparencies properly
     "PreviewType" = "Sphere"
     "DisableBatching" = "True"
 }
  
 Pass
 {
     //Use regular transparent blending
     Blend SrcAlpha OneMinusSrcAlpha
 
     CGPROGRAM
     #pragma vertex Vert
     #pragma fragment Frag
 
 ...

Depending on what kind of shader it is there are a few ways of going about adding transparency, but for vertex/fragment shaders you can just add the correct alpha-blending tags in the shaderlab pass before the main shader. This is quite possibly the most asked question in regards to shaders in Unity, so if you're looking for more information you can just search for alpha-blending.

https://docs.unity3d.com/Manual/SL-Blend.html

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

199 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 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 my shader have a variable transparency 1 Answer

Silhouette overlay shader 0 Answers

Why does the 3D Text shader show specular at certain angles? 2 Answers

Shader Transparency issues 1 Answer

Plugging in screenPosition node`s A channel gives different result then plugging in an identical float value in shader graph. 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