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
1
Question by Lextredis · Dec 26, 2016 at 05:16 PM · cameraportalmatrix4x4frustumnearclipplane

Match camera frustum's near plane to 3D plane

I've seen this question asked before, specifically this question is pretty close to mine but I couldn't find a definite answer about it and I actually need it myself now so I'll have to ask again, sorry if this was actually answered somewhere else but I couldn't find anything about it that suited my needs.

I'm trying to recreate the portals from the Portal game in Unity, and so far thanks to this blog post I've managed to create a pretty close effect for the visual part. The portal camera basically mimics the player camera's movements behind the destination portal, renders the result to a rendertexture and then a shader cuts off a portion of that texture and applies it to the portal mesh (or at least I think so, I don't quite understand shaders but this is what I got out of the blog post).

What happens though is that since portals are placed on walls, the camera will actually render the wall unless I get sufficently close to the portal. By looking around the github project I've found a way of handling the nearclip plane for the portal camera such that the camera will only start rendering from the portal's position onwards, which works. Kind of.

Because the camera's near clip plane is not always parallel to the portal's plane, getting far enough from a portal and looking at it at specific angles will start cutting out portions of the world inside the portal, as you can see here:

portalcutoff

I can't really come up with a solution for this except for changing the orientation of the near clip plane to match it with the portal plane, basically I'm looking for a way of "cutting" the camera's frustum at the angle and position of the portal plane, kinda like this:

camfrustum

I've tried playing around with the camera matrix but I couldn't find any configuration that properly moved the near clip plane to the correct rotation, scale and position, but I'm sure I'm missing something here. Is there anything that can be done for this?

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
5
Best Answer

Answer by Lextredis · Dec 27, 2016 at 12:32 PM

Ok guys, I fixed it by looking through the MirrorReflection3 script, the functions "`Vector4 CameraSpacePlane( ... )`" and "`static void CalculateObliqueMatrix( ... )`" did it perfectly, I just had to pass the other portal's position and normal as parameters for the first function (making sure the z axis is pointing outwards), then pass the player camera's matrix and the resulting Vector4 to the second function and then apply the resulting matrix to the portal's camera, so if anyone needs it, the link to the script is here

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 T_Beier · Feb 18, 2019 at 11:39 AM 1
Share

Works like a charm!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Minimum Near Clip Plane for the camera 2 Answers

!IsNormalized error when skewing a Camera 0 Answers

Detecting when camera's near clip plane is hit 2 Answers

Why is part of object outside camera frustum visible? 1 Answer

Generating rays from cameras with custom projection matrices 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