Skip to content

Commit 1e81c07

Browse files
committed
Creates chapter25/view_frustum_ii.png
Auto commit by GitBook Editor
1 parent 6116b62 commit 1e81c07

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

chapter25/bounding_sphere.png

14.9 KB
Loading

chapter25/chapter25.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ You may have wondered why are we drawing the whole list of GameItems every frame
66

77
But, first let’s review what is the view frustum. The view frustum is a volume that contains every object that may be visible taking into consideration the camera position and rotation and the projection that we are using. Typically, the view frustum is a rectangular pyramid like shown in the next figure.
88

9-
\*\*\* FIGURE \*\*\*
9+
![](/chapter25/view_frustum_i.png)
1010

1111
As you can see, the view frustum is defined by six planes, anything that lies outside the view frustum will not be rendering. So, frustum culling is the process of removing objects that are outside the view frustum.
1212

13-
\*\*\* FIGURE \*\*\*
14-
1513
Thus, in order to perform frustum culling we need to:
1614

1715
* Calculate frustum planes using the data contained in the view and projection matrices.
1816

1917
* For every GameItem, check if its contained inside that view frustum, that is, comatined between the size frustum planes, and eliminate the ones that lie outside from the rendering process.
2018

21-
So let’s start by calculating the frustum planes. A plane, is defined by a point contained in t and a vector orthogonal to that plane, as shown in the next figure:
19+
![](/chapter25/view_frustum_ii.png)
20+
21+
So let’s start by calculating the frustum planes. A plane, is defined by a point contained in it and a vector orthogonal to that plane, as shown in the next figure:
2222

23-
\*\*\* FIGURE \*\*\*
23+
![](/chapter25/plane.png)
2424

2525
The equation of a plane is defined like this:
2626

@@ -76,7 +76,7 @@ First, we store a copy of the projection matrix and multiply it by the view matr
7676

7777
Now that we have all the planes calculated we just need to check if the `GameItem`instances are inside the frustum or not. How can we do this ? Let’s first examine how we can check if a point is inside the frustum. We can achieve that by calculating the signed distance of the point to each of the planes. If the distance of the point to the plane is positive, this means that the point is in front of the plane \(according to its normal\). If it’s negative, this means that the point is behind the plane.
7878

79-
\*\*\*\* FIGURE \*\*\*
79+
![](/chapter25/distance_to_plane.png)
8080

8181
Therefore, a point will be inside the view frustum if the distance to all the planes of the frustum is positive. The distance of a point to the plane is defined like this:
8282

@@ -94,7 +94,7 @@ We need to enclsoe evey `GameItem`into a simple volume that is easy to check. He
9494

9595
In this case, we will use spheres, since is the most simple approach. We will enclose every `GameItems`into a sphere and will check if the sphere is inside the view frustum or not. In order to do that, we just need the center and the radius of the sphere. The checks are almost equal to the point case, except that we need to take the radius into consideration. A sphere will be outside the frustim if it the following condition is met: $$dist=Ax0+By0+Cz0 <= -radius$$.
9696

97-
\*\*\*\* FIGURE \*\*
97+
![](/chapter25/bounding_sphere.png)
9898

9999
So, we will add a new method to the `FrustumCullingFilter`class to check if a spphere is inside the frustum or not. The method is defined like this.
100100

chapter25/distance_to_plane.png

9.84 KB
Loading

chapter25/plane.png

6.43 KB
Loading

chapter25/view_frustum_i.png

27.3 KB
Loading

chapter25/view_frustum_ii.png

16.4 KB
Loading

0 commit comments

Comments
 (0)