- Home /
Mobile Additive surface shader
Hi, I'm trying to translate the default Mobile Particles Additive shader to a surface shader. The problem is, particles don't obey the color modifiers from the particle system. Its alpha is always one, and they're always white, both in shuriken and legacy systems. This is my code, I think I'm missing some calcs to pass to Albedo:
Shader "Mobile/SurfAdd" {
Properties {
_MainTex ("Particle Texture", 2D) = "white" {}
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha One
Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
BindChannels {
Bind "Color", color
Bind "Vertex", vertex
Bind "TexCoord", texcoord
}
CGPROGRAM
#pragma exclude_renderers flash
#pragma surface surf Lambert noforwardadd
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
I hope you can help me!
It's been a while since I've modified a shader, but you are setting the SrcAlpha to One in the shader. Don't you mean One$$anonymous$$inusSrcAlpha?
Try adding "alpha" to the surface shader pragma:
#pragma surface surf Lambert noforwardadd alpha
See if that works!
The surface shader documentation page has more details on all the options the surface shader pragma accepts.
Supernat, that doesn't set SrcAlpha to One, it multiplies the source pixel by SrcAlpha and the destination pixel by 1 and adds them together, resulting in a premultiplied alpha additive blend. Setting DstFactor to One$$anonymous$$inusSrcAlpha would result in alpha blending ins$$anonymous$$d. Refer to the ShaderLab blending documentation for more details.
Shoot, I read the question too fast. I thought he wanted alpha blending in my head. $$anonymous$$y mistake, thanks for correcting that.
Adding alpha to the pragma doesn't fix it. The sprite gets all dark actually, and it still isn't affected by the particle system color/alpha modifier...
if you look at what "alpha" actually does( just select the shader and read the compiled vertex/fragment shader), you will realize that it only adds: Blend SrcAlpha One$$anonymous$$inusSrcAlpha to the forward base pass. I also ran into this problem, but so far no solution, I read the unity 5 built in shaders and all the ones using custom Blend are written as vertex/fragment shaders ins$$anonymous$$d of surface shaders... This would work in Unity 4 though... so it seems that they didn't consider this case(people would want to specify their own blending in surface shaders) when implementing the surface shader compiler in Unity 5..