Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by george_gamedesign · Oct 23, 2014 at 01:22 AM · camera-lookmirrorfirst-person

how to make a real mirror in Unity?

I mean, a real mirror in a first person game, like how a mirror works in real life.

First, when you look at yourself in the mirror, your mirror image should move with you on the mirror. When you move left, it moves left; when you moves closer, it moves closer and becomes bigger.

Second, when you look at other things reflected by the mirror, the mirror image should be the same with a view from a camera in the other side of the camera. Like in the picture below: alt text

The second requirement is easy to do. But it conflicts with the first one. Anyone has an idea? Thank you very much!

mirror.png (8.1 kB)
Comment
Add comment · Show 2
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 george_gamedesign · Oct 22, 2014 at 10:27 PM 0
Share

$$anonymous$$aybe a stupid way is to copy everything on the backside of the mirror?

avatar image bubzy · Oct 28, 2014 at 07:11 AM 0
Share

if the arrows represent the direction of looking, this isn't how a mirror works.

5 Replies

· Add your reply
  • Sort: 
avatar image
2
Wiki

Answer by ZiadJ · Mar 12, 2015 at 10:32 AM

The proper way to achieve this is to use the mirror reflection shader available here: http://wiki.unity3d.com/index.php/MirrorReflection4

However this new version targeting Unity 5 is giving me a 'could not find entry point' error. It used to work fine in Unity 4 so it's either a bug or may be I'm missing something. Right now my workaround is to use the 'Fx/Water' shader instead from the standard assets.

Comment
Add comment · Show 2 · 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 JoeStrout · Jul 22, 2015 at 06:57 PM 0
Share

I just tried it, and for what it's worth, it's working fine for me (after letting the script updater correct a couple of things).

avatar image zinouch · Aug 11, 2018 at 12:37 PM 0
Share

this is actually working perfectly, i very recommend giving this a try since it's working in the personal educational version and without having to edit anything sample

mirror.jpg (170.8 kB)
avatar image
2

Answer by Pangamini · Mar 12, 2015 at 11:35 AM

Just take the unity example reflective water asset and trim out what you don't need. Start with simplifying the shader, remove all the wave distortions etc.

Basically you need to render the mirrored camera to the texture, but clip whatever's in front (or behind, from the reflection's point of view) of the mirror. The cheapest way is to hack the camera's clipping frustum, just like in the example water, take a look at the script.

Then you need to apply the camera to your mirror mesh in a screen space, not in model space (but again, that's covered by the unity water)

Additional tip, to make the mirror extra cool, you could duplicate and mirror all the lights that would normally affect the mirror mesh, and generate an inverted mirror mesh (something like a big plane with a hole instead of mirror) to use as shadow caster. This will create an effect of the light being actually reflected, lighting different parts of the world

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 Tepei · Oct 23, 2014 at 02:00 AM

If you have unity pro you could use a segond camera that render a texture and use this texture to make the mirror. http://docs.unity3d.com/Manual/class-RenderTexture.html

But for free it's not so easy.. you could use something similar to indie effect (i suppose) but this is slower and could affect your fps..

http://forum.unity3d.com/threads/indieeffects-bringing-almost-aaa-quality-post-process-fx-to-unity-indie.198568/

Comment
Add comment · Show 3 · 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 george_gamedesign · Oct 23, 2014 at 02:52 AM 0
Share

I have pro. But in this way, the mirror doesn't work like a real mirror, especially when you get close to it.

avatar image Tepei · Oct 28, 2014 at 03:06 AM 0
Share

I just find this : https://www.youtube.com/watch?v=Y$$anonymous$$Z$$anonymous$$6umLp3o

Unity3D 4 Indie (Free) Portal Effect With No Stencil And No Render To Texture

avatar image george_gamedesign · Oct 29, 2014 at 04:42 AM 0
Share

It's still fake. In some angle, you can see the red cube in the mirror, which should not be there. A nice one, though. I also don't know how to make my mirror so clear.

avatar image
0

Answer by Nanako · Oct 23, 2014 at 03:18 AM

I don't have specific knowledge to offer, but a general theory/suggestion.

have you tried a reflective material? There's a Reflective section in the material presets with many options, one of them might give the realtime reflections you desire, and you could just apply it to a flat panel. if you've not tried, it can't hurt to give it a test, won't take you a few minutes =) i'd be curious how it goes for you too

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 AlwaysSunny · Oct 28, 2014 at 05:24 AM 0
Share

Reflective shaders don't work like that. The "reflections" they display are from a static cubemap.

avatar image
0

Answer by Cinder · Mar 24, 2015 at 03:49 PM

Probes are now viable but still a bit meh in some conceptual ways. to get it to work as a mirror I used this script: var plane : GameObject; var character : GameObject;

  var offset : float;
  
  var directionFaced : Direction;
  
  function Update () {
  
      if(directionFaced == Direction.X){
          
          offset = (plane.transform.position.x - character.transform.position.x);
          
          transform.position.x = plane.transform.position.x + offset;
  
          transform.position.y = character.transform.position.y;
          transform.position.z = character.transform.position.z;
      }
      if(directionFaced == Direction.Y){
          
          offset = (plane.transform.position.y - character.transform.position.y);
          
          transform.position.x = character.transform.position.x;
          transform.position.y = plane.transform.position.y + offset;
          transform.position.z = character.transform.position.z;
      }
      if(directionFaced == Direction.Z){
          
          offset = (plane.transform.position.z - character.transform.position.z);
          
          transform.position.x = character.transform.position.x;
          transform.position.y = character.transform.position.y;
          transform.position.z = plane.transform.position.z + offset;
      }
  }
  
  //makes the possible directions 
  public enum Direction{
      X,Y,Z
  }

With the variable "plane" being the mirror surface and the "character" being the player's camera. There's a few other things I had to do to make this actually work and I go into step by step detail in the video here.

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

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

9 People are following this question.

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

Related Questions

[Closed] How could I create a first-person controller from scratch? 2 Answers

Camera won't rotate while holding WASD keys 0 Answers

How to move the rotation of the X and Z axis of a 3D model's head with Mouse Input? 0 Answers

Mirror material in Indie? 4 Answers

Sun rays don't show up in mirror reflection in deferred rendering ? 0 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