- Home /
How do you get a rendertexture with the camera's alpha onto a GUItexture?
I am looking for the most efficient way to:
Camera-render 3Dtext in front of a semi-transparent background polygon,
Bake this to a properly transparent texture and
Apply it into a GUItexture all at runtime.
Its easy to get a non-transparent camera rendering to a GUItexture. But none of the Clear Flags settings are providing the right result or they result in texture garbage. And if I used Texture2D.ReadPixels() as described in this Answer, how would I get the result to the GUI?
Done a lot of careful searching on forums and Answers, but no answers to this specific question.
--edit-- Here's an example screenshot of what I'm attempting. This is just a mocked up Photoshop file used as a GUItexture. I want to be able to build these question text objects dynamically, so I'm attempting to use a rendertexture from a camera that shoots the 3Dtext for the questions in front of their transparent poly backgrounds.
Any suggestions for clarifying this question to help find some answers?
I didn't get it. Do you want to have a kind of "lu$$anonymous$$ous advertising" with changing text and place it at a GUITexture? Why not the GUIText? Do you need it to be in a perspective view? Can you supply some picture or example? (bumped the question for you!)
Ok, I'll edit the question with a link to a screenshot. One moment
Why don't you use the GUI system to draw the questions, superposing a text box over the poly background? The city names should be done with 3D text, off course, since they are in perspective.
I'd like to be able to do 3D stuff (animate their depth, etc) with these text blocks. But that's a decent suggestion, thx.
Answer by aldonaletto · Jul 21, 2011 at 04:51 AM
Just to ilustrate the GUI possibilities, I created a simple scene using alpha blended DrawTexture:

I don't have Pro, so I've never used RenderTexture, but I read in the docs you can alocate a render texture (GetTemporary) which I suppose is off-screen. Could it be assigned to a Texture2D variable? If this is possible, you may use it in a DrawTexture and set GUI.color.a to control its transparency, like I did in my script, and GUI.depth to set the order. The simple test scripts Question.js and Wallpaper.js are listed below.
Question.js:
var pointer: Texture2D; var backgd: Texture2D; var style: GUIStyle; var alpha: float = 0.7;
function OnGUI(){
GUI.depth = 1;
GUI.color.a = alpha;
GUI.DrawTexture(Rect(40, 20, 300, 50), backgd);
GUI.DrawTexture(Rect(25, 30, 15, 30), pointer);
GUI.color.a = 1;
style.fontSize = 12;
GUI.Label(Rect(40, 20, 300, 50), "Generic question about something", style);
}
Wallpaper.js:
var wallpaper: Texture2D; var alpha: float = 1;
function OnGUI(){
GUI.depth = 2;
GUI.color.a = alpha;
GUI.DrawTexture(Rect(0, 0, 256, 256), wallpaper);
}
I think you're defining the recipe I have been searching for. I'm going to give this a try. Either way. I'd give this answer 2 votes if I could! Thanks! I'll update here with my findings.
And thank you, @aldonaletto! This was the recipe that worked. The essence was to direct the render texture to a GUI.DrawTexture ins$$anonymous$$d of to a GUItexture. Once that happened, all the defaults in both the render texture and the camera were fine.
Then the other trick was the material on the backing polygons (behind the 3Dtext in the scene of the rendertexture cam) needed to use Unlit/Transparent shader vs. any of the Transparent shaders.
This way I was able to get an alpha channel with no camera background and partially transparent elements around the 3Dtext.
This was really helpful and highly appreciated.
Your answer