Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by SOIL · Jun 23, 2010 at 07:07 AM · cameraflip

Flip/Mirror > Camera?

Is there a way to flip the Camera (let's say in X position), so the whole scene is "mirrored" for example to the right side,?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image buenacolombia · Jan 28, 2019 at 09:00 PM 0
Share

use this scrip

 void Start () {
     $$anonymous$$atrix4x4 mat = Camera.main.projection$$anonymous$$atrix;
     mat *= $$anonymous$$atrix4x4.Scale(new Vector3(-1, 1, 1));
     Camera.main.projection$$anonymous$$atrix = mat;
 }

 // Set it to true so we can watch the flipped Objects

 void OnPreRender()
 {
     GL.invertCulling = true;
 }

 // Set it to false again because we dont want to affect all other cammeras.

 void OnPostRender()
 {
     GL.invertCulling = false;
 }

6 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by Mike 3 · Jun 23, 2010 at 11:34 AM

You can use something like this (Once in start should do it):

Matrix4x4 mat = Camera.main.projectionMatrix;
mat *= Matrix4x4.Scale(new Vector3(-1, 1, 1));
Camera.main.projectionMatrix = mat;
Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SOIL · Jun 23, 2010 at 12:08 PM 0
Share

i haven't tried it yet, need to give that to my programmer, and he is at work atm (got no time). i help him as good as i can and i am only a grafic artist with a bit knowledge about how things work.

  • so we are not talking about a render to texture method?

  • it really flips the whole view in x position?

  • Does it work on iphone too?

avatar image Mike 3 · Jun 23, 2010 at 12:38 PM 0
Share

Should do. Flips the camera horizontally on 2.6, and the same function is there for iphone. It's old style flipping, nothing fancy,should work on any computer

avatar image SOIL · Jun 23, 2010 at 01:43 PM 0
Share

you are my god :D thnx!! is exactly that code the one which works on iphone too? xD

avatar image SOIL · Aug 09, 2010 at 03:16 PM 1
Share

Hello $$anonymous$$ike, we tried the script now. It seems to work, but it flips the normal matrix of all objects. in play mode the camera is facing to the right direction. in game mode i recognize my objects areflipped. but it's like all normals where flipped too. Do you know how to fix that problem?

avatar image Edy · Sep 10, 2010 at 10:37 PM 1
Share

Doesn't work... normals are also flipped so the mirrored camera renders objects something like inside-out, and terrain surfaces are not rendered at all.

Show more comments
avatar image
6

Answer by ApenasVB · Jan 17, 2017 at 03:30 PM

Just use the attached script in your camera, it will flip the image according to the editor selection and fix the culling accordingly.

 using UnityEngine;

 [RequireComponent(typeof(Camera))]
 [ExecuteInEditMode]
 public class MirrorFlipCamera : MonoBehaviour {

     new Camera camera;

     public bool flipHorizontal;

     void Awake () {
         camera = GetComponent<Camera>();
     }

     void OnPreCull() {
         camera.ResetWorldToCameraMatrix();
         camera.ResetProjectionMatrix();
         Vector3 scale = new Vector3(flipHorizontal ? -1 : 1, 1, 1);
         camera.projectionMatrix = camera.projectionMatrix * Matrix4x4.Scale(scale);
     }

     void OnPreRender () {
         GL.invertCulling = flipHorizontal;
     }
     
     void OnPostRender () {
         GL.invertCulling = false;
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image zqcolor · Aug 18, 2017 at 07:49 PM 0
Share

This one works in non-vr mode, in google cardboard VR mode, it seems not working, Any suggestions? thanks

avatar image
2

Answer by StephanK · Jun 23, 2010 at 11:04 AM

If you have render to texture (pro only) you could easily achieve this by rendering a texture and then flip that texture before it's displayed.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SOIL · Jun 23, 2010 at 12:04 PM 0
Share

That's a solution for Animated Textures or so. What i need is a flip for right handed iphone users. the whole game-view shell be flipped, and the touch-matrix would be moved to the right position too. thing is my game works with on thumb. and the touchfield for it is atm on the left side. if i want to move the touchfield to the right side, i also have to flip the camera in x position, cause the game is strictly layouted on that way.

avatar image
1

Answer by _geo__ · Nov 15, 2021 at 04:38 PM

URP and HDRP have deprecated the On..Render events. Here is a version of @ApenasVB s script which will work for URP and HDRP. I also added mirroring for both axis.

 using UnityEngine;
 using UnityEngine.Rendering;
 using UnityEditor;
 
 [RequireComponent(typeof(Camera))]
 [ExecuteInEditMode]
 public class MirrorFlipCamera : MonoBehaviour
 {
     Camera _camera;
     public Camera Camera
     {
         get
         {
             if (_camera == null)
             {
                 _camera = this.GetComponent<Camera>();
             }
             return _camera;
         }
     }
 
     [SerializeField]
     protected bool flipHorizontal;
     public bool FlipHorizontal
     {
         get => flipHorizontal;
         set
         {
             flipHorizontal = value;
             UpdateCameraMatrix();
         }
     }
 
     [SerializeField]
     protected bool flipVertical;
     public bool FlipVertical
     {
         get => flipVertical;
         set
         {
             flipVertical = value;
             UpdateCameraMatrix();
         }
     }
 
     protected float aspectRatio = 0;
 
     void Awake()
     {
         RenderPipelineManager.beginCameraRendering += beginCameraRendering;
         RenderPipelineManager.endCameraRendering += endCameraRendering;
     }
 
     void beginCameraRendering(ScriptableRenderContext context, Camera camera)
     {
         // Flip only if ONE of the two axis is mirrored but not if both are mirrored.
         if (this == null || !this.gameObject.activeInHierarchy)
             return;
 
         GL.invertCulling = flipHorizontal ^ flipVertical;
 
         // update is aspect ratio changed
         if (Mathf.Abs(aspectRatio - Camera.aspect) > 0.01f)
         {
             aspectRatio = Camera.aspect;
             UpdateCameraMatrix();
         }
     }
 
     void endCameraRendering(ScriptableRenderContext context, Camera camera)
     {
         if (this == null || !this.gameObject.activeInHierarchy)
             return;
 
         GL.invertCulling = false;
     }
 
     public void UpdateCameraMatrix()
     {
         Camera.ResetWorldToCameraMatrix();
         Camera.ResetProjectionMatrix();
         Vector3 scale = new Vector3(
             flipHorizontal ? -1 : 1,
             flipVertical ? -1 : 1,
             1);
         Camera.projectionMatrix = Camera.projectionMatrix * Matrix4x4.Scale(scale);
 
     }
 
     void OnValidate()
     {
         if (Camera == null)
             return;
 
         UpdateCameraMatrix();
 
 #if UNITY_EDITOR
         RenderPipelineManager.beginCameraRendering -= beginCameraRendering;
         RenderPipelineManager.endCameraRendering -= endCameraRendering;
         if (!EditorApplication.isPlayingOrWillChangePlaymode)
         {
             RenderPipelineManager.beginCameraRendering += beginCameraRendering;
             RenderPipelineManager.endCameraRendering += endCameraRendering;
         }
 #endif
     }
 }

Since another answer mentioned the Unity wiki (which no longer exists), here is the linked page from the archives: https://web.archive.org/web/20210414060956/https://wiki.unity3d.com/index.php?title=InvertCamera

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by devigod · Mar 11, 2011 at 04:10 AM

There is the answer: http://wiki.unity3d.com/index.php?title=InvertCamera

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Flip The Entire Output in App 0 Answers

Why does my fly though camera flip over on the first call of Input.GetAxis("Mouse X") (or Y)? 1 Answer

Player follow object changes direction when the player does 0 Answers

Platformer Flipping 0 Answers

How to rotate the camera on a button press. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges