• 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 NymThePseudo · Dec 07, 2016 at 05:49 AM · cullingnear

How to not render objects within certain distance of camera?

I'm working on a project where it might be preferable to not render certain objects (on a specific layer) if they're within a certain distance of the camera. I know I could technically achieve this with a script, but seeing how this should apply to thousands of objects at the same time (grass for example), I was wondering whether this would be possible to do in a different, more efficient way?

Would a shader work? I'm not very good at writing shaders myself, so it would be nice if such a shader could be found somewhere. Or is there a way of doing it with built-in Unity functionality?

So yeah, I'm basically looking for the opposite of layerCullDistances, however in my case I can't just move the near clip plane.

Comment
Add comment · Show 4
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 getyour411 · Dec 07, 2016 at 06:01 AM 0
Share

What's the criteria for "might be"?

avatar image JedBeryll · Dec 07, 2016 at 06:31 AM 0
Share

Interesting question. I know you said scripts may be slow but it's pretty easy to test. You would only have to calculate the squared magnitude. For efficiency, create a static reference to the main camera's transform, and a local reference to the object's own transforms. Then just compare the squared distance to the squared range that you want to test, if object passes outside, turn off renderer, otherwise turn it on. I think it's worth a try.

avatar image JedBeryll · Dec 07, 2016 at 06:34 AM 0
Share

Another idea: lod levels. Unity already handles lod levels pretty well, so maybe just create a lod that is a cube or nothing at all (if that's even possible).

avatar image tomekkie2 · Dec 07, 2016 at 07:02 AM 0
Share

You could use a clipping shader. Then you could define clipping surfaces like planes or spheres, and code this shader so it doesn't render between these surfaces. But objects that are cut by these surfaces will be partially rendered, i.e. clipped.

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

double-sided plane with texture? 3 Answers

lighting occlusion 1 Answer

Backface Transparent Diffuse Shader 1 Answer

How do you add something to your pass? 1 Answer

Occlusion Culling with Static Mesh Render Object 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