- Home /
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.
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.
Answer by aldonaletto · Sep 16, 2013 at 01:15 AM
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!
Hello, first of all thanks very much for your answer!
That was what I figured aswell, but I can't get it working with that code. :/
Ok, I'll test this and go back here
UPDATE: I tested the use of another object as the mirror plane reference, and things worked fine while the other object was inside the main camera's frustum. When it was outside the frustum, however, weird images appeared. I suppose that this is due to the mirror camera matrix being calculated as a reflection of the main camera - maybe reflecting through an object out of view generates an invalid matrix.
Your answer
Follow this Question
Related Questions
How to make a mirror in 3.x? 0 Answers
Problem with the mirror view made by reflection probe in android build 0 Answers
How to mirror an object (reverse its sides)? 2 Answers
Controlling the opacity of the reflection in the Mirror Reflection Shader 0 Answers
Mirrorreflection V3 needed for Unity 3? 0 Answers