Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
0
Question by arhopkins3 · May 11, 2013 at 07:50 PM · cameracullingplanesfrustum

Which plane is which with CalculateFrustumPlanes

I understand that CalculateFrustumPlanes() in Unity3D returns an array of Plane objects, each representing a different frustum plane, but I can't find any documentation to suggest which element is which?

for example

[0] = Front [1] = Back

etc.

I need to calculate whether a point in space (like the centre point of a Bounding volume) is in the camera frustum, for a Quad tree system.

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 AlwaysSunny · May 11, 2013 at 09:09 PM 0
Share

If there's no documented answer, it's likely the only way to learn this is by checking. It's even possible (though probably unlikely) that it won't be the same order in every scenario or version of Unity.

In whichever method initializes and populates the array, check the normal of each plane against the camera's forward, then sort them however you like with some vector math. Not pretty, but the calculations should be fast, and probably only need to happen once to establish ordering.

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MrEastwood · Feb 13, 2015 at 01:34 AM

I got this arrangement:

 [0] = Left
 [1] = Right
 [2] = Down
 [3] = Up
 [4] = Near
 [5] = Far

All normals point towards the inside of the frustum

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 gashraf · Aug 14, 2018 at 07:00 AM 0
Share

Thanks a lot! The Unity documentation code supports your last statement. The direction of frustum plane normals should be added to the documentation. Since the normals are facing inwards, a cheap cull test for a point Vector3 p with a safe margin float safe$$anonymous$$argin would have to compare with the negated frustum plane normals as follows:

if(Vector3.Dot(-planes[i].normal, p) - planes[i].distance) > safe$$anonymous$$argin) cull = true;

avatar image
-3

Answer by correia55 · Dec 06, 2015 at 02:40 PM

The answer to this question is now described in the unity documentation , including a script that creates planes in the correct positions. Either way the answer from @MrEastwood is correct so you should mark it as solved.

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 KevinCodes4Food · May 05, 2014 at 07:14 PM

The answer proved by AlwaysSunny above recommends checking the normal of each plane against the camera's forward.

Unfortunately, the near and far planes have the same forward :(

The easiest solution I have found is to move each plane along the normal. Then I look at the location of the plane relative to the camera's position while the camera is at a zeroed rotational position:

 GameObject[] frustumBounginObjects = new GameObject[6];
 public void CreateScreenBoundingObjects ()
 {
     Camera cam = Camera.main;
     Plane[] frustumPlanes = GeometryUtility.CalculateFrustumPlanes(cam);       

     for (int i=0; i < frustumPlanes.Length; ++i)
     {            
         frustumBounginObjects[i] = GameObject.CreatePrimitive(PrimitiveType.Plane);      

         frustumBounginObjects[i].transform.position = -frustumPlanes[i].normal * frustumPlanes[i].distance;   

         // Which plane?
         if(frustumBounginObjects[i].transform.position.y > 0) // Top?
         {
             frustumBounginObjects[i].name = "Top";
         }
         else if(frustumBounginObjects[i].transform.position.y < 0) // Bottom?
         {
             frustumBounginObjects[i].name = "Bottom";
         }
         else if(frustumBounginObjects[i].transform.position.x > 0) // Right?
         {
             frustumBounginObjects[i].name = "Right";
         }
         else if(frustumBounginObjects[i].transform.position.x < 0) // Left?
         {
             frustumBounginObjects[i].name = "Left";
         }
         else if(frustumBounginObjects[i].transform.position.z > Camera.main.nearClipPlane) // Far?
         {
             frustumBounginObjects[i].name = "Far";
         }
         else // Near?
         {
             frustumBounginObjects[i].name = "Near";
         }
             
         frustumBounginObjects[i].name += "Plane ";    
     }
 }
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

19 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

Related Questions

Frustum culling only stops rendering gameobjects to the left of the camera 0 Answers

CalculateFrustumPlanes not working 1 Answer

GameObject disappear as I move/rotate the camera 1 Answer

Particle System Particles disappear when game object transform is off screen 2 Answers

Where To Learn Occlusion Culling Scripts 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