View Frustum

In the Scene view, the camera is represented by several lines in the shape of a pyramid with the top cut off. This shape is called a frustum, and everything inside the frustum is what the camera will be able to see.

Resources

Cameras in Unity - Project Files - This is a zip file that contains the Unity project for this course. Download the file, unzip it, and then in your file browser (Finder on OS X and Exporer on Windows) navigate to Cameras in Unity > Assets > _Scenes. Finally, choose the scene you'd like to open.

0:00

In the scene view the camera is
represented by several lines in the shape

0:05

of a pyramid with the top cut off.

0:08

This shape is called a frustum and

0:11

everything inside the frustum is
what the camera will be able to see.

0:15

Let's take a look in Unity.

0:17

In hierarchy,
I'm going to select the Camera.

0:20

And then in the scene view,

0:22

I'm going to hit the q key to
hide the transform controls.

0:27

And then in the scene view search box.

0:30

I'm going to type camera so that the scene
view isolates the camera game object.

0:37

With the camera selected in the hierarchy,
I'm going to hit the F key in

0:43

the scene view to frame it, and
then let's zoom in for a closer look.

0:50

Here you can see the top
of the pyramid shape.

0:55

It looks like a long rectangle.

0:58

This matches the aspect
ratio of the game view.

1:03

I'm going to put the game view side
by side with the scene view and

1:08

then change the resolution drop down
to a few different aspect ratios.

1:14

In the scene view notice how
when I change aspect ratios

1:19

the top of the view
frustum changes to match.

1:23

I'm going to change the view
back to Free Aspect.

1:27

And then I'll dock the game
view back to this tab group.

1:32

In the Inspector, take a look at
the Clipping Planes for the camera.

1:37

This is where the camera
starts rendering and

1:42

where it stops rendering
based on its transform.

1:47

The top of the frustum
is near clipping plane.

1:52

To demonstrate, I'm going to switch the
scene view to an isometric perspective.

1:58

And then I'll zoom out and
rotate the view.

2:04

So that we can see the frustum edge on.

2:14

Now if I increase the near clipping plane.

2:18

Watch how in the scene view the start
of the frustum moves forward.

2:24

Then, as it intersects the geometry
of the scene in the camera preview,

2:30

it no longer renders it.

2:32

Of course, we don't want to do this.

2:34

So set the value back to 0.3,
which is the default.

2:42

Now let's try adjusting
the Far Clipping Plane.

2:45

The default value of 1,000 is very high.

2:49

This is good for an open world
game with distant scenery but

2:53

I'm going to set the Far Clipping Plane
to a value of 200.

2:57

This is a much lower value, but
it will still provide plenty of room for

3:04

the camera frustum to capture all
of the game objects in the scene.

3:08

As a general rule,

3:09

you should make the far clipping plane
as large as you need it but not larger.

3:14

Higher values will render more
geometry that may not be needed

3:19

which can impact performance and
decrease the frame rate.

3:22

This is especially true if objects
in the foreground are occluding

3:26

the more distant objects.

3:28

It doesn't matter much for this small
scene, but in a more complex scene

3:33

the difference becomes more important,
so it's good to form the habit now.

3:38

I'm going to select the Camera again and
hit the F key to frame it and

3:43

the scene view it will come out
of the isometric perspective.

3:49

And remove the search, So
that we can see the scene view again.

3:55

Now in the inspector,
let's try adjusting the view port

4:00

rectangle which is labeled Viewport Rect.

4:03

To demonstrate this,
I'm going to switch to the Game view.

4:07

The Viewport Rect values adjust where
the camera viewport appears on the screen.

4:14

This is useful for creating a variety
of effects involving multiple cameras.

4:19

Such as a picture in picture view for
a sports or racing game.

4:24

Or a split screen view with two cameras
for a local couch multiplayer game,

4:29

we're not going to use
this feature in our game.

4:33

But to demonstrate,
I'm going to create a second camera for

4:38

a picture in picture effect.

4:40

I'll adjust this camera so

4:42

that it's viewing the game board from
a slightly different perspective.

4:51

Maybe move it up a little bit,
and then angle it downwards.

4:58

Now if I turn this camera on and
off in the Inspector,

5:02

you can see the view alternate
between the two cameras.

5:06

For now I'll keep both cameras enabled.

5:09

With the second camera selected,

5:11

take a look at the Viewport Rect
values in the Inspector.

5:14

In the second row, the W and
H values stand for width and height.

5:21

These adjust the size of the viewport
as it appears on the screen.

5:26

So instead of a wide angle,
I want this to look like a square.

5:31

So I'm going to have to counter
balance the wide aspect ratio a bit,

5:37

and I'll change this to a value of 0.3.

5:41

And then I'll give it
a taller height value of 0.5.

5:46

Now in the first row I can use the X and
Y value to adjust

5:51

where this second angle
appears on the screen.

5:56

I want it to be in the bottom right,
so I'll adjust this to and

6:02

X value of 0.65, and a Y value 0.05.

6:07

Now, if we play the game,

6:13

a second camera angle will
disappear behind the main camera.

6:18

Let's stop the game to fix this.

6:21

That's because when there
are multiple cameras like this,

6:24

we need to manually adjust
their stacking order.

6:27

This can be done with the Depth
setting in the Inspector.

6:32

By default,
a new camera will be set to zero so

6:36

I'll increase the second camera
to a value of 1, and hit enter.

6:41

And now it will be rendered on top
because the first Camera is at

6:46

a Depth of zero and
the second Camera is at a Depth of 1.

6:52

So it should be higher
in the stacking order.

6:55

Now if we play the game we can see
the action from two different angles.

7:07

For now I'll stop the game.

7:10

We don't need the second camera, so
I'm going to click on it in the hierarchy,

7:15

and then delete it.

7:16

When you're done, save the scene.

7:21

That covers some of the basics of the view
frustum, but there's still more to learn.