Greetings,
I am currently making this tutorial. In this project, two cameras and used, one with near/far clip plane 0-50, the seconde camera with near/far clip plane 50-500 (the first camera renders the environment enough close, and the second the environment enough far). Differents Clear flags are used for each camera. I try reading this URL but it is simply mind-blowing, I just can’t understand how it works.
I just understood that by selecting Skybox or Solid color for a camera, if anywhere on the screen, there was no object to block the view/to be shown, there would be the skybox or the solid color chosen. The latter URL shown contains an explication/exemple about a gun shown (like in many FPS, Unreal Tournament, etc.) but I haven’t understood a single word.
Could someone explains it in an other way ?
In the tutorial, the near camera ignores objects farther than 50 units away because that is the distance its far clipping plane is set to. The far camera renders objects that are more than 50 units away because its near clipping plane is set to 50. To see everything in the scene, the near camera’s view must be superimposed on the far camera’s.
If one camera renders over the view displayed by another camera, it normally obliterates it completely by clearing the whole view to a colour or skybox. However, if you set the clear flags to Depth, it won’t do this but rather draw over what is already there (ie, it will only add new rendering to the existing view). In the tutorial, the near camera is set to render over the far camera, but with its clear flags set to Depth, it shows the far camera’s output in the background.
So far, so pointless because it involves using two cameras in a complicated way to simulate the output of a single camera. However, a camera is also equipped with a so-called culling mask, which enables it to ignore an object if it is on a particular layer (see this manual page for more details about layers and culling masks). The far camera’s culling mask is set to ignore objects which the game designer deemed insignificant when they are at distance. The upshot of all this is that the insignificant objects are not rendered at all when they are more than 50 units away, thus reducing the load on the GPU and improving performance.
1 Like
A camera in Unity holds info about the displayed object’s colors and depths. In this case, depth info means the game world distance from the displayed object to the camera.
When a camera renders an image it can get rid of all or just some of the old image information and then displays the new image on top of what’s left. Depending on what clear flags you select, the camera gets rid of different info.
-
The skybox clear flag means that when the camera renders a new frame, it clears everything from the old frame and it displays the new image on top of a skybox.
-
The solid color clear flag means that when the camera renders a new frame, it clears everything from the old frame and it displays the new image on top of a solid color.
-
The depth only clear flag means that when the camera renders a new frame, it clears only the depth information from the old frame and it keeps the color information on top of which displays the new frame. This means that the old frame can still show but it doesn’t have depth information, meaning the new objects to be displayed can’t be shown as intersected or obstructed by the old objects, because there’s no information about how far the old objects are(depth info was cleared). So the new objects will be on top of the old ones, mandatory.
This has useful implications for example in FPS games, where you want to avoid, when getting very close to a wall, the gun going through the wall. This can be avoided by having two cameras , one displaying on top of the other(camera order selected by using Depth parameter; the bigger Depth camera displays on top of the other). The first camera should display only the environment(and use skybox or solid color clear flag) and the second camera should display only the gun(and use depth only clear flag) (obs. selective display of game objects is done by using the culling mask ). Because the gun camera clears the depth info of the image shown by the environment camera, the gun image will be shown in full, on top of the environment image, regardless if the gun intersects with the environment in the game world.
2 Likes