- Home /
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.
Answer by Waz · Aug 11, 2011 at 11:37 PM
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 ins$$anonymous$$d 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?
Answer by Molix · Aug 11, 2011 at 11:09 PM
This post may be what you need: http://forum.unity3d.com/threads/2065-Render-Texture-Alpha?p=23802&viewfull=1#post23802
Your answer

Follow this Question
Related Questions
Shader to render RenderTexture plus alpha? 1 Answer
How do you get a rendertexture with the camera's alpha onto a GUItexture? 1 Answer
Alpha values not blending in RenderTexture 2 Answers
Transparent shader: final alpha value wrong 2 Answers
Unity RenderTexture displays transparency when the front-most sprite contains alpha 0 Answers