- Home /
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?
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.
Ok thanks, I will look into translating the surface shader part to a vertex/fragment setup
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!
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.
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;
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]}
}}
}
}
Your answer
Follow this Question
Related Questions
Shader with zwrite, shadows and alpha (special alpha) 2 Answers
Cutout Shader getting Opaque when turning alpha off and on again 1 Answer
How should I add an alpha mask AND an alpha multiplier into a shader? 0 Answers
how to make simple unlit shader for rgba points? 0 Answers
Multiply Shader with Alpha 0 Answers