Search Unity

Unity_Vertex_Output_Stereo

Discussion in 'Shaders' started by JasonBricco, Jan 3, 2017.

  1. JasonBricco

    JasonBricco

    Joined:
    Jul 15, 2013
    Posts:
    956
    Hey all,

    Just a simple question here. I was looking at Unity's Sprite shader source and came across these macros:

    UNITY_VERTEX_OUTPUT_STEREO
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);

    I can't seem to find out what these are for. Just wondering what they do.

    Is it related to Stereoscopy? I can't seem to see any difference if I remove those lines of code... and I don't really want stuff using up resources if I don't need it.
     
    LxiongAXX likes this.
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    It's related to VR, specifically single pass stereo rendering for VR. They do nothing if VR is not enabled.
     
    kaiyum and JasonBricco like this.
  3. Vathsal

    Vathsal

    Joined:
    Mar 31, 2017
    Posts:
    1
    @bgolus : I use this for VR, but I am unable to find any documentation on what these macros do. Will you be able to shed some light on that?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    They pass the instance id and eye index to the fragment shader. This lets you access instanced properties in the fragment shader, as well as do any unique per eye work that may be needed. For example, if you’re using any of the view or projection matrices or the camera position in the fragment shader these need the eye index to give the correct value, otherwise you’ll always access the left eye.

    edit: You have to additionally call UNITY_TRANSFER_INSTANCE_ID to transfer the instance id.
     
    Last edited: Feb 24, 2018