- Home /
Alpha transparency not displaying, using SSE with Unity 4.2
I'm using the latest version of SSE with Unity 4.2, and I'm trying to create a shader with transparency loaded from the alpha channel of the diffuse. I'm using a Splat to copy the alpha channel (Splat set to W) and plugged that in to Alpha, but the result is not displaying transparency.
I've also set the Render Type and Queue to Transparent. I heard that SSE was having some problems with Unity 4 but I get completely overwhelmed looking at the shader file and really don't know where to look to see if the alpha isn't getting connected somewhere.
Here is the code:
Shader "TransparentSpecSeparated"
{
Properties
{
_Color("Color(RGB) Transparency(A)", 2D) = "gray" {}
_Spec("Spec", 2D) = "black" {}
_Gloss("Gloss", Range(0,1) ) = 0.5
}
SubShader
{
Tags
{
"Queue"="Transparent"
"IgnoreProjector"="False"
"RenderType"="Transparent"
}
Cull Back
ZWrite On
ZTest LEqual
ColorMask RGBA
Fog{
}
CGPROGRAM
#pragma surface surf BlinnPhongEditor vertex:vert
#pragma target 2.0
sampler2D _Color;
float _Gloss;
sampler2D _Spec;
struct EditorSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
half4 Custom;
};
inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha;
return c;
}
inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot ( lightDir, s.Normal ));
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular*128.0);
half4 res;
res.rgb = _LightColor0.rgb * diff;
res.w = spec * Luminance (_LightColor0.rgb);
res *= atten * 2.0;
return LightingBlinnPhongEditor_PrePass( s, res );
}
inline half4 LightingBlinnPhongEditor_DirLightmap (EditorSurfaceOutput s, fixed4 color, fixed4 scale, half3 viewDir, bool surfFuncWritesNormal, out half3 specColor)
{
UNITY_DIRBASIS
half3 scalePerBasisVector;
half3 lm = DirLightmapDiffuse (unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
half3 lightDir = normalize (scalePerBasisVector.x * unity_DirBasis[0] + scalePerBasisVector.y * unity_DirBasis[1] + scalePerBasisVector.z * unity_DirBasis[2]);
half3 h = normalize (lightDir + viewDir);
float nh = max (0, dot (s.Normal, h));
float spec = pow (nh, s.Specular * 128.0);
// specColor used outside in the forward path, compiled out in prepass
specColor = lm * _SpecColor.rgb * s.Gloss * spec;
// spec from the alpha component is used to calculate specular
// in the Lighting*_Prepass function, it's not used in forward
return half4(lm, spec);
}
struct Input {
float2 uv_Color;
float2 uv_Spec;
};
void vert (inout appdata_full v, out Input o) {
float4 VertexOutputMaster0_0_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_1_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_2_NoInput = float4(0,0,0,0);
float4 VertexOutputMaster0_3_NoInput = float4(0,0,0,0);
}
void surf (Input IN, inout EditorSurfaceOutput o) {
o.Normal = float3(0.0,0.0,1.0);
o.Alpha = 1.0;
o.Albedo = 0.0;
o.Emission = 0.0;
o.Gloss = 0.0;
o.Specular = 0.0;
o.Custom = 0.0;
float4 Tex2D0=tex2D(_Color,(IN.uv_Color.xyxy).xy);
float4 Tex2D1=tex2D(_Spec,(IN.uv_Spec.xyxy).xy);
float4 Splat0=Tex2D0.w;
float4 Master0_1_NoInput = float4(0,0,1,1);
float4 Master0_2_NoInput = float4(0,0,0,0);
float4 Master0_7_NoInput = float4(0,0,0,0);
float4 Master0_6_NoInput = float4(1,1,1,1);
o.Albedo = Tex2D0;
o.Specular = _Gloss.xxxx;
o.Gloss = Tex2D1;
o.Alpha = Splat0;
o.Normal = normalize(o.Normal);
}
ENDCG
}
Fallback "Diffuse"
}
Your answer
Follow this Question
Related Questions
How do you setup Depth Bias Alpha for Shaders? 0 Answers
Strumpy Shader Editor Alpha Issues 2 Answers
Strumpy Shader Editor: Transparency Issues 0 Answers
Alpha not displaying when changed in code, unless changed manually in the inspector 0 Answers
Fading in/out SVGs without showing the half-transparent SVG-layers 1 Answer