Hi there, I’m new to Unity. I’m working on the Walker Brothers tutorial for creating a 2D mario clone.
I’m a bit confused as to how the Clear Flags field works on a camera. The options are:
Skybox, Solid Color, Depth Only, and Don’t Clear
My current scene is just mario, the platform and a few blocks above him.
If I switch to “Skybox”, everything is clear and fine, the background cast is a sky. Same thing with “Solid Color”.
If I select “Depth Only”, objects in the scene begin repeating themselves (for example, walking mario around will leave several frozen copies of him trailing, kind of like a graphics glitch. Is there a term for this?). The same thing happens for “Don’t Clear”.
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.
You would only use Depth Only if you have more than one camera. You can use this for layering cameras, where you use Depth Only on the top camera, so the background areas would have the bottom camera show through. Don’t Clear is rarely used for anything. http://unity3d.com/support/documentation/Components/class-Camera.html