Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does OpenGL have a far clipping plane, and what idioms are used to deal with this?

I've been learning OpenGL, and the one topic that continues to baffle me is the far clipping plane. While I can understand the reasoning behind the near clipping plane, and the side clipping planes (which never have any real effect because objects outside them would never be rendered anyway), the far clipping plane seems only to be an annoyance.

Since those behind OpenGL have obviously thought this through, I know there must be something I am missing. Why does OpenGL have a far clipping plane? More importantly, because you cannot turn it off, what are the recommended idioms and practices to use when drawing things at huge distances (for objects such as stars thousands of units away in a space game, a skybox, etc.)? Are you expected just to make the clipping plane very far away, or is there a more elegant solution? How is this done in production software?

like image 649
exists-forall Avatar asked Aug 14 '12 09:08

exists-forall


People also ask

What is far clipping plane?

The far clipping plane is furthest point of the Camera's view frustum. The Camera cannot see geometry that is further this distance. For more information, see Understanding the view frustum. In the Unity Editor, this corresponds to the Clipping Planes: Far property in the Camera component Inspector.

What is the main purpose of the near clipping plane?

Near and far clipping planes are imaginary planes located at two particular distances from the camera along the camera's sight line. They determine how much of a scene is seen by the camera in the viewport.

What is distance clipping?

Near clipping distance and far clipping distance refer to the near and far plane of the viewing frustum. Anything closer to the eye than the near clipping distance isn't displayed (it's too close), and anything further away from the eye than the far clipping distance isn't displayed either (it's too far away).

Is the truncated pyramid between near and far clipping plane?

The frustum is a truncated pyramid. Features within the pyramid between the near plane (in red) and the far plane (in green) are visible in the scene. The distances of the near and far clipping planes from the camera are determined automatically.


2 Answers

The only reason is depth-precision. Since you only have a limited number of bits in the depth buffer, you can also just represent a finite amount of depth with it.

However, you can set the far plane to infinitely far away: See this. It just won't work very well with the depth buffer - you will see a lot of artifacts if you have occlusion far away.

So since this revolves around the depth buffer, you won't have a problem dealing with further-away stuff, as long as you don't use it. For example, a common technique is to render the scene in "slabs" that each only use the depth buffer internally (for all the stuff in one slab) but some form of painter's algorithm externally (for the slabs, so you draw the furthest one first)

like image 174
ltjax Avatar answered Nov 15 '22 20:11

ltjax


Why does OpenGL have a far clipping plane?

Because computers are finite.

There are generally two ways to attempt to deal with this. One way is to construct the projection by taking the limit as z-far approaches infinity. This will converge on finite values, but it can play havoc with your depth precision for distant objects.

An alternative (if you're willing to have objects beyond a certain distance fail to depth-test correctly at all) is to turn on depth clamping with glEnable(GL_DEPTH_CLAMP). This will prevent clipping against the near and far planes; it's just that any fragments that would have normalized z coordinates outside of the [-1, 1] range will be clamped to that range. As previously indicated, it screws up depth tests between fragments that are being clamped, but usually those objects are far away.

like image 30
Nicol Bolas Avatar answered Nov 15 '22 22:11

Nicol Bolas