Search Unity

Mirror Reflections in VR

Discussion in 'AR/VR (XR) Discussion' started by BLMSTN, Jul 18, 2016.

  1. jorgeolothar

    jorgeolothar

    Joined:
    Mar 27, 2016
    Posts:
    26
    I haven't been able to adopt OpenXR + URP because of the lack of VR mirrors. Seeing your VR avatar in a mirror is important for immersion and customization. Count me in to the people who would pay for this.
     
  2. ThisIsJeff

    ThisIsJeff

    Joined:
    Oct 30, 2019
    Posts:
    6
    OpenXR + URP Mirror in the 2020 LTS version... I´m now closing to a month of constant fighting and nothing wants to work. If anyone got something, please. Share it with us.
     
  3. AkilliMum

    AkilliMum

    Joined:
    Dec 6, 2014
    Posts:
    111
    I have tested my URP paid assets on 2021 with XR Plugin + OpenXR and seems to work fine with Oculus Runtime :)
    http://u3d.as/1p3H
    Of course it works with with XR Plugin + Oculus Provider too :) above 2020.2
    Also it has shader graph support both standalone and VR! So you can use the reflection output on your custom shaders easily :)
     
  4. Sheynes

    Sheynes

    Joined:
    Mar 27, 2017
    Posts:
    66
  5. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    In case anyone runs into this thread in the future, I've made an Internal Renderer mirror here:
    https://github.com/NegInfinity/NiVrMirrorDemo

    It should be possible to adapt this into URP/HDRP fairly easily, as long as the shader is replicated. No, it is not super-optimal.
     
    Iwanllu and JoeStrout like this.
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I'm down for a mirrored copy of the player avatar behind the wall. But my worry is, what happens when the player sticks their hand through the wall? Seems like it's going to be somewhat alarming for your mirror-self to reach out through the mirror and try to grab you. :eek:

    I can of course try to prevent the user from doing that, but users are squirrely. Is there some trick that could be done with the camera or shader or something to clip it at the mirror plane?
     
  7. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    @neginfinity I just tried your package, and it's amazing! Looks perfect and I'm still getting 90 fps where I need it.

    My only wish is that it would also work when running in the editor, so I could more easily test things like layer masks. But all I see in the editor is a dark gray plane with a little blue at the bottom:
    upload_2023-1-12_10-38-49.png

    Any idea why that is, and would it be hard to fix?
     
    neginfinity likes this.
  8. neginfinity

    neginfinity

    Joined:
    Jan 27, 2013
    Posts:
    13,566
    It's been a while since I worked with it, so my memory is a bit hazy.

    Looking through the codebase and remembering how it worked, Mirror is handled by VRPortalRenderer class (it is a portal renderer, because you can also do portals with it, as the principle is the same, so a mirror is technically a portal), which reads eye position data from input system and uses it to calculate and set shader parameters for camera projection matrices.

    This is happening within updateEyePos() method which is located at line 110 in my copy of the demo.

    The script does not have "ExecuteInEditMode" attribute, and IIRC in edit Mode there would be no pose data.

    Now, you could modify updateEyePos() function to work differently when not in play mode and calculate eye position data in editor view. As long as LateUpdate is called, RenderTargets are rendered, it /should/ produce desired result.

    Note that I have personally never bothered with it.


    By the way, that dark plane with little blue is definitely rendering your level. From somewhere.

    -------

    Also if you only wanted flat non-VR mirror, you could try this earlier script:
    https://forum.unity.com/threads/pla...-renderer-vr-compatible.1170721/#post-7742469

    This will not work in VR, and IIRC will produce some horrific eye gouging result like one eye seeing red or something like that. It also uses camera stacking instead of render targets.