View Frustum
Near and Far Planes
A view frustum is a truncated pyramid that determines what can be in view. Only objects within the frustum can appear on the screen. The camera is at the tip of the pyramid. The pyramid extends out along the direction that the camera is looking as shown below.
The frustum starts at the near plane and ends at the far plane. These planes are parallel and their normals are along the direction that the camera is looking. The length of the frustum is determined by the distance from the camera to the near plane and the distance from the camera to the far plane as shown below.
These values can be set using the NearPlane and FarPlane camera properties as shown below.
[C#] | Copy Code | |
---|---|---|
|
Moving the near plane too far from the camera can result in objects frequently getting clipped by the near plane as shown below.
Near Plane Distance: 1 meter | Near Plane Distance: 10,000 meters |
STK Engine uses multiple view frustums to correct the precision problems of a close near plane but it can sometimes negatively impact performance. The best practice is to start with the default near plane distance of 1 meter and adjust it only if you need to.
Far-to-Near Plane Ratio
The camera's FarNearPlaneRatio property is used to compute the size and number of view frustums used for rendering. The best practice is to not modify this property unless you have a good reason. A low far-to-near ratio provides better depth buffer precision but may create more view frustums, which can adversely affect performance.
The view frustum closest to the camera has a near plane distance defined by the NearPlane property. Its far plane distance is computed by multiplying its near plane distance by FarNearPlaneRatio. The next farthest view frustum has a near plane distance of the previous view frustum's far plane (ignoring a slight overlap). Its far plane distance is again computed using the far-to-near ratio. This process continues until the final view frustum has a far plane distance that satisfies the FarPlane property.
The following image (not to scale) shows an example where 3 view frustums are created based on the NearPlane, FarPlane, and FarNearPlaneRatio properties. Note that view frustums farther away from the camera are larger.
Field Of View
Depending on the window's aspect ratio, the field of view is either the angle between the top and bottom view frustum planes, or the left and right planes. If the y dimension of the window is larger than the x dimension, then the field of view is the angle between the top and bottom planes, otherwise it is the angle between the left and right planes. Set the field of view using the camera's FieldOfView property. Use the HorizontalFieldOfView and VerticalFieldOfView properties to get the horizontal and vertical fields of view.
[C#] | Copy Code | |
---|---|---|
|
Wider fields of view create bigger view frustums with more potentially visible objects and can look distorted.
|
|
35 degree field of view |
120 degree field of view |