- Home /
RenderTexture Mirror - Camera postion and rotation
Hello,
I'm trying to make mirror using the RenderTexture. Everything works as expected except of one simple detail, which I'm trying to figure out. I've been searching for a long time online now but couldn't find any solution.
From what I've understood after my searching, the Mirror camera should be position exactly at the same position as main camera, but behind the Mirror plane, but this approach doesn't really work for me, because it also draws empty space behind the camera.
I'm posting a video to better understand what I mean : https://youtu.be/d4GxRWS5ZR0
After seeing this problem I've tried to make Mirror camera stick ON the Mirror plane, but now it makes image zoomed.
Again, I've made a video : https://youtu.be/jPhWA9-44To.
Here's code for the camera Update function :
void Update()
{
Vector3 mcforward = cameraMain.transform.TransformDirection(Vector3.forward);
Vector3 cforward = Vector3.Reflect(mcforward, Vector3.left);
//Getting camera position and reflection
Debug.DrawRay(cameraMain.transform.position, mcforward * 20, Color.red);
Debug.DrawRay(transform.position, cforward * 20, Color.green);
//Drawing rays
transform.rotation = Quaternion.LookRotation(cforward);
//Rotating camera (works as expected)
Vector3 position = cameraMain.transform.position - _collider.transform.position;
//transform.localPosition = new Vector3(-position.z, position.y, position.x);
transform.localPosition = new Vector3(-position.z, position.y, 0);
//Positioning camera
}
The _collider variablle is actually Plane with mirror and cameraMain is of course main camera.
Thank you for your help.
Answer by Eno-Khaon · Mar 27, 2016 at 03:54 AM
In this wiki writeup, you will find numerous complex details of a reflection camera outlined, including specifics such as creating an oblique camera matrix to properly align the camera's view to the surface it's reflecting from.
Your answer
Follow this Question
Related Questions
Flip a render texture? 2 Answers
Check if mouse is over GUI element using Rendertexture? 1 Answer
First Person Camera Pixelation 1 Answer
RenderTexture.active for a non-VR camera in a VR project 0 Answers