I noticed the Render To Texture automatically builds an alpha channel from the grayscale. Is there a way to turn this off? And is there a way to get a “true” alpha of the rendered scene?
Another thing I’m curios about is how hard it would be to script/create a grayscale Zbuffer or depthmap image from the rendered scene. This seems like it would be hard, but could be really cool for manipulating image effects down the road.
I’m wondering the same thing – I want the view in the Render to Texture to be 100% opaque and not have any transparency (otherwise, it doesn’t really do the whole “arena cam” thing properly).
Does it? There’s no code in Unity to do that; and in all cases I’ve seen the alpha of a render texture is whatever is rendered into alpha.
Right now you could render several camera-facing planes, with depth test on and blending the results. More planes = better accuracy, but slower. Or wait until we add depth texture support to Unity (but that will require hardware that can actually do this of course).
Render texture alpha contains whatever is rendered into alpha. So if you make sure all your objects render “white” into alpha, then you get white. Alternatively, you could render a full-screen quad with a shader that writes only to alpha channel. Sort of an image effect that doesn’t do anything interesting, just sets alpha to white everywhere.
…or you don’t actually need having 100% opaque alpha in your render texture If you’re just putting that texture onto some object, just use a shader that does not do alpha blending!
Another solution is not to use a render texture nor a GUITexture at all. Just render it as a normal, but set the camera viewport rect and layer, so it is rendered into a square above the main camera.
Thanks everybody for all this help. I observed the Render Texture camera images being transparent on a GUITexture in the FPS tutorial project. When I tried the same technique with our actual project, for whatever reason, I didn’t get the partial alpha.
I appreciate knowing there’s a back-door way to assign a material to a GUITexture, though.
I had tried the simple viewport thing, but really wanted a fixed pixel size and position for the camera’s view, since it’s a GUI element and needs to be layered with other GUITextures.
Aras, look at my problem again, please. I want to render my character for produsing “real” projector shadow.
I can’t change original instantiated materials on my character. How can I render him only in alpha chanel?
Or may be other trick?
May be recolor Diffuse to black? But how?
Hi, I have a camera with a target renderTexture. It works perfectly until I have a transparent/diffuse shader on any objects it sees. They won’t show up at all in the renderTexture. The material that displays the camera on a plane is also set to transparent/diffuse, could this be the problem?
Thanks for the info. I ended up using a RenderTexture camera with a black background with this custom shader on a plane, to act as though the background of the camera was transparent.
No need for any scripts attached to the camera. Recap.
Camera with black background.
Camera points to render texture.
Mask texture: white for showing, transparent for hidden.
Material points to the custom shader.
Material has _MainTex as the RenderTexture.
Material has _Mask as the mask
Plane uses the Material to display the RenderTexture with a mask
I may be mistaken but this approach will not work if you have alpha in your textures that is greater than 0 and less than 1. Is there still no way to make the Camera render alpha into a RenderTexture?
Hi, I had a similar problem and I used Aras approach.
I need a texture with a runtime generated RGB (using render to texture) and an Alpha channel with specular information.
So I make the render to texture and then on post render I draw a quad just in alpha channel using a specular texture.
It is working in my computer, but it doesn’t work in my Android!!
Any idea about what is happening?
The result texture is used with a Mobile/BumpedSpecular material, in the computer it works but in the Android device it seems a full white specular.
I’m pretty sure the problem is in the shader used to render the alpha quad because I’ve seen that tga textures with alpha are well interpreted by the bumpedSpecular shader also in Android.
This is the shader that I’m using to render the alpha quad
Hi,
I’m having a similar problem in that I had a camera rendering to a texture in my project. The character (an on-screen guide) used to only have a diffuse material and the render texture worked perfectly (i.e. in the alpha channel it was white where the character was, and black where they weren’t) which enabled me to overlay it on the GUI. I’ve since added a specular shader to the character, but that has now changed the alpha of the render texture to show the specular values of the character (so his shiny stuff is opaque, but matt parts are transparent). I tried Aras’s 1st script above, but that has made the entire render texture opaque. Is there a way of keeping the specular material on my character, but getting the render texture to be a more traditional alpha channel (i.e. white where there is geometry and black where there isn’t)?