• 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 dchen05 · Apr 09, 2013 at 09:46 PM · shaderalphaalpha-channelunlitsurfaceshader

Unlit Shader with alpha mask

I have a surface shader that has a main texture, and an alpha mask. (not just opacity value, but independent alpha mask that can be moved seperatly)

How can I get this to not interact with lights and be unlit?

 Shader "Custom/CanvasWithAlphaMask" {
     Properties {
        _MainTex("Base (RGB) Trans (A)", 2D) = "white" {}
        _Color ("Main Color", Color) = (0,0,0,0)
        _Stencil("Stencil Texture (RGB)", 2D) = "white" {}
     }
     Subshader {
        Tags {
          "Queue"="Transparent"
          "IgnoreProjector"="False"
          "RenderType"="Transparent"
        }

       Lighting Off //doesn't do anything

        CGPROGRAM
        #pragma surface surf Lambert alpha
          
          struct Input {
           float2 uv_MainTex;
          };
   
          half4 _Color;
          sampler2D _MainTex;
          sampler2D _Stencil;
          
            void surf (Input IN, inout SurfaceOutput o) {
             half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
             o.Albedo = c.rgb;
                o.Alpha = c.a - tex2D(_Stencil, IN.uv_MainTex).a ;
         }
        ENDCG
     }
 }

Putting Lighting Off before CGPROGRAM didn't work , I thought it might be that simple.

Alternatively, if its easier, is there a way to use non-surface shader to achieve the same effect?

Comment
Add comment · Show 4
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 The-IT664 · Apr 09, 2013 at 10:46 PM 0
Share

Just a thought, if lighting is applied in the vertex/fragment functions and the default functions apply lighting, it would explain why you are still getting lighting applied. Writing basic custom vertex/fragment functions would solve the problem if this is the case.

avatar image dchen05 · Apr 09, 2013 at 10:49 PM 0
Share

Ok thanks, I will look into translating the surface shader part to a vertex/fragment setup

avatar image OP_toss · Apr 09, 2013 at 11:20 PM 0
Share

In your subshader add the following:

 Lighting Off

This will disable lighting without having to manually write a vertex and fragment shader. Hope this helps!

avatar image dchen05 · Apr 09, 2013 at 11:26 PM 0
Share

Thanks @OP_toss, but that doesn't work for some reason. I read a similar question around here that had that as the answer, but no dice.

2 Replies

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

Answer by OP_toss · Apr 09, 2013 at 11:30 PM

Try this. Assign to emission instead of albedo. Albedo is for lighting.

instead of

 o.Albedo = c.rgb;

do

 o.Emission = c.rgb;
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
1

Answer by jason-yi-kai · Jun 19, 2013 at 11:52 PM

Hope this help

 Shader "Custom/Unlit/Transparent" {
 
 Properties {
 
     _Color ("Main Color (A=Opacity)", Color) = (1,1,1,1)
 
     _MainTex ("Base (A=Opacity)", 2D) = ""
 
 }
 
  
 
 Category {
 
     Tags {"Queue"="Transparent" "IgnoreProjector"="True"}
 
     ZWrite Off
 
     Blend SrcAlpha OneMinusSrcAlpha 
 
  
 
     SubShader {Pass {
 
         GLSLPROGRAM
 
         varying mediump vec2 uv;
 
         
 
         #ifdef VERTEX
 
         uniform mediump vec4 _MainTex_ST;
 
         void main() {
 
             gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
 
             uv = gl_MultiTexCoord0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
 
         }
 
         #endif
 
         
 
         #ifdef FRAGMENT
 
         uniform lowp sampler2D _MainTex;
 
         uniform lowp vec4 _Color;
 
         void main() {
 
             gl_FragColor = texture2D(_MainTex, uv) * _Color;
 
         }
 
         #endif      
 
         ENDGLSL
 
     }}
 
     
 
     SubShader {Pass {
 
         SetTexture[_MainTex] {Combine texture * constant ConstantColor[_Color]}
 
     }}
 
 }
 
  
 
 }
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

13 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

Related Questions

Shader with zwrite, shadows and alpha (special alpha) 2 Answers

Multiply Shader with Alpha 0 Answers

Cutout Shader getting Opaque when turning alpha off and on again 1 Answer

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

Unlit, Transparent and Slice Shader 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges