- Home /
Rendering OnGUI elements on 3d object / Unity Free / Stereo Cameras
Hello, I'm using 2 cameras for stereo purpose (one for left eye, one from right eye). Everything works fine, but at the moment I did not find a good way to have GUI rendered correctly so I can see it on both eyes.
The GUI seems to be rendered after the two cameras so I've tried to render it into a texture and map it onto a 3d object. I don't know if it's a Unity Free limitation or that I did something wrong but it does not work as expected.
Any help would be appreciated ! Thanks a lot in advance !
So here is a quick summary of what I did at the moment (which works fine if I do it with a camera instead of the object with the GUI script) :
created a GameObject for GUI management an assigned the GUI script thereafter
created a material in project and assigned it to the "guiToMaterial" by drag/drop
created a quad in front of the camera and drag/dropped the same material
GUI script extract:
public Material guiToMaterial = null; // <= assigned from Unity UI
private RenderTexture renderedTexture = null;
void Awake()
{
renderedTexture = new RenderTexture(Screen.width, Screen.height, 0);
guiToMaterial.mainTexture = renderedTexture;
}
private void OnGUI()
{
RenderTexture.active = renderedTexture;
//GUI.Button...
RenderTexture.active = null;
}
Answer by Ericool · Jan 09, 2015 at 01:37 PM
Did you set the render texture as target texture to a camera. So the camera will copy its view into this texture?
Thanks for answering. No I did not. I've just rendered the GUI in a texture and to a material (like above code), then used this material on a quad displayed on the front of the scene. This quad is then displayed into the 3d views.
So if I understand what you suggest, I shall try to render GUI on a Camera, then into a texture and then use this texture on the 3d obj ?