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

unity_StereoEyeIndex is always 0

Discussion in 'EditorXR' started by ErdTod, Aug 9, 2018.

  1. ErdTod

    ErdTod

    Joined:
    Jan 7, 2018
    Posts:
    11
    Hello, community!
    I have enabled Single Pass Stereo Rendering, and trying to make my shader work with Unity built-in variable unity_StereoEyeIndex - however, it seems that it awlays outputs 0 - when I flip cameras target eye, nothing changes - I seem to always see left eye. There's oddly not too much of stuff explained about this, so if anyone here could help me figure out how to properly use this variable, and how can I see results of it working in unity Editor - I'm sure this would be useful for many users in the present and future, including myself!

    So,
    Should I set up something else in the Editor, after turning on VR support in Player Settings, and selecting Single Pass Stereo Rendering?
    Or, maybe, I need to have some includes, or defines in my custom (vert/frag) shader? I just want to utilize unity_StereoEyeIndex being 0 for left eye, and 1 for right eye.
    Or should I install some kind of SDK, or import some kind of unitypackage? What can I do to see the results in Editor, like, for example, in this video:
     
  2. amirebrahimi_unity

    amirebrahimi_unity

    Joined:
    Aug 12, 2015
    Posts:
    400
  3. mptp

    mptp

    Joined:
    May 30, 2014
    Posts:
    29
    Since this is the first result in Google for checking this error, I thought I might as well say that unity_StereoEyeIndex only has a valid value in your vertex shader. If you try to access it in the fragment shader, it'll have a value of zero.

    If you need to access the stereo eye index in your fragment shader, pass it through your vertex-to-fragment struct.
     
    KayH, Propagant, DanjelRicci and 7 others like this.
  4. magdalenajones

    magdalenajones

    Joined:
    Sep 12, 2023
    Posts:
    2