cancel
Showing results for 
Search instead for 
Did you mean: 

How to disable near (and far) clipping

2EyeGuy
Adventurer
In Virtual Reality you almost never want near clipping. But putting the near clipping plane too close wastes most of the depth buffer resolution.

Here is a simple solution that disables near and far clipping so everything is still rendered regardless of distance. The disadvantage is that when two things are both closer than the near clipping plane the wrong one may occlude the other one. But it is still almost always better than near clipping.

In OpenGL 3 and above, just add this at the start:
glEnable(GL_DEPTH_CLAMP);
In Direct3D 10 and above, set DepthClipEnable to false in the rasterizer state, for example:
D3D11_RASTERIZER_DESC rs;
memset(&rs, 0, sizeof(rs));
rs.AntialiasedLineEnable = true;
rs.CullMode = D3D11_CULL_BACK;
rs.DepthClipEnable = false;
rs.FillMode = D3D11_FILL_SOLID;
Rasterizer = NULL;
Device->CreateRasterizerState(&rs, &Rasterizer.GetRawRef());


This site explains it well:
http://www.arcsynthesis.org/gltut/Positioning/Tut05%20Depth%20Clamping.html
(except when it says at the end "but that only gets us to exactly where we started" it means only for things in front of the near clipping plane... ie. it is a lot better than where they started overall)

A more complicated solution is to use the depth buffer differently, like this:
http://outerra.blogspot.com.au/2012/11/maximizing-depth-buffer-range-and.html
4 REPLIES 4

cybereality
Grand Champion
Interesting. Thanks for sharing.

kojack
MVP
MVP
"2EyeGuy" wrote:
A more complicated solution is to use the depth buffer differently, like this:
http://outerra.blogspot.com.au/2012/11/maximizing-depth-buffer-range-and.html

I've used the Outerra log z buffer technique, very cool.


Each turret is around 1m tall, with the camera placed 1km or so away with a tiny fov to zoom in and a very close near plane. The turrets on the right are rendered normally, the turrets on the left are using the Log Z shader.
Still some slight flaws, but way better.

owenwp
Expert Protege
Yes, just turning off clipping doesn't really gain you anything. It wasn't put into the graphics API by mistake. Without it you are going to introduce artifacts, like in the right hand side of that turret image, because depth testing goes out the window.

kojack
MVP
MVP
A good reference for any conversation on near/far planes: http://www.sjbaker.org/steve/omniv/love_your_z_buffer.html

Scary fact: with a conventional z buffer, half your z buffer values are used up in the z range of near plane to near plane * 2.
If you have a 24 bit z buffer and a near plane of 1cm, then the distance range of 1cm to 2cm from the camera takes up the z buffer range of 0 to 8,388,691.