hi a couple of weeks ago i asked about this “layerCullDistances” feature and how to implement it:
people gave me a link to the documentation:
and here is what i did:
-i put the code snippet from the documentation into the orbit camera script!
-attached it to the camera
-attached it to my third person controller object ( its all based on lerpz really )
-made a bunch of small objects
-added them to the appropriate layers
-i walk too far away and they dissapear ( wohoo so far so good)
-i walk closer again and they reappear ( great ) !
but now the issue: if i stand close to the cull distance and start rotating the camera the objects start flickering around like crazy.
as if its trying to recalculate the distance each frame but the calculation is vastly imprecise and the result each frame is in a +1-1unit range from what the distance actually is.
i made a video check out the barrels stacked against the house wall in the center of the screen:
I’m not sure if this is a bug, an unavoidable side effect of the way the distance is calculated in relation to the projection matrix while rotating, or the way you have integrated the layer distance culling code into your camera orbit script. Whatever the issue is though that is definitely annoying and it would be much appreciated if you could file a bug that reproduces this effect.
okay i have a fool proof reproduction method now and made a lerpz escapes project scene that has the tees dissappear in this fashion but i think there is no point in submitting a bug with this attached because:
the key to making the flickering happen is setting the far clip plane to 2000 and the near clip plane 0.01 ( thats what i use in my game)
is this range really that unreasonable ?
if i set the near clip plane to anything higher the near clip plane will start eating away from my main character if the camera gets caught between the model and a wall but if its less than 2000 for the far clip plane i cant see my maya animated skydome
can somebody explain to me exactly how the depth between far and near clip plane is handled in unity ?
and can that maybe be turned up that there is more precision in between ?!
This isn’t a Unity problem. It’s a problem with 3D graphics in general. Not only does depth precision suffer, the greater the distance between the near and far planes, but the precision also gets worse, the closer to the far clip plane you get.
If you really need precision offer such a range, a solution may be for you to use multiple cameras, with the near clip plane of one beginning at the far clip plane of the other. Alternatively, you could move objects to different layers based on the sqrDistance from the cameras (you’ll need two, in the same spot, with differing clip planes and layer culling). Then you won’t have to render anything twice.
I’m sure there are better solutions on the boards. Those are just off the top of my head.
Because the far clip plane is stored as a float, the maximum is 2^32.
There’s always error in the projection. It just isn’t noticeable for the most part, because the scale of objects tends to be too big to display the problem. What you can actually use is dependent on how close together objects are in the distance.
okay i have a 2 camera solution now cam 1 draws only the skybox and has the range 50 - 2000
whilst the world camera has the range 0.02 - 200
are those ranges reasonable ?!
this definitely fixes the flickering of the small cullable objects ! and i haven’t noticed any other problems either so thanks alot guys for the help ! you are the best !
because it isn’t a unity skybox its a maya model with an animation and all sorts of custom stuff going on it ( birds flying around clouds moving etc … )