# Create Polygonal View Frustum

## Recommended Posts

I'm getting really close to being able to do real view frustum culling with triangle shaped or quad shaped polygons but need only one measly step to getting there.
Basically when I wanted to add frustum culling I did a number of techniques. First I tried testing the vertices of a poly to see if they are all in or out of the view frustum. Works great! Except one problem. When a polygon is big or you are close to it, all the vertices are out of the view frustum but the polygon remains to be seen. So I tried testing to see if the sides of the polygons were in the view frustum by using a line plane collision algorithm as a third and forth case, which is if the lines of the polygon collide into any of the 6 planes of the view frustum, it will be visible, else, cull the polygon. I was basically using this:

		for (int i = 0; i < 6; i++)
{
//Check if any of the 4 lines of the quad cross any of the 6 view frustum planes. If the values fall between 0 and 1, then the line has crossed
//the plane and the polygon is visible.
t[0] = -((frustum_plane[i].a * vertex[0].x + frustum_plane[i].b * vertex[0].y + frustum_plane[i].c * vertex[0].z) + frustum_plane[i].d) /
(frustum_plane[i].a * vector[0].x + frustum_plane[i].b * vector[0].y + frustum_plane[i].c * vector[0].z);
t[1] = -((frustum_plane[i].a * vertex[1].x + frustum_plane[i].b * vertex[1].y + frustum_plane[i].c * vertex[1].z) + frustum_plane[i].d) /
(frustum_plane[i].a * vector[1].x + frustum_plane[i].b * vector[1].y + frustum_plane[i].c * vector[1].z);
t[2] = -((frustum_plane[i].a * vertex[2].x + frustum_plane[i].b * vertex[2].y + frustum_plane[i].c * vertex[2].z) + frustum_plane[i].d) /
(frustum_plane[i].a * vector[2].x + frustum_plane[i].b * vector[2].y + frustum_plane[i].c * vector[2].z);
t[3] = -((frustum_plane[i].a * vertex[0].x + frustum_plane[i].b * vertex[0].y + frustum_plane[i].c * vertex[0].z) + frustum_plane[i].d) /
(frustum_plane[i].a * vector[3].x + frustum_plane[i].b * vector[3].y + frustum_plane[i].c * vector[3].z);

if ((t[0] < 0.0f || t[0] > 1.0f) &&
(t[1] < 0.0f || t[1] > 1.0f) &&
(t[2] < 0.0f || t[2] > 1.0f) &&
(t[3] < 0.0f || t[3] > 1.0f))
{
pierced[i] = false;
}
else
{
pierced[i] = true;
}
}


Where the vector was literally all 4 sides of a quad. Works but ran into another problem. Even when the polygon is completely off screen, it still manages to collide into a frustum plane due to the fact it is literally 6 infinite planes. So I wanna test the frustum as six polygons rather than treat them as planes. How can I make the view frustum 6 polygonal quads? Thanks in advance.

##### Share on other sites
Why are you frustum-culling triangles and polygons?

L. Spiro

##### Share on other sites

To add to L. Spiro's comment.  Why are you using DX9?  Microsoft just dropped support for Window's Vista.  Which was what, DX10.  Your working on an API that is well over 10 years old and few if any use anymore.  What is your end goal?

##### Share on other sites

Well i was gonna port to dx11 just that i was gonna see if i could pull this off using dx9 for now since i know more of it than dx11

Basically im making a terrain engine, and im gonna cull sections of the terrain not necessarily individual triangles. So the quadrants of the terrain are treated as triangles. And with nifty special cases, i should be able to cull sections of the terrain as well as parts of the terrain involving height. Before i made these sections cull using invisible spheres but i figured its not practical due to certain heights of the terrain.

##### Share on other sites

Terrain is implemented as its own system.  It is not rendered the same way as standard geometry, nor is it culled the same way, and ray casts and other types of tests are usually written specifically for terrain.

Your terrain system is often defined by how it is rendered, and rendering is usually coupled with culling (for terrain).
GeoMipmaps and GeoClipmaps are two types of terrain systems whose rendering includes culling (and LOD) implicitly.

You should be using one of these for terrain, and in no case should you be frustum-culling triangles or polygons.  If you use chunked terrain, you cull chunks based on bounding boxes (specifically an AABB), just as you would cull anything else.

If you are creating a general rendering system and culling triangles/polygons, you are definitely doing it wrong.

L. Spiro

##### Share on other sites
i wasnt frustum culling individual polygons per sey, but instead was gonna cull quadrants of the terrain thats not in the view frustum just like the docs you shared. Its gonna have LOD like i did on my last terrain project. Only my harddrive died and i lost the code. Im practically doing it from scratch again to play around with this idea of mine.

##### Share on other sites

Then you wrap an AABB around the chunk and cull that.

There are many resources online for testing an AABB with a frustum.

L. Spiro

##### Share on other sites

Then you wrap an AABB around the chunk and cull that.

Since your models will probably be transformed either once or every frame, why not use and cull BBs instead of AABBs?

Well i was gonna port to dx11

Note that this involves more than changing 9s to 11s (quite large gap between d3d9 <> d3d10, d3d11)

##### Share on other sites

DX11 forces you to use shaders which is not my strong point unfortunately. DX9 gives you the option to use either or. Yet I've been working with DirectX9 the longest so I'm more comfortable with it. It's the only reason I was testing my idea on DirectX9. On top of that, they screwed up the entire library. Now using anything D3DX is now deprecated. And you have to use another library of C++ and h files in a thing called DirectXTK, and finding code on working with that on the internet is pretty far fetched considering most of the websites, and even books out there still use the deprecated D3DX library. Hell the Windows SDK no longer even packages the d3dx lib. I didn't want to get into a struggle of even trying to draw one measly polygon by spending days on even getting the code working. With that said, I've played plenty of games where in the options menu gives you the choice of using DX9 or DX11 (notice they skipped DX10), World of Warcraft being a fine example.

I don't wanna turn this thread into a DX war, but you must understand why I still use DirectX9 to test my idea. I will see if I can find anything on AABB to cull quadrants from the view frustum.

##### Share on other sites
Posted (edited)
On top of that, they screwed up the entire library. Now using anything D3DX is now deprecated. And you have to use another library of C++ and h files in a thing called DirectXTK, and finding code on working with that on the internet is pretty far fetched considering most of the websites, and even books out there still use the deprecated D3DX library.

You do not need DirectXTK (DirectX Tool Kit) to use Direct3D 11. It is like the name says just a "tool kit" not your pacemaker.

The deprecation of the DirectX 11 SDK (I am talking about the rendering aspect of DirectX), mostly affects your math structures and operations for which you can now use DirectXMath. For a more complete overview, take a look at "Living without D3DX".

Here are some tutorials I found useful for bootstrapping Direct3D 11:

http://www.rastertek.com/tutdx11.html (without DirectXMath)

http://www.rastertek.com/tutdx11s2.html (with DirectXMath)

Edited by matt77hias

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627652
• Total Posts
2978424

• 10
• 12
• 22
• 13
• 33