• 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 Marnix · Jun 29, 2011 at 03:30 PM · cameralayersfrustrumculling

layerCullDistances farther than farClipPlane

I am looking for a way to overrule the clipping plane of the camera. Why? Because I have an object that is very far away, but should always be drawn. The rest of the objects in the camera should use their normal farClipPlane.

I tested this by setting my layerCullDistances for layer 12 (where the object is in) to 100000, but it still got clipped by the farClipPlane.

 Camera.main.layerCullDistances[12] = 100000;

I also read the API: http://unity3d.com/support/documentation/ScriptReference/Camera-layerCullDistances.html
It only tells me about setting smaller values, but I want it to be larger.

How can I draw my object without it being clipped by the farClipPlane?

My second option is to use a second camera with a larger frustum, but this is not my intention, because it is against my design principles to have two cameras rendering the same way. There is most probably some setting that I can't find.

Update

Here is a screenshot of what is happening. The object is not culled completely, because the pivot point is in the cameras range, but it is clipped by the shader at the farClip's distance.

unisky clipping problem

You can see in this image, that it should actually continue to the end. It is a simple sky dome. The complete object is not clipped, but changing the far clip plane does change this image.

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 Marnix · Jun 29, 2011 at 05:14 PM 0
Share

@aldonaletto Updated my question with an image.

avatar image Marnix · Jun 29, 2011 at 10:26 PM 0
Share

Also asked my question in a more general form at SO: http://stackoverflow.com/questions/6525464/disable-culling-on-an-object

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Marnix · Jun 30, 2011 at 05:16 PM

I decided to make a camera managing system that has two cameras. One with a giant frustum that only renders the skydome. Its depth is set to -1. The other camera has a normal frustum, but only clears the depth buffer (`clearFlags = depth`) and depth = 0.

The cameras are drawn over one another, which is fine, but the camera needs polling to values like the FoV to maintain the same ratios.

The clearing of the depth buffer was very important to keep a good ratio for the SSAO-effect (Screen Space Ambient Occlusion-effect).

Another solution could have been, to set the farClipPlane to a large number at OnWillRenderObject. This also works, but the depth buffer still contains large values. So clearing the depth buffer is actually quite important to have high detail in the z-buffer.

Comment
Add comment · Show 4 · 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 aldonaletto · Jun 30, 2011 at 11:27 PM 0
Share

This is a good solution: it's like you had two depth buffers, one for the "far" camera and other for the "near". I suppose that if you're using culling$$anonymous$$ask to enable only the skydome layer in the "far" camera (and to disable it in the other), there will be no loss of performance - probably the layer culling is performed before any other proccess, thus avoiding waste of time with unnecessary frustum culling of other objects in scene.

avatar image Marnix · Jun 30, 2011 at 11:42 PM 0
Share

At the SO forum, someone did tell me that there will be a loss of performance, because the engine has to loop through 2 cameras ins$$anonymous$$d of one. I can imagine that every list is checked twice now. Although there isn't more or less to draw.

avatar image aldonaletto · Jul 01, 2011 at 07:12 PM 1
Share

If you are using culling$$anonymous$$ask, the extra cost will probably be the following: for each camera, the system will clear the buffers and search objects in the layers enabled by culling$$anonymous$$ask. This will be very fast in the new camera, since there's only one object. The really heavy part is the rendering process itself, which will not be different since the objects are the same as before - only the skydome was assigned to another camera.

avatar image Marnix · Jul 01, 2011 at 07:28 PM 0
Share

@aldonaletto Thanks for the status update. I'll just use the two cameras, but it's still not exactly as I would want it, because I need the polling to keep both cameras at equal values.

avatar image
0

Answer by aldonaletto · Jun 29, 2011 at 04:24 PM

The layerCullDistances can only reduce the far clip plane; I think it's a kind of "fake" far plane, used to avoid drawing unnecessary far objects. The "official" near and far planes play an important additional rule - they set the range of the Z plane. You can set a really far camera's Far Clipping Plane, but you can experience problems with borders of objects that intersect others or the terrain - the borders become to tremulate when you move the camera. If possible, you can increase the Near Clipping Plane distance to solve this problem - it has a much higher influence in the Z buffer resolution. The problem is that you can have very near objects clipped, since nothing before the near plane is drawn.

Comment
Add comment · Show 5 · 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 Marnix · Jun 29, 2011 at 04:28 PM 0
Share

That is exactly what I already knew =) But isn't there a solution to set the cullHint to Never? So, let it always render? There is no possibility for me to adjust the near clip plane, because we have a small scale game, but I am using UniSky, which wants me to set it the far plane to 100000. What would you recommend other than changing the clipping planes?

avatar image aldonaletto · Jun 29, 2011 at 04:38 PM 0
Share

The near and far clipping is done first at a higher level, where the engine decides which should be drawn or not - that's the problem, nothing in the shaders can change this because whole clipped objects don't even are sent to the renderer. Let me do a little research, and I'll be back asap.

avatar image Marnix · Jun 29, 2011 at 05:06 PM 0
Share

Well, maybe... the complete object is not culled, a part of it is visible actually. I'll post a screenshot of the case.

avatar image aldonaletto · Jun 30, 2011 at 03:45 AM 0
Share

I'm back! I've searched around a lot, but haven't found any useful trick to cheat the far clipping plane. Anyway, your object isn't being culled off since parts of it are inside the camera frustum - the problem is the clipping itself.
Restarting from the basics, I decided to test in my project the real relation between the far plane distance and the Z buffer accuracy - the project contains several lakes created by intersection between water planes and the terrain, which are by far the most sensible itens to Z buffer inaccuracies.
The result was surprising: setting the far plane to 100,000 had no noticeable effect on the Z buffer accuracy! I moved the camera around my terrain, and didn't see any apreciable change in the margins of the lakes (in a previous test, when I set the near plane to 0.01 the lake margins changed madly at any small camera movement). I let the near plane set to the default 0.3, and the only movement noticeable in the margins was the usual aliasing effect. I also tested 1,000,000, but then very small fluctuations could be noticed in the margins.
$$anonymous$$y computer has a simple Intel 945G$$anonymous$$ GPU, and as far as I know its Z buffer is 24 bits wide. If you're designing your game to run in PCs or $$anonymous$$ACs, I believe you will have no trouble setting the far plane to 100,000 - even with the default 0.3 at the near plane. This however may not be true in mobile devices, which can use 16 bits depth buffers.

avatar image Marnix · Jun 30, 2011 at 08:55 AM 0
Share

Unfortunately I do have problems with the settings between 0.3 and 100.000. $$anonymous$$y SSAO is creating all sorts of artifacts and I found that adjusting the values inside SSAO cannot be adjusted in a way that it still looks good. I would really like to use a smaller frustum, also for optimizations. I'll probably use 2 cameras then. One for the sky with a far frustum and one with a near frustum for the rest of the scene.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Rendering a camera in front of a gui element 3 Answers

camera layer issue, multiplayer. 1 Answer

Unity - blur on one camera effects the other as well 0 Answers

How to show part of the screen only for specified sorting layer? 0 Answers

Network restrictive rendering 1 Answer

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