1

I'm developing game for Google Daydream and cameras that are used there are really confusing - all of their params are set to the same value when scene starts. Initially I had a problem with further object meshes clipping through each other. I found out that the solution to this is to set nearClippingPlaneto higher value. This caused next problem wich was the cockpit of my ship being not entirerly rendered because of this nearClippingPlane being too far. I tried to create another camera that would render only the cockpit, but because of what I mentioned previously it doesn't work(the cameras act weird), and when I set it through a script it also doesn't work properly.

Because of that I need to change some property of the object, not the camera. I found this but it only works for farClippingPlane(otherwise it would be perfect). Do you know how can I ignore nearClippingPlane for one object/layer without adding second camera?

Wojtek Wencel
  • 2,257
  • 6
  • 31
  • 65
  • I don't think what you're describing is possible. Camera.layerCullDistances makes an object disappear completely, rather than cutting it off when it gets too close/too far. I think what you're looking for is a Camera culling mask. That way you can render only objects in specific layers on one specific camera. – Jespertheend Feb 24 '17 at 19:24
  • @Jespertheend `Camera.layerCullDistances ` allows you to set `farClipPlane` for specific laer and it would be perfect if I could do the same thing with `nearClipPlane`. I also can't do it with culling mask because it needs two cameras to work and because of what I wrote previously it won't work. – Wojtek Wencel Feb 24 '17 at 19:27
  • I don't think that would work even if unity had an option for culling nearby objects. As far as I know `Camera.layerCullDistances` only makes entire objects disappear, and after that it applies the clipping panes. So even if you were able to set the near culling distance of your cockpit, it would still not render it. I think your best bet is to either tweak the near and far clipping panes to something that works best, or try to get a setup with multiple cameras to work. – Jespertheend Feb 24 '17 at 19:35
  • That's the easy option that I know will work, but I asking there because I want to do it without any compromises and someone might know some way to do it, for example with shader. – Wojtek Wencel Feb 24 '17 at 19:38

1 Answers1

2

Regarding further object meshes clipping, this is likely happening due to z-fighting: https://en.wikipedia.org/wiki/Z-fighting

Note that by default, Daydream in Unity will use a 16-bit depth buffer. This is accessible via the player settings -> other settings -> Virtual Reality SDKs -> Daydream.

Switching to a 32-bit depth buffer might allow you to render both the objects in the cockpit and the objects far away using a small nearClippingPlane value. However, this is mostly a mitigation and you might still run into clipping problems, albeit much smaller ones. Additionally there's a performance impact by doing this since you're doubling the memory and bandwidth used by your depth buffer.

You should be able to use multiple cameras like you tried. Create a "Cockpit" and "Environment" camera, with the cockpit camera rendering second using the camera's Depth property. This will render the environment first, and you can ignore all the objects within the cockpit. This has the advantage that you can push out the near plane pretty far.

Next, set the cockpit camera to only clear depth. You can set the cockpit camera to enclose only objects that might be in your cockpit. Now the renderer will preserve the environment, but allow you to use two different depth ranges. Note that this also has performance implications on mobile devices, as the multiple render passes will incur an extra memory transfer, and you also need to clear the depth buffer in the middle of rendering.

You might want to consider creating separate layers for your objects, e.g. "cockpit" and "environment" to prevent things from being rendered twice.

Sample scene with two cameras, note the difference in near/far values

gstanlo
  • 33
  • 3