Search Unity

VR Mirror URP 2019.3

Discussion in 'AR/VR (XR) Discussion' started by avandenberg, Feb 28, 2020.

  1. avandenberg

    avandenberg

    Joined:
    Nov 22, 2018
    Posts:
    23
    Hey everyone, I'm trying to implement a mirror in VR for the new URP in 2019.3

    I've seen some implementations but they all seem limited to multi-pass, or to the built-in RP. I need single-pass since the XR plugin doesn't render the right eye when using multi-pass currently (Vive).

    I've seen this tut too:
    but I can't get it to work with the latest URP, and it's also not designed for VR.

    Can anyone help me to get started on this effect? I've been searching all over for days now and nothing really seems to work. Even an minimal implementation would be sufficient for my research project.

    Thanks!
     
  2. alexchesser

    alexchesser

    Joined:
    Sep 15, 2017
    Posts:
    146
    you're sure you're using URP 7.2.0 or greater? The one-eye only issue was fixed in 7.2.0
     
  3. avandenberg

    avandenberg

    Joined:
    Nov 22, 2018
    Posts:
    23
    Actually you are correct, updating to 7.2.1 fixes the one-eye issue. However, I still can't get it to work nicely. The left and right eye render texture don't correctly align resulting in a very bad looking mirror :/ I've been searching for 2 days now but still haven't found a solution.

    Vive stereo rendering plugin looks exacly like what I need but it doesn't work for Unity 2018 and above unfortunately :/

    Would greatly appreciate any help!!!
     
  4. Tabski

    Tabski

    Joined:
    Jun 26, 2015
    Posts:
    2
    Ahh, I'm so happy that one eye issue is fixed. With that I'm able to almost get mirrors working with 2019.3 and URP. Check it out:



    Only thing I'm stuck on is that the culling is really wack for some reason. The mirror is only ending up rendering what is immediately in front of it. I really have no idea what could be causing this, and at this point the mirror has caused me so much headache that I don't care to spend more time looking into the issue.

    If anyone wants to try it for themselves, I attached my current script(s) and shader. It's not very clean though.

    To set it up:
    1. Create a Plane
    2. Attach a material that uses the shader provided
    3. Attack two "MirrorReflection" components to the Plane
    4. Set the Reflection types on each MirrorReflection script to each eye
    upload_2020-3-13_22-37-24.png

    Basic gist of how the script works:
    1. It sets up a render texture for the eye
    2. It sets the texture of the material to the texture created
    3. It sets up a new camera, with settings equal to the main camera.
    4. Every frame, it does some matrix magic to position the cameras and set up their matrices
    Hopefully this gives you some inspiration. If anyone figures out the culling issue I would be thrilled to know what's going on there.
     

    Attached Files:

  5. avandenberg

    avandenberg

    Joined:
    Nov 22, 2018
    Posts:
    23
    Good job on getting this to work! Ive managed to get something working as well! Some of the scripts ive seen use a near clipping value, this could be it. Also it could be that you need to mask the mirror itself for the camera. Sometimes the clipping is Wonky, especially whennot aligned with the World frame.

    Now that ive taken a loot at the ss, i see theres a near clipping value. Have you tried lowering it to a smaller value?

    Edit: and thank you for explaining this so nicely! Im sure thisll help a lot of people(including me)!
     
  6. Tabski

    Tabski

    Joined:
    Jun 26, 2015
    Posts:
    2
    Alright, I revisited this a bit. I checked the clipping value, but after playing around with values that doesn't seem to be the problem.

    What does seem to be the problem is the frustrum culling. One thing I noticed with my mirror script was that the culling matrix would update every frame without VR, but when VR was enabled the culling matrix would never be recalculated on the mirror cams.

    This almost certainly seems like a bug to me, but it's hard to say without doing more investigation into that aspect of the rendering.

    Now, there's a few options I could pursue to get around this issue:
    1. I could submit a bug report, and wait for a fix (but I'm impatient)
    2. I could do some math to calculate the culling matrix matrix myself (but this goes far above my paygrade as a hobbyist)
    3. I could disable the frustrum culling for these cameras by scripting the render pipeline (but I don't want to make any changes to that if I can help it)
    4. I could disable the effects of the frustrum culling with an incredibly hacky and janky solution.
    Naturally, I opted for option #4. Since the culling matrix would still be calculated before I modified it with a VR matrix, I am now setting up the camera waaaay behind the mirror on awake. This means that the non-updating culling matrix will at least be set so that everything will be in view (as well as a lot of things that should be culled, but hey I'll take what I can get).



    This is still far from a perfect solution (there's extra rendering overhead and now the camera can't be moved), but this is good enough for what I'm trying to achieve.

    I've attached the updated camera script, to be used alongside the other assets I posted.
     

    Attached Files:

  7. jorgeolothar

    jorgeolothar

    Joined:
    Mar 27, 2016
    Posts:
    13
    Is using Valve.VR; a dependence on SteamVR? Looking for a solution that works for all headsets, not just Vive
     
  8. OP3NGL

    OP3NGL

    Joined:
    Dec 10, 2013
    Posts:
    260
    how do i get it to work with oculus quest?
     
    Folstrym likes this.
  9. kogrob

    kogrob

    Joined:
    Jul 10, 2020
    Posts:
    6
    Bump! Thank you so much for posting your code, Tabski!! I tried using your code but for some reason, the mirror is acting more like a portal window than a mirror. The mirror camera is facing in the same direction as my VR camera. Is there something I might've missed?
     
unityunity