Tweak MirrorReflection.cs (Portal Effect)

I’m trying to tweak MirrorReflection.cs to allow me to place two planes (mirrors) that each show the other ones reflection instead of their own.

Mirror Reflection wiki/code

I’ve managed to make them show all kinds of weird crap, but apparently I cant figure out how to go about producing the portal effect.

Mirror scripts modify the camera matrix so that the camera “thinks” to be in a position behind the mirror plane (pure math - the camera’s actual position is irrelevant). If you want to show the image from mirror A in mirror B and vice versa, fool the camera a little more by passing the other mirror’s transform when calculating the mirror plane. Add a Transform variable mirrorObject to the script and assign to it the other mirror, and make the mirror plane calculation use this variable instead of the object’s transform. The changes are the following:

public class MirrorReflection : MonoBehaviour
{
    // add this variable:
    public Transform mirrorObject; // drag the other mirror here
    public bool m_DisablePixelLights = true;
    ...
    ...
    // find out the reflection plane: position and normal in world space
    Vector3 pos = mirrorObject.position; // <= replace transform with mirrorObject
    Vector3 normal = mirrorObject.up;    // <= do the same here
    ...

NOTE: I’ve not tested this, but the logic should be ok. Let me know if something is wrong.

NOTE2: The mirrors must not be facing each other!