- Home /
custom Standard Shader alpha issues.
Sorry for the generic title but I'm having a hard time explaining this issue in a simple way. I've made a custom shader based on the standard lighting model, my goal being simply to animate the emission component of the shader. Everything works splendidly, except for the alpha, of all things.
My issue is that the alpha never really becomes fully transparent, even though it should be. The texture maps used have correct alpha, and even if I were to manually set the alpha to zero in the shader, I'd get the following result:
When viewed from an angle like the picture to the right, the issue is less prominent, dunno if this is a clue. To further eliminate possible culprits, all the lighting stuff for the mesh is turned off, lighting is turned off in the shader, and fog as well.
//
SubShader {
Tags {"Queue" = "Transparent" "RenderType" = "Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
Lighting Off
Fog {Mode Off}
Zwrite Off
LOD 200
CGPROGRAM
#include "UnityCG.cginc"
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard alpha
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
fixed4 _Color;
sampler2D _MainTex;
fixed4 _GlowColor;
sampler2D _GlowTex;
fixed _Speed;
fixed _Power;
fixed _Falloff;
fixed _Alpha;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutputStandard o) {
float4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
clip (c.a);
o.Albedo = c.rgb;
o.Alpha = c.a;
//o.Alpha = c.a * _Alpha;
//float4 e = tex2D (_GlowTex, IN.uv_MainTex);
//e.a = frac(e.a + -_Time) * c.a;
//o.Emission = (e.rgb * c.a + pow(e.a, _Falloff)) * _Alpha * _GlowColor;
}
ENDCG
//
Any ideas on how to tackle this?
Answer by Bikupan · Jun 25, 2015 at 11:14 AM
After some digging around I found the problem.
#pragma surface surf Standard alpha
should use alpha:fade instead. I'm not sure why the regular alpha mode didn't work properly, I don't see any reason why it shouldn't, but with alpha:fade it works.
I'm pretty sure the default alpha setting is premul, so it wouldn't go fully trans to allow for glass reflections, etc.
Your answer
Follow this Question
Related Questions
CG Shader: Setting output alpha changes RGB too 0 Answers
Add transparency to mask shader 1 Answer
Can anyone help me with reflective shader with fall off property? 0 Answers
Problem with lighting in CG Shader 1 Answer
Grab Pass alternative? Frag shader that applies alpha values behind it to itself. 1 Answer