RenderTexture Alpha Channel

Hi

I am trying to render alpha channel for transparent objects in RenderTexture. However I cannot make this work.
It looks like the alpha channel is not being written correctly.

I’ve found some topics talking about it but I didn’t find the solution.
http://forum.unity3d.com/threads/126750-Camera-that-displays-the-alpha-channel?highlight=rendertexture+alpha
http://forum.unity3d.com/threads/108008-Particle-RTT-Alpha-blending?highlight=rendertexture+alpha

I’ve attached a simple project where I show 3 cubes with very simple shaders rendered by a camera that shows colored or alpha channel image. I am using the shaders that Unity make available here: http://unity3d.com/download_unity/builtin_shaders.zip

The example project : 885978–33082–$RenderTextureAlpha_Assets.rar (12.3 KB)

If I do not change alpha channel in cube shaders, everything looks good. But, if I try to make a cube transparent, it does not work. The alpha channel rendered by the camera does not show the cube transparent. Also, even the cubes that have alpha channel rendered they look wrong, since there is an object (a plane, in this case) with alpha=1 behind the cubes.

So, my question is: what am I doing wrong? Is there some trick to make alpha works with RenderTextures?

Any help will be welcome.

Thanks in advance

885978–33082–$RenderTextureAlpha_Assets.rar (12.3 KB)


any help?

This could be because transparent shaders don’t write to the z buffer unless modified to. This is just a wild guess.

This is the shader I am using.

Shader "Test/Transparent-Diffuse" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}

SubShader {
	Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
	LOD 200

	ZWrite On
	ColorMask RGBA

	CGPROGRAM
	#pragma surface surf Lambert alpha

	sampler2D _MainTex;
	fixed4 _Color;

	struct Input {
		float2 uv_MainTex;
	};

	void surf (Input IN, inout SurfaceOutput o) {
		fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
		o.Albedo = c.rgb;
		o.Alpha = c.a;
	}
	ENDCG
	}

	Fallback "Transparent/VertexLit"
}

After insert ZWrite ON the result was this. The cube disappeared.
I really don’t know how to make transparency work on Unity

nothing…

This is my exact problem too… seems alpha blending has some problem with render texture in 2019.1. I’m using LWRP, and no matter what shader I’m using… (I’m mean from built ins)

I found an old shader which could work, but it’s not compatible with new LWRP. Can someone help me to “port” this?

Shader "Mobile/Particles/Alpha Blended1" {
Properties {
    _MainTex ("Particle Texture", 2D) = "white" {}
}
Category {
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    Blend SrcAlpha OneMinusSrcAlpha
    Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
 
 
    BindChannels {
        Bind "Color", color
        Bind "Vertex", vertex
        Bind "TexCoord", texcoord
    }
 
    SubShader {
        Pass {
            SetTexture [_MainTex] {
                combine texture * primary
            }
        }
    }
}
}

The weird thing, that with built in Unlit/Transparent shader on rendertexture material shows right in editor’s game window. My problem is that alpha isn’t showing when I build the project. (nor windows or mac platform)