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
0
Question by Dudledok · Jun 24, 2015 at 01:55 PM · camerarenderingcullingfieldofview

How to render objects outside the camera's view?

How do I go about rendering objects outside of the camera's field of view? The shader I am using can slightly change the shape / position of objects visually, but the gameobject is obviously unmoved and so Unity sometimes thinks (correctly) that the object is outside the camera's field of view, but because of the shader they are in view and not being rendered. This also causes objects to disappear just before going off camera. It would be pretty ugly to put a border round the edge of the screen so how would I go about doing this?

Basically I want to make the culling frustum a little larger than the view frustum of the camera. Is this possible?

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
2

Answer by Hellium · Jun 24, 2015 at 02:07 PM

If you could, at least, give the code of the shader, it could be helpfull.

You will have to make some research about Frustum culling. This is the method used to not render objects which are outside the cameras' view frustum.

From the doc, it is said that :

Unity ensures that when rendering your objects those which are completely outside of this frustum are not displayed. This is called Frustum Culling. Frustum Culling happens irrespective of whether you use Occlusion Culling in your game.

See : http://docs.unity3d.com/Manual/class-Camera.html

EDIT : it is possible to modifiy the culling distance for specific layers (near and far plane distance)

I think it will be difficult to find a way to tell your cameras to render an object if it is outside the view frustum.


Oops, my bad, see this blog post :

http://allenwp.com/blog/2013/12/19/disabling-frustum-culling-on-a-game-object-in-unity/

The author simply moves the bounds of the gameobject inside the view frustum (but set the transform position back), so that the cameras render it.

 // boundsTarget is the center of the camera's frustum, in world coordinates:
 Vector3 camPosition = camera.transform.position;
 Vector3 normCamForward = Vector3.Normalize(camera.transform.forward);
 float boundsDistance = (camera.farClipPlane - camera.nearClipPlane) / 2 + camera.nearClipPlane;
 Vector3 boundsTarget = camPosition + (normCamForward * boundsDistance);
  
 // The game object's transform will be applied to the mesh's bounds for frustum culling checking.
 // We need to "undo" this transform by making the boundsTarget relative to the game object's transform:
 Vector3 realtiveBoundsTarget = this.transform.InverseTransformPoint(boundsTarget);
  
 // Set the bounds of the mesh to be a 1x1x1 cube (actually doesn't matter what the size is)
 Mesh mesh = GetComponent().mesh;
 mesh.bounds = new Bounds(realtiveBoundsTarget, Vector3.one);

Credits : Allen Pestaluky

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 Dudledok · Jun 24, 2015 at 02:25 PM 0
Share

So yeah, basically the ideal scenario would be to adjust the culling frustum to make it a little large than the view frustum. I'm using a curvature shader and it's applied to most game objects so adjusting the bounds of each one wouldn't be great, nor efficient.

avatar image Owen-Reynolds · Jun 24, 2015 at 05:56 PM 0
Share

Using that same "change mesh.bounds" idea, seems like the textbook solution is to 1-time enlarge mesh.bounds to include everywhere the mesh might be moved.

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

occlusion culling conflict with shader,Occlusion culling conflict with shader 0 Answers

Dynamically render/hide object individually for each camera in scene 0 Answers

GameObject disappear as I move/rotate the camera 1 Answer

Where To Learn Occlusion Culling Scripts 1 Answer

Render an object or texture only near camera 0 Answers


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