- Home /
Z-priming alpha-per-vertex
I'm using the MeshParticleRenderer from asset-store, which renders all particles together as one mesh. It is able to set color-animation on vertex-base, and by using the custom shader it is able to do correct color animations. However, transparency problems and wrong render orders appear because of the Z-write alpha problem. A solution would be Z-priming, as I added in this shader. However, Z-priming pass only puts "full black" in the z-buffer. If a particle would fade in and out, the particle immediately turns black (non-transparent) and then starts fading in the color. When fading out, it first fades out to black (non-transparent), then immediately disappears.
Is there any way I can make the Z-prime pass use the alpha-per-vertex values?
Shader "Internal/ParticleVertex" {
Properties {
_MainTex ("Texture", 2D) = "white" {}
_BumpMap ("Texture", 2D) = "bump" {}
_Color ("Main Color", Color) = (1,1,1,1)
_SpecColor ("Specular Color", Color) = (1.0, 1.0, 1.0, 1.0)
}
SubShader {
// Zprime Frontfaces
Pass {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "LightMode" = "Always"}
zwrite on Cull off
colormask 0
}
// Front Faces
Tags {"Queue"="Transparent" "RenderType"="Transparent" }
CGPROGRAM
#pragma surface surf BlinnPhong vertex:vert alpha
struct Input {
float2 uv_MainTex;
float4 vertexColour;
};
void vert (inout appdata_full v, out Input o)
{
o.vertexColour = v.color;
}
sampler2D _MainTex;
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
o.Albedo *= IN.vertexColour.rgb;
o.Alpha = tex2D (_MainTex, IN.uv_MainTex).a;
o.Alpha *= IN.vertexColour.a;
o.Specular = 0.2f;
o.Gloss = 1.5f;
}
ENDCG
}
Fallback "Transparent/Diffuse"
}
Your answer
Follow this Question
Related Questions
Transparent Vertex Shader Error 1 Answer
Transparent shader: final alpha value wrong 2 Answers
[Unity5]how to change alpha by using shader. 1 Answer
Unity Fog Shader with Alpha Change 0 Answers