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 wolga2 · May 18, 2014 at 02:09 AM · camerascreensplitintersection

Split Screen where Waterplane intersects with Camera

Hi!

As mentioned here http://forum.unity3d.com/threads/39292-Request-Special-Underwater-Blurring-Script, I have two cameras in my scene, one for the underwater-effect and one for the over-water game. I have a 3rd person controller, and if I swim or wade in the water the camera is able to rotate around the player and dive into it. Therefore I want the screen to split on the line, where the water intersects with the camera. Is there a easy way to find the point of the intersection of the water and the camera and set that as the split value?

Thank you!

Comment
Add comment
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 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Cherno · May 18, 2014 at 03:57 PM

Sounds like you just need the compare the camera's y position and the water plane's y position.

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 wolga2 · May 18, 2014 at 07:45 PM 0
Share

Hi! Thank you for your answer!

Yes, I surely did that. Works perfectly if the $$anonymous$$ouseLook-Asis is only on X. But thus I have the $$anonymous$$ouseLook on X and Y Axes, the camera can 'dive' into the water even though it's not under the water surface (because of the angle). Is there a possibility to solve this problem?

Here's my code, attached to a child-objcet camera of the $$anonymous$$ainCam:

 using UnityEngine;
 using System.Collections;
 
 public class CamSplit : $$anonymous$$onoBehaviour
 {
     public GameObject water;
     public float split;
     public float maxViewHeight;
     
     Camera topCam;
     
 
     void Start ()
     {
         Transform topTrans = transform.parent;
         topCam = (Camera) topTrans.gameObject.GetComponent("Camera");
     }
     
 
     void Update ()
     {
         split = -(0.5f + ((1/(maxViewHeight*2)) * (transform.position.y - water.transform.position.y)));
         if (split <= 0)
         {
             split = 0.0001f;
         }
 
         split = $$anonymous$$athf.Clamp01(split);
         float halfHeight = $$anonymous$$athf.Tan(camera.fieldOfView * $$anonymous$$athf.Deg2Rad * .5f) * camera.nearClipPlane;
         float upperTop = halfHeight;
         float upperBottom = (split - .5f) * halfHeight * 2f;
         float lowerTop = upperBottom;
         float lowerBottom = -halfHeight;
         
         $$anonymous$$atrix4x4 upper$$anonymous$$at = topCam.projection$$anonymous$$atrix;
         upper$$anonymous$$at[1, 1] = (2f * camera.nearClipPlane) / (upperTop - upperBottom);
         upper$$anonymous$$at[1, 2] = (upperTop + upperBottom) / (upperTop - upperBottom);
         topCam.projection$$anonymous$$atrix = upper$$anonymous$$at;
         
         $$anonymous$$atrix4x4 lower$$anonymous$$at = camera.projection$$anonymous$$atrix;
         lower$$anonymous$$at[1, 1] = (2f * camera.nearClipPlane) / (lowerTop - lowerBottom);
         lower$$anonymous$$at[1, 2] = (lowerTop + lowerBottom) / (lowerTop - lowerBottom);
         camera.projection$$anonymous$$atrix = lower$$anonymous$$at;
         
         Rect botCamRect = camera.rect;
         botCamRect.height = split;
         camera.rect = botCamRect;
         
         Rect topCamRect = topCam.rect;
         topCamRect.height = 1f - split;
         topCamRect.y = split;
         topCam.rect = topCamRect;
     }
 }
avatar image Cherno · May 19, 2014 at 02:03 AM 0
Share

I am not sure what you mean, are you talking about how you can see the submerged area under teh water surface if you are a little bit higher than the surface? If so, from looking at how many AAA titles still have this problem, I guess there's no easy solution.

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

22 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

Related Questions

Camera.ScreenToWorldPoint Not Giving Right Point 3 Answers

Clicking Trigger 1 Answer

Lock the screen 1 Answer

Camera Shake 4 Answers

WorldToScreenPoint, isn't getting it right? 1 Answer


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