- Home /
Mirror flip camera?
hi I found this script on the Wiki called InvertCamera
// EXAMPLE WITH CAMERA UPSIDEDOWN
function OnPreCull () {
camera.ResetWorldToCameraMatrix ();
camera.ResetProjectionMatrix ();
camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(Vector3 (1, -1, 1));
}
function OnPreRender () {
GL.SetRevertBackfacing (true);
}
function OnPostRender () {
GL.SetRevertBackfacing (false);
}
@script RequireComponent (Camera)
"This script inverts the view of the camera. So everything rendered by the camera is flipped. This will help you to implement a rear mirror camera."
It makes every think look up side down basically. But I'm trying to make it get flipped vertical. will this even be possible?
Answer by GerryM · Nov 24, 2012 at 11:18 PM
Just change the matrix (line 5 of your code) to flip the x axis instead of the y axis:
camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(Vector3 (-1, 1, 1));
Thanks Sir. that did the job. I feel stupid for not seeing that. $$anonymous$$any thanks again.
-Frank
Out of all the posts I've been scouring over the past 9 months here regarding Unity, this one has single handedly fixed all my inverse Z positioning co-ords I've been having to use. Now my procedural meshes are correctly aligned position-wise, but also uv's are mapped as they're meant to be and my triangle ordering can go back to clockwise! Although the editor mesh filter navigator thinks my meshes are inside out, I know they're not! Thankyou every so much :-)
Answer by JamsCenter · Oct 05, 2019 at 02:07 AM
For the next coming on this post. C# version of it. (Tested in 2019.1.14f )
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FlipCamera : MonoBehaviour
{
public Camera m_camera;
void OnPreCull()
{
m_camera.ResetWorldToCameraMatrix();
m_camera.ResetProjectionMatrix();
m_camera.projectionMatrix = m_camera.projectionMatrix * Matrix4x4.Scale(new Vector3(-1, 1, 1));
}
void OnPreRender()
{
GL.SetRevertBackfacing(true);
}
void OnPostRender()
{
GL.SetRevertBackfacing(false);
}
}
All good - except Unity (2019.2.9f1) is saying GL.SetRevertBackfacing is deprecated and to use GL.invertCulling ins$$anonymous$$d. So I replaced GL.SetRevertBackfacing(bool) with GL.invertCulling = bool.
Answer by hydrix · May 12, 2016 at 08:03 AM
the above approach messes up with occlusion culling so here's an approach that worked for me: copy paste the main camera, flip it, then enable it and disable the other at runtime on that button down, and reinitialize the camera. On the standard assets RigidBodyFirstPersonController this is mouseLook.Init (transform, cam.transform);
Answer by SylverLocks · Mar 10, 2017 at 07:18 AM
Or just rotate the camera 180 degrees on the Z axis.
Nerd doesn't get question, doesn't test solution, is consumed by gagging need to establish superiority over topic they don't understand.
The internet, everyone.
A 180 degree rotation is not equivalent to a vertical flip. After a 180 degree rotation, a horizontal flip would be needed to result in the equivalent of a vertical flip.
Your answer
Follow this Question
Related Questions
Camera Effects binoculars 2 Answers
Create a break screen effect 0 Answers
Flip/Mirror > Camera? 6 Answers
effect on clipping plane 1 Answer