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

Mirror reflection shader on to multiple objects for VR

Discussion in 'Shaders' started by TareqProjects, May 10, 2018.

  1. TareqProjects

    TareqProjects

    Joined:
    Jun 27, 2016
    Posts:
    55
    Hello all,

    I got a scene that has multiple mirrors in the same area. I've found this script and shader online that does mirror reflection quite well: https://wiki.unity3d.com/index.php/MirrorReflection4

    The issue is that if I apply this to more than one object within the scene it doesn't reflect the environment. I was wondering whether anyone has made any tweaks to get this script to work on to multiple objects.

    Thanks

    Edit: I should've clarified a bit more but I need this for a VR project. I'm trying to get reflection to work in a car specifically for the wing mirrors and and rear-view mirror. Using render textures seems to be a bit too taxing since the environment I'm using is quite large and urban, still in the process of optimising it.

    The shader above seemed promising; in a test scene it was able to reflect the environment while I had the headset on. The issue, however, is that I can't use it on more than one object. I've tried the Vive Stereo Rendering Toolkit. I wasn't quite sure what was meant regarding the anchor point and canvas but I did get it to reflect the environment. The only issue however is that if I move around within the card, the reflection only seems to reflect whatever the anchor point was set to (the anchor point doesn't update)
     
    Last edited: May 10, 2018
  2. Seyed_Morteza_Kamaly

    Seyed_Morteza_Kamaly

    Joined:
    Nov 18, 2015
    Posts:
    80
  3. TareqProjects

    TareqProjects

    Joined:
    Jun 27, 2016
    Posts:
    55
    Thanks for the reply, I'm aware of using render textures but I'm not particularly a fan of it. There's quite a bit of fiddling around trying to get the camera to be in the right place, I would have to make a render texture and camera for each instance of them, and then there's also performance if I decide to scale up the project.

    I forgot to mention the the main post (will update), but this is for a VR project.
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    You realize that the MirrorReflection4 and Vive Toolkit both use render textures, yes? It's kind of "the way" to do this effect.
     
  5. addiadriano

    addiadriano

    Joined:
    Apr 22, 2018
    Posts:
    2
    I've run into the exact same problem: Multiple Mirrors (Front and Wings) in a car for a VR project with a HTC Vive by using the MirrorReflection4 (https://wiki.unity3d.com/index.php/MirrorReflection4).

    I found a solution that worked for me.
    1. First you should know, the MirrorReflection4 by default makes mono pictures, that look wrong with the Headset on. For a VR application, I had to modify it for stereo pictures. I found a modified solution of the MirrorReflection4 in this thread: https://forum.unity.com/threads/mirror-reflections-in-vr.416728/
    2. Make sure you use seperate materials and shaders for each mirror in your environment.
    3. This was the core problem for me: When applying the MirrorReflection4 onto multiple objects, they are reflecting themselves, which produces weird reflections. I solved this by working with Layers. Put different Layers onto each mirror. In the Inspector/MirrorReflectionScript you should be abled to modify the ReflectLayers, and there you can uncheck the other Mirror Layers.
     
    Last edited: May 6, 2019