Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[VR] Camera Target Eye RenderTexture

Discussion in 'Shaders' started by korzen303, Jul 13, 2017.

  1. korzen303

    korzen303

    Joined:
    Oct 2, 2012
    Posts:
    223
    Hi,

    I am trying to build a simple HeadUp Display for a vehicle in VR (Oculus).

    My plan was to use three cameras. One normal main camera, which renders everything except HUDContent layer and two HUDCamera that are identical but render only HUD Content to two RenderTextures, one for left eye and one for right eye. Next I have got a HUD plane mesh in the vehicle windshield with a simple shader that reads the render textures and overlays the HUDContent.

    The problem is that changing the target eye in the camera does not affect the rendertextures. It always renders left eye image no matter what is set there.

    Some time ago I used a simple trick to "hijack" the main camera settings and manually render to texture.
    AFAIK, it worked fine for HoloLens but doesn't work anymore

    Code (CSharp):
    1. public class RenderToTexture : MonoBehaviour
    2. {
    3.  
    4.     public Camera cam;
    5.     public Camera cam2;
    6.  
    7.     public RenderTexture tex;
    8.  
    9.     public LayerMask mask;
    10.     public Camera.StereoscopicEye eye2;
    11.     public StereoTargetEyeMask eye;
    12.  
    13.     // private void OnPreRender()
    14.     private void OnPreRender()
    15.     {
    16.  
    17.         cam2.CopyFrom(cam);
    18.         //cam2.SetStereoProjectionMatrix(eye, cam.GetStereoProjectionMatrix(eye));
    19.         cam2.targetTexture = tex;
    20.         cam2.projectionMatrix = cam.GetStereoProjectionMatrix(eye2);
    21.         cam2.stereoTargetEye = eye;
    22.         cam2.backgroundColor = Color.clear;
    23.         cam2.clearFlags = CameraClearFlags.Color;
    24.         cam2.cullingMask = mask;
    25.         cam2.Render();
    26.     }
    27.  
    28.  
    29. }
    Any ideas

    Thanks
     
    EyePD likes this.
  2. ixikos

    ixikos

    Joined:
    Jun 21, 2013
    Posts:
    26
    Any luck with this? Trying to make a stereoscopic camera...