You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapter25/chapter25.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,21 +6,21 @@ You may have wondered why are we drawing the whole list of GameItems every frame
6
6
7
7
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.
8
8
9
-
\*\*\* FIGURE \*\*\*
9
+

10
10
11
11
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.
12
12
13
-
\*\*\* FIGURE \*\*\*
14
-
15
13
Thus, in order to perform frustum culling we need to:
16
14
17
15
* Calculate frustum planes using the data contained in the view and projection matrices.
18
16
19
17
* 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.
20
18
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
+

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:
22
22
23
-
\*\*\* FIGURE \*\*\*
23
+

24
24
25
25
The equation of a plane is defined like this:
26
26
@@ -76,7 +76,7 @@ First, we store a copy of the projection matrix and multiply it by the view matr
76
76
77
77
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.
78
78
79
-
\*\*\*\* FIGURE \*\*\*
79
+

80
80
81
81
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:
82
82
@@ -94,7 +94,7 @@ We need to enclsoe evey `GameItem`into a simple volume that is easy to check. He
94
94
95
95
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$$.
96
96
97
-
\*\*\*\* FIGURE \*\*
97
+

98
98
99
99
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.
0 commit comments