Objects in RenderTexture render with black alpha value

I’ve come across a problem that I believe came up in the latest update, but I cannot be sure.

My RenderTexture from the camera has an alpha channel that is completely black, even though there are completely opaque objects (with diffuse shader applied) that is rendered into it. How can I get the RenderTexture to have an alpha channel that reflects what is really rendered? For example, If I have a diffuse sphere in the camera’s view, I want the alpha channel to be white where the object is.

If you have a reference to something you don't need to reference it again. What you need to look into more is the RPCTargets.All flag, as that's what's invoking your functions on the players.

2 Answers

2

The problem is that most of Unity’s shaders do not write to Alpha channel at all. They have:

ColorMask RGB

in them. I’ve had the same problem when rendering icons that should have alpha written, and rather than change all the shaders, I just render them a second time with a replacement shader that writes to the alpha, thus siloetting the object. The problem gets worse when you want to draw transparent stuff.

I guess that makes sense. I'm curious why Unity decided to change this to RGB from RGBA. Is there some sort of performance benefit to not rendering the alpha?

I don't think it's a recent change. I noticed it at least in 3.2. There would be a small performance advantage on some hardware. Personally, it seems a wrong optimization, but I'm no expert in Shader costs.

Someone wrote here that at least one of the cell-phone GPUs uses hardware scalars instead of Vector4s. If so, a big 25% (speed and memory?) increase for them. Well, unless they have their own shaders?

I have the same problem in 4.3 unity. Any solutions without replacing shaders? or at least some code of replacing shader?

This post may be what you need:
http://forum.unity3d.com/threads/2065-Render-Texture-Alpha?p=23802&viewfull=1#post23802