Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by asimov · Jan 19, 2016 at 10:38 PM · waterreflectionmirrorvisibility

Identifying/detecting whether an object is visible in a mirror reflection (using Water.cs)

Hey guys,

I am using the Water.cs script in Reflective mode as a mirror and was wondering if it's possible to detect when an object is visible (being reflected) by the plane. I can see that the script uses a LayerMasks so I can choose which layers are culled, but is there a way to check if a specific object is being drawn?

I have tried using the regular Visibility checkers (OnBecameVisible/OnBecameInvisible as well as the IsVisibleFrom script on the Wiki) but as Water.cs uses cameras in an unconventional way these don't seem to work.

Any help would be great. Thanks in advance!

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 ZefanS · Jan 20, 2016 at 12:57 AM 0
Share

Not sure if this will work in your case, but here's a script that can be used to check if an object with the tag Target is seen by a specific camera:

 #pragma strict
 
 private var mirrorCam : Camera;
 
 function Start()
 {
     mirrorCam = GetComponent.<Camera>();
 }
 
 function Update()
 {
     if (GameObject.FindWithTag("Target"))
     {
         var screenPoint = mirrorCam.WorldToViewportPoint(GameObject.FindWithTag("Target").transform.position);
         
         if (screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1)
         {
             Debug.Log("Visible");
         }
         else
         {
             Debug.Log("Invisible");
         }
     }
     else
     {
         Debug.Log("Invisible");
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by asimov · Jan 20, 2016 at 06:25 PM

Thanks for the script, ZefanS. However, it only checks if the object is on screen in the usual way. That is, if the object is in front of the camera. If we have a mirror placed in front of the camera which reflects an object which is at the camera's side (so not within the camera's view frustum), it will fail the screenpoint check you have set up.

I suspect one way would be to somehow detect which objects are being reflected by the Cameras in the m_ReflectionCameras dictionary in the Water.cs script. However, how to approach this is a little beyond my level of experience - any suggestions would be great.

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

33 People are following this question.

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

Related Questions

Reflect the whole picture to the slope 1 Answer

Reflection/Refraction water 1 Answer

Mirror material in Indie? 4 Answers

mirror effect reversed side? 1 Answer

Mirror reflection stretching problems 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