Jump to content
• Advertisement

# DX11 Frustum culling Rastertek Tutorial - Need urgent help!

This topic is 373 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

Hi, there's a great tutorial on frustum culling, but impossible to compile because it uses old DirectX 11 types (Direct3DXPlane instead of XMVECTOR, etc).  Can someone please help me update this one class - frustumClass - to the new DirectX11 types (XMMATRIX, XMVECTOR, etc)?

Furthermore, can anyone please explain how he gets the minimum Z distance from the projection matrix by dividing one element by another? He leaves no explanation for this math and it's extremely frustrating.

// Calculate the minimum Z distance in the frustum.
zMinimum = -projectionMatrix._43 / projectionMatrix._33;
r = screenDepth / (screenDepth - zMinimum);
projectionMatrix._33 = r;
projectionMatrix._43 = -r * zMinimum;

Also not sure how to use an XMVECTOR instead of the old Plane class that he uses. Confused as to where all the m12, m13, etc correspond to the elements of an XMVECTOR. I thought you're not supposed to even access the elements of an XMVECTOR directly! So incredibly frustrating.

Please help, thanks.

#### Share this post

##### Share on other sites
Advertisement

Getting the near/far values from the projection matrix is basically done by reversing the projection matrix equation.  In particular, you take the perspective projection equation, then solve for near/far values.  There's a plethora of information online about the perspective projection formula, and still a lot of information already on how to solve for the near/far values (including caveats), so I'll leave that to you to look up.

As for XMVECTOR, the plane equation is just a 4D set of values (a, b, c, d), so anything that holds the 4D values can be used to store a plane.  You can store this inside an XMVECTOR if you like, then operate on it while it's loaded into the vector.  DirectXMath has a wide range of functions to set/get values inside an XMVECTOR

#### Share this post

##### Share on other sites
Edited by matt77hias

#### Share this post

##### Share on other sites

Thanks for all your advice and I appreciate your desire to make me seek the answers myself. However, I am still inexperienced with the right ways of using these new XM types, is this the right way to access the element of an XMMATRIX say at row 4, column 3?

float element43 = projectionMatrix.r[3].m128_f32[2];

Also, you said "as for XMVECTOR, the plane equation is just a 4D set of values," but a plane would need 12 values - 3 floats to express each of the 4 points, right? (or in the case of XMVECTOR, it has 4 floats). So how on earth do you store 4 3D points inside of 1 XMVECTOR? Even msdn specifically says use XMVECTOR instead of plane, but it makes no sense!

And could you please tell me the best way to access the element of an XMVECTOR? They make it really user unfriendly, you can't just index into an XMVECTOR, like you have to load it into an XMFLOAT4 or something, which seems like a huge waste of resources.

Edited by mister345

#### Share this post

##### Share on other sites
5 minutes ago, mister345 said:

but a plane would need 12 values - 3 floats to express each of the 4 points, right? (or in the case of XMVECTOR, it has 4 floats)

plane normal: 3 floats

signed distance from origin: 1 float

= 4 floats

#### Share this post

##### Share on other sites

I'm sorry, could you please elaborate? A plane would normally need at least 3 points to express in 3D space. How exactly do you only express it using a scalar value for distance from origin and normal? That tells you nothing about the location of the plane relative to the origin, or its width and height, only the direction of its surface. What am I missing here?

#### Share this post

##### Share on other sites

If I remember right, then my frustum class is directly ported from the rastertek tutorials for the new DirectXMath, you can check it out:

#### Share this post

##### Share on other sites
6 minutes ago, mister345 said:

I'm sorry, could you please elaborate? A plane would normally need at least 3 points to express in 3D space. How exactly do you only express it using a scalar value for distance from origin and normal? That tells you nothing about the location of the plane relative to the origin, or its width and height, only the direction of its surface. What am I missing here?

The normal specifies the orientation/rotation of the plane.

The distance specifies the position/translation of the plane.

Scaling is not needed, because a plane has an infinte area.

3 minutes ago, turanszkij said:

If I remember right, then my frustum class is directly ported from the rastertek tutorials for the new DirectXMath, you can check it out:

You can use some more SIMD

Edited by matt77hias

#### Share this post

##### Share on other sites
2 minutes ago, matt77hias said:

You can use some more SIMD

For sure, this is like one of my oldest codes so it is a bit low quality

#### Share this post

##### Share on other sites
1 minute ago, matt77hias said:

The normal specifies the orientation of the plane.

The distance specifies the translation of the plane.

Scaling is not needed, because a plane has an infinte area.

Yes, but translation in which direction? You can't just translate a 3D object with a single scalar value. If you wanted to translate some object by that value, you would have to multiply a normalized direction vector by your desired distance, then add it to the 3D position of the object in question. So which point on the plane exactly are you "translating" with this "distance" scalar, and in what direction exactly? Thanks.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 16
• 18
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633362
• Total Posts
3011527
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!