- Home /
Getting alpha information in shader
To give some context, this is the effect I am trying to accomplish for a particle system:
I'm modifying the Alpha Blended shader for Particles to accomplish this. Here is the texture I'm using and here is the relevent code:
fixed4 frag (v2f i) : COLOR
{
float4 col = 2.0f * i.color * tex2D(_MainTex, i.texcoord);
return (col.a > _Threshold) ? _TintColor : float4(0,0,0,0);
}
_TintColor here is the desired color (yellow in the example above). Currently, I'm using the col.a (which is the alpha of the output color) to compare to the threshold. This however does not work because this alpha value is only for the one particle, not the alpha of the overlapped particles, so all I get is circles of solid colors, which is not what I need.
Now what I do need is a way to get the alpha value of the overlapped particles to correctly implement the method described in the demonstration mentioned above. Is this possible?
Answer by ScroodgeM · Jul 19, 2012 at 07:06 PM
you cannot get an alpha of previous pixels due to shader's internal mechanism. you just able to control blending options using buil-in property
http://docs.unity3d.com/Documentation/Components/SL-Blend.html
but, if you really want the previous color, look here:
http://docs.unity3d.com/Documentation/Components/SL-GrabPass.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613073300im_/https://answers.unity.com/themes/thub/images/avi.jpg)