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 smirlianos · Mar 30, 2014 at 07:12 PM · shaderalphamaptransparentchannel

How can I add alpha-channel to this shader?

Hello,

I have this shader that does not support alpha map. How can I modify it so I can adjust the alpha channel so as to be transparent?

Thanks!

 Shader "-smn-/GlowingBorder" {
     Properties {
         _ColorTint("ColorTint", Color) = (1,1,1,1)
         _MainTex("Main Texture", 2D) = "white" {}
         _BumpMap("Normal Map", 2D) = "bump" {}
         _RimColorOuter("Rim Color Outer", Color) = (1,1,1,1)
         _RimColorInner("Rim Color Inner", Color) = (1,1,1,1)
         _RimPowerOuter("Rim Power Outer", Range(0.0, 7.0)) = 3.0
         _RimPowerInner("Rim Power Inner", Range(0.0, 20.0)) = 3.0
     }
     SubShader {
         Tags { "RenderType" = "Opaque" }
         
         
         CGPROGRAM
         #pragma surface surf Lambert
 
         struct Input {
             float4 color : COLOR;
             float2 uv_MainTex;
             float2 uv_BumpMap;
             float3 viewDir;
         };
         
         float4 _ColorTint;
         sampler2D _MainTex;
         sampler2D _BumpMap;
         float4 _RimColorOuter;
         float4 _RimColorInner;
         float _RimPowerOuter;
         float _RimPowerInner;
         
         void surf (Input IN, inout SurfaceOutput o) {
             IN.color = _ColorTint;
             o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb * IN.color;
             o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
             
             half rimOuter = 1.0 -saturate(dot(normalize(IN.viewDir), o.Normal));
             half rimInner = saturate(dot(normalize(IN.viewDir), o.Normal));
             o.Emission = (_RimColorOuter.rgb * pow(rimOuter, _RimPowerOuter)) + (_RimColorInner.rgb * pow(rimInner, _RimPowerInner)) ;
         }
         ENDCG
     } 
     FallBack "Diffuse"
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by CHPedersen · Mar 30, 2014 at 08:54 PM

Three steps:

  1. Add objects rendered with this shader to the Transparent queue by adding "Queue"="Transparent" to the subshader's Tags list.

  2. Add "alpha" to the surface function declaration, after the lighting function declaration, so the line becomes "#pragma surface surf Lambert alpha"

  3. Actually set the alpha to something in the surface function, i.e. set o.Alpha = whatever you want.

I have done these modifications and used the _ColorTint's alpha channel in the example. Then the shader becomes this:

 Shader "-smn-/GlowingBorder" {
     Properties {
        _ColorTint("ColorTint", Color) = (1,1,1,1)
        _MainTex("Main Texture", 2D) = "white" {}
        _BumpMap("Normal Map", 2D) = "bump" {}
        _RimColorOuter("Rim Color Outer", Color) = (1,1,1,1)
        _RimColorInner("Rim Color Inner", Color) = (1,1,1,1)
        _RimPowerOuter("Rim Power Outer", Range(0.0, 7.0)) = 3.0
        _RimPowerInner("Rim Power Inner", Range(0.0, 20.0)) = 3.0
     }
     SubShader {
        Tags { "Queue"="Transparent" "RenderType" = "Opaque" }
  
  
        CGPROGRAM
        #pragma surface surf Lambert alpha
  
        struct Input {
          float4 color : COLOR;
          float2 uv_MainTex;
          float2 uv_BumpMap;
          float3 viewDir;
        };
  
        float4 _ColorTint;
        sampler2D _MainTex;
        sampler2D _BumpMap;
        float4 _RimColorOuter;
        float4 _RimColorInner;
        float _RimPowerOuter;
        float _RimPowerInner;
  
        void surf (Input IN, inout SurfaceOutput o) {
          IN.color = _ColorTint;
          o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb * IN.color;
          o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
           o.Alpha = _ColorTint.a; // For example. Could also be the alpha channel on the interpolated vertex color (IN.color.a), or the one from the texture.
         
          half rimOuter = 1.0 -saturate(dot(normalize(IN.viewDir), o.Normal));
          half rimInner = saturate(dot(normalize(IN.viewDir), o.Normal));
          o.Emission = (_RimColorOuter.rgb * pow(rimOuter, _RimPowerOuter)) + (_RimColorInner.rgb * pow(rimInner, _RimPowerInner)) ;
        }
        ENDCG
     } 
     FallBack "Diffuse"
 }
Comment
Add comment · Show 3 · 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 smirlianos · Mar 31, 2014 at 12:26 PM 0
Share

Thanks!

Do I make similar steps to make it self-illu$$anonymous$$ too? (Not be affected by light actually)

avatar image CHPedersen · Mar 31, 2014 at 02:19 PM 0
Share

If it shouldn't be affected by light at all, there are a great deal of unnecessary computations in that shader. For this reason, it would undergo heavy modification to excempt it from being lit at all. For example, you would remove the bump map, since that texture contains surface normals, the purpose of which is to interact with lighting.

Please see this question for an example of a surface shader that disables lighting, but note in particular the point about writing old-school vertex/fragment shaders, if you want the most efficient option for an unlit shader. :) Surface shaders are really mostly about plugging into Unity's built-in lighting engine, so for an unlit shader, the multiple passes they compile into are overkill.

avatar image smirlianos · Mar 31, 2014 at 03:42 PM 0
Share

The normal maps are there to have the rim light effect on different parts of the texture. It is not needed for the light bumps it is supposed to create!

avatar image
1

Answer by marouane01 · May 21, 2017 at 03:06 AM

about week now trying to add some alpha to this shade any idea

 Shader "Custom/Stancel Object" {
     Properties {
         _Color ("Color", Color) = (1,1,1,0)
         _MainTex ("Albedo (RGB)", 2D) = "white" {}
         _Glossiness ("Smoothness", Range(0,1)) = 0.5
         _Metallic ("Metallic", Range(0,1)) = 0.0
     }
     SubShader {
             Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
         LOD 200        
             Stencil{
         Ref 1
         Comp NotEqual
         }
         CGPROGRAM
         // Physically based Standard lighting model, and enable shadows on all light types
         #pragma surface surf Standard fullforwardshadows
 #pragma surface surf Lambert alpha
         // Use shader model 3.0 target, to get nicer looking lighting
         #pragma target 3.0
 
         sampler2D _MainTex;
 
         struct Input {
             float2 uv_MainTex;
         };
 
         half _Glossiness;
         half _Metallic;
         fixed4 _Color;
 
         void surf (Input IN, inout SurfaceOutputStandard o) {
             // Albedo comes from a texture tinted by color
             fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
             // Metallic and smoothness come from slider variables
             o.Metallic = _Metallic;
             o.Smoothness = _Glossiness;
             o.Alpha = c.a ;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }

Comment
Add comment · Show 1 · 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 jojizaidi · Apr 01, 2018 at 11:04 AM 0
Share

I've been trying to add alpha to the exact shader. Were you able to get it to work?

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

23 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

Related Questions

Z-priming alpha-per-vertex 0 Answers

Transparent terrain shader not working 2 Answers

How to add an alpha channel to Unity Toon shader? 2 Answers

Adding Alpha-Transparency to Shader 0 Answers

Tinted alpha 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