Why I couldnt control alpha in Surface shader?
# pragma surface surf Lambert alpha:fade
this code make my Sones look like the picture! But my objects couldn't transparency if I take out alpha:fade from this code.
Please could somebody help me? Here's my code:
Shader "Custom/Transparent" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Cutoff("Cutoff", Range(0,1)) = 0.5
}
SubShader {
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType"="Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha:fade
sampler2D _MainTex;
fixed4 _Color;
float _Cutoff;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = _Color.a;
clip(c.a - _Cutoff);
}
ENDCG
}
FallBack "Diffuse"
}
Answer by fguinier · Sep 30, 2015 at 08:27 AM
Hi hasayomo717
the pragma alpha:fade is the actual way to active blending mode in Unity. If you dont provide it in your shader the object will be renderered in the opaque pass and alpha blending / transparency wont be possible.
So to recap :
alpha:fade -> object is part of the blended render pass. Blending with current target is available.
no alpha:fade -> object is part of the opaque render pass. Blending is not possible (set top copy), however you can still use clip to do alpha testing.
Please note that the opaque render pass is more efficient by design, especially in the deferred rendering path.
Some documentation links: Surface shaders doc & Unity Rendering paths
Have a good day
Florent
Answer by keeperkai2 · Mar 14, 2016 at 06:35 AM
If you want to use Blend SrcAlpha OneMinusSrcAlpha Then you just add alpha or alpha:blend option to the surface shader pragma line If you would like to specify your own way of blending, like you could in Unity 4 surface shaders, simply use the "keepalpha" option and: Blend [whatever setups you want to do]
Answer by tuanpham · Mar 30, 2018 at 02:06 AM
Add alpha to #gragma like this
#pragma surface surf NoLighting alpha
Alpha will work