- Home /
Question by
Shifty-Geezer · Jul 15, 2017 at 04:21 PM ·
rendertexturealphaimage effects
Does alpha blending work on image effects?
I've two cameras rendering my background and foreground separately, and want to composite them with an image effect. This is working except that the alpha value for the foreground provided as 'src' in the OnRenderImage() is always 1, despite setting the camera's clear flags to (0,0,0,0).
static const fixed4 _yellow = fixed4(1, 1, 0, 1);
half4 frag_composite(v2f_img i) : SV_Target {
float4 s;
s = tex2D(_MainTex, i.uv);
s = lerp(s, _yellow , s.a);
return s;
}
ENDCG
Subshader {
Pass { // 0, quarter size
ZTest Always Cull Off ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert_img
#pragma fragment frag_composite
ENDCG
}
}
private void OnRenderImage(RenderTexture src, RenderTexture dest){
Graphics.Blit(src, dest,shader_compositor);
}
This just draws _MainTex without drawing yellow in the transparent background.
Comment
Answer by Shifty-Geezer · Jul 15, 2017 at 06:40 PM
Alpha does work. I was starting from someone else's example script that was outdated. Still runs and compiled but is different from a new Image Effect created in Unity.