Use clipping planes (Clipping Planes) to define the camera's viewing range
Clipping Planes define the range of the scene that the camera can see. In some cases, limiting what the camera can see is a matter of style, but the main purpose of editing Clipping Planes is to optimize performance. The less the camera has to render, the lower the program load.
The camera's clipping plane has two parameter values: near (near plane) and far (far plane). near defines the position of the plane closest to the camera and can also be rendered by the camera; far is the opposite plane.
For an orthographic projection camera, the far and near planes are in the shape of a pyramid, which can be seen after selecting the camera in the scene view:
For an orthographic projection camera, this plane is a rectangle:
Next, let's adjust the parameters of clipping planes (orthogonal projection type camera):
1. Select the Main Camera in the Hierarchy, zoom the scene view so that you can observe the overall far and near plane of the camera.
2. In the Inspector of the Main Camera, modify the Far parameter in the Clipping Planes, from 1000 to 100, from 100 to 10, and then from 10 to 1. Observe the situation of the camera's far and near plane wireframe in the scene view and the change of the camera preview window.
We can see that as Far decreases, the camera can see less. Things that can be seen originally will be filled with the background (usually the background of the skybox) after being invisible.
3. In the scene view, we use the move tool to let the camera translate forward along the z-axis.
As the camera pans forward, we can see objects that were previously invisible, and when they reach the Far plane range, they will suddenly pop out. Although this effect can be deliberately used for some stylized needs, in general, it should be avoided in games or real-time applications. Generally, we will set a larger Far value, so that users will not feel the sudden disappearance or sudden appearance of this object. Here we set Far back to the default of 1000.
4. The meaning of the near plane parameter Near is similar to that of Far, and we can also adjust this parameter. But a common problem is that when the model of a character or a game object is partially out of the near plane, we may see the mesh inside the object.
We may see this kind of scene in some 3D games. To solve this problem, it is best to keep a safe distance between the camera and the object. If the camera is fixed, you can also adjust the value of Near.
Use culling masks to hide or show objects
What should we do if there is an object within the Near and Far planes of the camera, but we want to hide or show it? There are various ways to solve this problem, for the camera, there are culling masks that can be used to achieve this function.
1. In the scene view, select the red capsule and press F to focus.
2. In the Inspector of the capsule body, select Layer -> Add Layer, and then set User Layer6 to Culled.
3. Reselect the capsule body in the scene view, and then set the Culled layer to the capsule body in the Inspector.
4. Select the Main Camera, navigate to the Inspector, select the Culling Mask option in the Rendering section of the Camera component, and disable Culled.
In the scene view, the capsule is still there, but as you can see from the camera preview window, the capsule is gone.
Modify background type
By default, the scene will use a default skybox as the background. This sky box is bound to Directional Light (which is also the default parallel light source when creating a scene). Together, these two objects contribute to the ambient light of the scene. While the skybox and associated lighting are determined by the skybox's shader and lighting properties, the camera can manage whether the skybox is visible in the scene.
1. Adjust the camera angle of view to ensure that the camera can see the skybox.
2. In the Inspector, find the Environment part of the Camera component
3. Change the Background Type from Skybox to Solid Color
4. At this point, we compare the scene view and the camera preview view, and we will find that the sky box still exists in the scene, and the sky displayed in the camera view is blue. If there are multiple cameras in the scene, each camera can have a different background type setting, which can be used to achieve some special effects.
5. Click the color bar of Background and change the color to other colors, such as green.
One thing to note is that the background type is selected as Solid Color, and its color will not affect the lighting of the scene, which is different from Skybox. Solid Color simply tells the camera to stop rendering the skybox and replace it with a color of our choice. Even if the skybox is not visible in the camera, any modification to the skybox will still be visible in the environment.