• 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 zenforhire · Sep 10, 2015 at 01:31 AM · frustrum

Calculate camera frustum intersection with plane

We have play area composed of hex gameobjects. We only display/load what is visible. Impossible to load large maps at one time. We want to calculate the polygon intersection with the game board plane. We cannot load every possible game object and test if in the frustum or ray cast to the screen.

We need custom code to see which gameobject positions are in the visibility polygon? How do you get the corner rays of the camera frustum?

alt text

view-pyramid-clipping.jpg (33.8 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by musaranya · Sep 10, 2015 at 08:07 AM

I think Unity performs its frustum culling by default so you should not worry about it. Also keep in mind that if the objects are very large culling is less efective because when a vertex gets into the frustum the entire object is rendered. If you still want to get dirt with frustum culling, this couple of functions may interest you:

GeometryUtility.CalculateFrustumPlanes

GeometryUtility.TestPlanesAABB

regards

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
3

Answer by troien · Sep 10, 2015 at 08:20 AM

As for the :

How do you get the corner rays of the camera frustum?

To get the ray of each corner you can simply use camera.ViewportPointToRay.

 Ray bottomLeft = camera.ViewportPointToRay(new Vector3(0, 0, 0));
 Ray topLeft = camera.ViewportPointToRay(new Vector3(0, 1, 0));
 Ray topRight = camera.ViewportPointToRay(new Vector3(1, 1, 0));
 Ray bottomRight = camera.ViewportPointToRay(new Vector3(1, 0, 0));

If your plane is on a fixed height you perhaps don't even have to raycast. As a method like this should return the rays intersection on a given y position. (I used this method because I needed a similar thing, but I didn't have a collider to raycast against as I used Graphics.DrawMesh).

 public static Vector3 GetPointAtHeight(Ray ray, float height)
 {
     return ray.origin + (((ray.origin.y - height) / -ray.direction.y) * ray.direction);
 }

Note that this method can thow a division by zero if ray.direction.y is 0.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

29 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

Related Questions

How can I know if a gameObject is 'seen' by a particular camera? 10 Answers

Occlusion Culling issue (works like Frustum Culling) 0 Answers

creating an asymmetric viewing frustum 0 Answers

How do I zoom the camera when it is in danger of colliding or being obstructed 1 Answer

Checking frustrum against Bounds per Object VS Player&List? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges