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 grimmy · Mar 15, 2012 at 11:58 AM · camerarendererbounds

How do I check if an object is completely visible?

How do I check if an object is completely within my camera frustum? ie Is the whole object is being rendered.

I am currently using a script which detects only if any single part of the object is within the camera frustum which isn't what I want..

Current code:

 function IsRenderedFrom(renderer : Renderer, camera : Camera) : boolean
 {
     planes= GeometryUtility.CalculateFrustumPlanes(camera);
     return GeometryUtility.TestPlanesAABB(planes, renderer.bounds);
 }
Comment
Add comment · Show 2
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 FredMastro · Jul 07, 2020 at 06:05 PM 0
Share

Looks this was never answered. Did you haver find an answer, I was looking for the same thing.

avatar image grimmy FredMastro · Jul 07, 2020 at 06:43 PM 1
Share

I can't remember. This was 8 years ago :)

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by senad · Mar 15, 2012 at 12:25 PM

This is the standard frustum test, because normally you are interested if any of the geometry is inside the view frustum. (is visible)

What you would need would be to test if any of the bounding geometry is outside of the frustum. Because if not, then everything is completely inside.

I am a little new to Unity3D so I do not know if they offer this functionality, but I would suspect not. If you want to implement this yourself you have to test each BB vertex against six frustum planes, but the test succeeds if the vertex is outside.

You can google frustum culling to read up on this.

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 Meltdown · Mar 15, 2012 at 01:27 PM

You can use renderer.isVisible to determine if the object is within 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 senad · Mar 16, 2012 at 12:56 PM 1
Share

He was asking to know if the object is completely visible, not only (partially) visible. :)

avatar image
0

Answer by Shinugami · Oct 16, 2012 at 02:03 PM

You can use renderer.isVisible to determine if the object is within the frustum.

Yes this is correct but if the object casts shadows even though it is technically off camera then it is still considered as visible: /Documentation/ScriptReference/Renderer-isVisible.html

"Note that object is considered visible when it needs to be rendered in the scene. It might not be actually visible by any camera, but still need to be rendered for shadows for example. Also, when running in the editor, the scene view cameras will also cause this value to be true."

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 Bunny83 · Jul 08, 2020 at 04:33 AM

Since the question was already bumped...

You can actually use TestPlanesAABB with the inverted planes and check that the renderer is not in front of the planes which will ensure it's within the frustum. Keep in mind that this only accounts for the AABB of the object. So even it might be completely visible it might not be considered visible because the AABB is larger than the visible object.

 public static bool IsRenderedFrom(Renderer aRenderer, Camera aCam)
 {
     var planes = GeometryUtility.CalculateFrustumPlanes(aCam);
     for(int i = 0; i < planes.Length; i++)
         planes[i] = planes[i].flipped;
     return !GeometryUtility.TestPlanesAABB(planes, aRenderer.bounds);
 }

By flipping all 6 planes we essentially form a negative space. So the planes will cover everything except the inner part of the frustum. So whenever an object is outside the frustum or partially overlapped with one plane, TestPlanesAABB will return true. This is our indication that it's not fully visible. Only when TestPlanesAABB returns false we know it has to be completely inside the frustum.


Flipping a plane is a trivial operation. We just have to flip the sign of all 4 float values that define our plane. The normal vector is inverted ( so it points in the opposite direction) and the distance from the origin is also inverted in order to keep the plane at the same position in space.

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

9 People are following this question.

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

Related Questions

Want to frame multiple objects in camera view using render bounds 0 Answers

put prefab in top left of the camera 0 Answers

This camera controller is overriding it's default position when the boundary check is enabled? 0 Answers

Shuriken won't render off camera bounds 0 Answers

How can I stop the drawcall of an object if it is not in view of the camera, without using occlusion culling? 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