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 /
  • Help Room /
avatar image
2
Question by Basyan · May 30, 2016 at 10:50 AM · shadertransparencytransparentgradient

Gradient + Transparent

Hello. Previously, this did not come across. The gradient shader, add transparency map on the similarity of the standard "Unlit / Transparent". I would be grateful for your help.

 Shader "Unlit/LinearGradient"
 {
         Properties {
         _TopColor ("Color1", Color) = (1,1,1,1)
         _BottomColor ("Color2", Color) = (1,1,1,1)
     }
         SubShader
         {
                 Pass
                 {
                         CGPROGRAM
                         #pragma vertex vert
                         #pragma fragment frag
                         
                         #include "UnityCG.cginc"
 
                         fixed4 _TopColor;
                         fixed4 _BottomColor;
 
                         struct v2f {
                                 float4 position : SV_POSITION;
                                 fixed4 color : COLOR;
                         };
 
                         v2f vert (appdata_full v)
                         {
                                 v2f o;
                                 o.position = mul (UNITY_MATRIX_MVP, v.vertex);
                                 o.color = lerp(_TopColor,_BottomColor, v.texcoord.y );
                                 return o;
                         }
 
                         fixed4 frag (v2f i) : SV_Target
                         {
                                 float4 color = i.color;
                                 color.a = 1;
                                 return color;
                         }
                         ENDCG
                 }
         }
 }
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
3

Answer by Namey5 · May 31, 2016 at 06:30 AM

 Shader "Unlit/LinearGradient"
 {
     Properties{
         _TopColor("Color1", Color) = (1,1,1,1)
         _BottomColor("Color2", Color) = (1,1,1,1)
         _MainTex ("Main Texture", 2D) = "white" {}
     }
         SubShader
     {
         Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
         Pass
         {
             ZWrite Off
             Blend SrcAlpha OneMinusSrcAlpha
 
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             #include "UnityCG.cginc"
 
             sampler2D _MainTex;
             float4 _MainTex_ST;
 
             fixed4 _TopColor;
             fixed4 _BottomColor;
             half _Value;
 
             struct v2f {
                 float4 position : SV_POSITION;
                 fixed4 color : COLOR;
                 float2 uv : TEXCOORD0;
             };
 
             v2f vert (appdata_full v)
             {
                 v2f o;
                 o.position = mul (UNITY_MATRIX_MVP, v.vertex);
                 o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
                 o.color = lerp (_TopColor,_BottomColor, v.texcoord.y);
                 return o;
             }
 
             fixed4 frag(v2f i) : SV_Target
             {
                 float4 color;
                 color.rgb = i.color.rgb;
                 color.a = tex2D (_MainTex, i.uv).a * i.color.a;
                 return color;
             }
             ENDCG
         }
     }
 }

Just change the alpha value for each colour as a multiplication for the texture's alpha.

Comment
Add comment · Show 6 · 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 Basyan · May 31, 2016 at 08:50 AM 0
Share

Thank you for your response, your script is useful but I meant another.alt text

forum.jpg (352.5 kB)
avatar image Namey5 Basyan · May 31, 2016 at 09:07 AM 0
Share

Ah, ok. I'll fix it for you. I thought you meant you wanted the gradient as transparency.

avatar image Basyan Namey5 · May 31, 2016 at 09:24 AM 0
Share

Thank you very much

avatar image Basyan · Jun 04, 2016 at 10:55 AM 0
Share

In Unity editor shader is displayed normally. Android and ios assembly disappears transparency map. What could be the problem?

avatar image Namey5 Basyan · Jun 04, 2016 at 12:51 PM 0
Share

Try checking the material queue. This is a common bug in Unity 5 that I think may be your problem. At the top of the inspector, there should be a little padlock. Next to that is a down arrow. Click this, then "Debug". Select your material and find the material queue. This should be 3000. If it isn't change it. If it is, I'm not entirely sure on the problem.

avatar image Basyan Namey5 · Jun 07, 2016 at 05:44 AM 0
Share

Thanks, did not know about this option, partly helped solve the problem.

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

74 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

Related Questions

How can I add alpha channel to this shader and how can I make the object to be transparent ? 1 Answer

A problem with a shader to make a window transparent 0 Answers

vertex shader with alpha channel 0 Answers

Circular Bar Transparent gradient 0 Answers

Transparency using Scene Color node not layering multiple transparent objects over each other 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